@w6w/ui 0.2.67 → 0.2.68
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 +8 -0
- package/dist/{CodeBlock-C1IC5_6O.cjs → CodeBlock-85y9qvE3.cjs} +4 -4
- package/dist/{CodeBlock-C1IC5_6O.cjs.map → CodeBlock-85y9qvE3.cjs.map} +1 -1
- package/dist/{CodeBlock-CsdRXzb0.js → CodeBlock-a5QVaIGk.js} +158 -131
- package/dist/{CodeBlock-CsdRXzb0.js.map → CodeBlock-a5QVaIGk.js.map} +1 -1
- package/dist/NodeConfigForm.d.ts +8 -2
- package/dist/StepBuilderModal.d.ts +2 -0
- package/dist/code.cjs +1 -1
- package/dist/code.mjs +1 -1
- package/dist/components/ExecutionLogDock.d.ts +44 -0
- package/dist/components/ExecutionLogPanel.d.ts +66 -0
- package/dist/components/ExecutionLogView.d.ts +30 -0
- package/dist/components/icons.d.ts +1 -1
- package/dist/connection-app-meta-DID4zDg-.cjs +29 -0
- package/dist/connection-app-meta-DID4zDg-.cjs.map +1 -0
- package/dist/{connection-app-meta-DEC0n4PA.js → connection-app-meta-mmyKM3H9.js} +4606 -3725
- package/dist/connection-app-meta-mmyKM3H9.js.map +1 -0
- package/dist/flow-types.d.ts +25 -1
- package/dist/flow.cjs +7 -5
- package/dist/flow.cjs.map +1 -1
- package/dist/flow.mjs +1119 -980
- package/dist/flow.mjs.map +1 -1
- package/dist/form-schema.d.ts +34 -0
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +1683 -1313
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.ts +2 -0
- package/package.json +2 -2
- package/src/styles/_execution-log-view.scss +322 -0
- package/src/styles/_form-builder.scss +13 -0
- package/src/styles.css +335 -0
- package/src/styles.scss +1 -0
- package/dist/connection-app-meta-DEC0n4PA.js.map +0 -1
- package/dist/connection-app-meta-Dk6F3KEH.cjs +0 -29
- package/dist/connection-app-meta-Dk6F3KEH.cjs.map +0 -1
package/dist/flow.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
"use client";"use strict";var mo=Object.defineProperty;var wo=(t,s,o)=>s in t?mo(t,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[s]=o;var at=(t,s,o)=>wo(t,typeof s!="symbol"?s+"":s,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),le=require("@xyflow/react"),u=require("react"),i=require("./connection-app-meta-Dk6F3KEH.cjs"),we=require("./CodeBlock-C1IC5_6O.cjs"),Ae=require("@w6w/expr");function go({x:t,y:s,items:o,onAction:n,onClose:r}){const c=u.useRef(null),[l,f]=u.useState({left:t,top:s});u.useLayoutEffect(()=>{const x=c.current,h=x==null?void 0:x.offsetParent;if(!x||!h)return;const m=x.offsetWidth,k=x.offsetHeight;f({left:t+m>h.clientWidth?Math.max(0,t-m):t,top:s+k>h.clientHeight?Math.max(0,s-k):s})},[t,s]),u.useEffect(()=>{var x,h;(h=(x=c.current)==null?void 0:x.querySelector("[role=menuitem]"))==null||h.focus({preventScroll:!0})},[]),u.useEffect(()=>{const x=k=>{var j;(j=c.current)!=null&&j.contains(k.target)||r(!1)},h=k=>{var j;(j=c.current)!=null&&j.contains(k.target)||r(!1)},m=()=>r(!1);return document.addEventListener("pointerdown",x,!0),document.addEventListener("scroll",h,!0),document.addEventListener("wheel",h,{capture:!0,passive:!0}),window.addEventListener("blur",m),window.addEventListener("resize",m),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("scroll",h,!0),document.removeEventListener("wheel",h,!0),window.removeEventListener("blur",m),window.removeEventListener("resize",m)}},[r]);const d=x=>{x.disabled||(r(!1),n(x.action))};return e.jsx("div",{ref:c,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:l.left,top:l.top},onContextMenu:x=>x.preventDefault(),onKeyDown:x=>{var j;x.stopPropagation();const h=[...((j=c.current)==null?void 0:j.querySelectorAll("[role=menuitem]"))??[]],m=h.indexOf(document.activeElement),k=y=>{var C;return(C=h[(y+h.length)%h.length])==null?void 0:C.focus()};if(x.key==="ArrowDown")k(m+1);else if(x.key==="ArrowUp")k(m<0?-1:m-1);else if(x.key==="Home")k(0);else if(x.key==="End")k(-1);else if(x.key==="Escape"||x.key==="Tab")r(!0);else if(x.key==="Enter"||x.key===" ")m>=0&&d(o[m]);else return;x.preventDefault()},children:o.map(x=>e.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":x.disabled||void 0,className:`w6w-note-menu-item${x.danger?" danger":""}${x.separated?" separated":""}`,"data-action":x.action,onClick:()=>d(x),children:x.label},x.action))})}const nn=i.customCssTemplate();function xo({value:t,onChange:s,readOnly:o,stepId:n}){const r=u.useMemo(()=>vo(t),[t]),c=u.useMemo(()=>{var S;return r?((S=i.parseFormDefinition(r))==null?void 0:S.problems)??[]:[]},[r]),[l,f]=u.useState(null),[d,x]=u.useState(null),[h,m]=u.useState(null),[k,j]=u.useState(0);if(!r)return e.jsxs("div",{className:"w6w-result w6w-error",children:["This form is not a form definition (it may be set by an expression). Edit it in the Parameters code view, or reset it.",!o&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-sm",onClick:()=>s(i.defaultFormDefinition()),children:"Reset to a starter form"})})]});const y=r.fields,C=S=>s({...r,...S}),M=S=>C({fields:S}),w=S=>new Set(y.filter(g=>g.id!==S&&g.name).map(g=>g.name)),F=(S,g)=>{const P=y.find(ne=>ne.id===S);if(!P)return;let Y=yo({...P,...g});if(g.label!==void 0&&i.isInputField(P.type)){const ne=w(S),Z=i.uniqueName(i.slugName(P.label??""),ne);(!P.name||P.name===Z)&&(Y={...Y,name:i.uniqueName(i.slugName(g.label||P.type),ne)})}const B=P.name&&Y.name!==P.name?P.name:null;M(y.map(ne=>{var Z;return ne.id===S?Y:B&&((Z=ne.showIf)==null?void 0:Z.field)===B&&Y.name?{...ne,showIf:{...ne.showIf,field:Y.name}}:ne}))},W=(S,g=y.length)=>{const P=on(y),Y=i.newField(S,P,w()),B=[...y];B.splice(g,0,Y),M(B),f(P)},O=(S,g)=>{const P=y.findIndex(Z=>Z.id===S);if(P<0)return;const Y=g>P?g-1:g;if(Y===P||Y<0||Y>=y.length)return;const B=[...y],[ne]=B.splice(P,1);B.splice(Y,0,ne),M(B)},I=S=>{const g=on(y),P={...structuredClone(S),id:g};P.name&&(P.name=i.uniqueName(P.name,w()));const Y=y.findIndex(ne=>ne.id===S.id)+1,B=[...y];B.splice(Y,0,P),M(B),f(g)},R=()=>{x(null),m(null)},E=(S,g)=>{if(S.preventDefault(),o)return R();d&&O(d,g),R()},V=(S,g)=>{if(o||!d)return;S.preventDefault(),S.dataTransfer.dropEffect="move";const P=S.currentTarget.getBoundingClientRect();m(S.clientY>P.top+P.height/2?g+1:g)},K=y.filter(S=>i.isInputField(S.type)&&S.name);return e.jsxs("div",{className:"w6w-form-builder","data-testid":"form-builder",children:[c.length>0&&e.jsx("ul",{className:"w6w-form-problems","data-testid":"form-problems",children:c.map(S=>e.jsxs("li",{children:[e.jsx(we.Icon,{name:"warning",size:12})," ",S.fieldId?e.jsx("button",{type:"button",className:"w6w-form-problem-link",onClick:()=>f(S.fieldId??null),children:S.message}):S.message]},`${S.fieldId??"form"}:${S.message}`))}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Form title"}),e.jsx("input",{type:"text",value:r.title??"",disabled:o,"aria-label":"Form title",onChange:S=>C({title:S.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Description"}),e.jsx("textarea",{rows:2,value:r.description??"",disabled:o,"aria-label":"Form description",onChange:S=>C({description:S.target.value||void 0})})]}),e.jsxs("div",{className:"w6w-form-section-label",children:["Fields ",e.jsx("span",{className:"w6w-muted",children:"· drag to reorder"})]}),e.jsxs("div",{className:"w6w-form-fields","data-testid":"form-fields",onDragLeave:S=>{S.currentTarget.contains(S.relatedTarget)||m(null)},children:[y.length===0&&e.jsx("div",{className:`w6w-form-empty${h===0?" is-drop-target":""}`,onDragOver:S=>{o||!d||(S.preventDefault(),m(0))},onDrop:S=>E(S,0),children:"No fields yet. Add one below."}),y.map((S,g)=>{const P=l===S.id,Y=["w6w-form-field",P?"is-open":"",d===S.id?"is-dragging":"",h===g?"is-drop-before":"",h===g+1&&g===y.length-1?"is-drop-after":"",S.type==="pageBreak"?"is-page-break":""].filter(Boolean).join(" ");return e.jsxs("div",{className:Y,"data-field-id":S.id,onDragOver:B=>V(B,g),onDrop:B=>E(B,h??g),children:[e.jsxs("div",{className:"w6w-form-field-head",children:[e.jsx("button",{type:"button",className:"w6w-icon-btn w6w-router-grip",draggable:!o,disabled:o,"aria-label":`Reorder ${Lt(S)}`,title:"Drag to reorder · arrow keys to move",onDragStart:B=>{B.dataTransfer.effectAllowed="move",B.dataTransfer.setData("text/plain",S.id);const ne=B.currentTarget.closest(".w6w-form-field");ne&&B.dataTransfer.setDragImage(ne,16,16),x(S.id)},onDragEnd:R,onKeyDown:B=>{B.key!=="ArrowUp"&&B.key!=="ArrowDown"||(B.preventDefault(),O(S.id,B.key==="ArrowUp"?g-1:g+2))},children:e.jsx(we.Icon,{name:"grip",size:14})}),e.jsxs("button",{type:"button",className:"w6w-form-field-summary","aria-expanded":P,onClick:()=>f(P?null:S.id),children:[e.jsx("span",{className:"w6w-form-field-type",children:i.FIELD_TYPE_LABELS[S.type]}),e.jsxs("span",{className:"w6w-form-field-label",children:[Lt(S),S.required?e.jsx("span",{className:"w6w-form-req",children:" *"}):null]}),S.name&&i.isInputField(S.type)&&e.jsx("code",{className:"w6w-form-field-name",children:S.name}),S.showIf&&e.jsx("span",{className:"w6w-form-field-badge",title:"Shown only when a condition holds",children:"if"}),e.jsx(we.Icon,{name:"chevron-down",size:12})]}),!o&&e.jsx(i.IconButton,{label:`Duplicate ${Lt(S)}`,icon:"copy",onClick:()=>I(S)}),e.jsx(i.DeleteButton,{label:`Remove ${Lt(S)}`,disabled:o,onClick:()=>M(y.filter(B=>B.id!==S.id))})]}),P&&e.jsx(ko,{field:S,earlier:K.filter(B=>y.indexOf(B)<g&&B.id!==S.id),readOnly:o,stepId:n,onPatch:B=>F(S.id,B)})]},S.id)})]}),!o&&e.jsx(i.Combobox,{className:"w6w-form-add",mode:"combobox","aria-label":"Add a field",placeholder:"+ Add a field…",options:jo,value:"",onChange:S=>{W(S),j(g=>g+1)}},k),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Submit button label"}),e.jsx("input",{type:"text",value:r.submitLabel??"",placeholder:"Submit",disabled:o,"aria-label":"Submit button label",onChange:S=>C({submitLabel:S.target.value||void 0})})]}),e.jsx(To,{form:r,save:C,readOnly:o}),e.jsx(Ao,{form:r,save:C,readOnly:o})]})}const bo=[{title:"Text",types:["text","textarea","email","number","phone","url","password"]},{title:"Choice",types:["select","radio","checkboxes","checkbox","rating"]},{title:"Date & time",types:["date","time","datetime"]},{title:"Other",types:["file","hidden"]},{title:"Layout",types:["heading","paragraph","pageBreak"]}],jo=bo.flatMap(t=>t.types.map(s=>({value:s,label:i.FIELD_TYPE_LABELS[s],group:t.title,keywords:`${t.title} ${s}`})));function vo(t){if(t==null||t==="")return i.defaultFormDefinition();let s=t;if(typeof s=="string")try{s=JSON.parse(s)}catch{return null}if(!s||typeof s!="object"||Array.isArray(s))return null;const o=s;if(!Array.isArray(o.fields))return null;if(o.fields.every(r=>r&&typeof r.id=="string"&&r.id))return o;const n=new Set;return{...o,fields:o.fields.filter(r=>r&&typeof r=="object").map((r,c)=>{let l=typeof r.id=="string"&&r.id&&!n.has(r.id)?r.id:`f_${c+1}`;for(;n.has(l);)l=`${l}_`;return n.add(l),{...r,id:l}})}}function on(t){const s=new Set(t.map(o=>o.id));for(;;){const o=`f_${Math.random().toString(36).slice(2,8)}`;if(!s.has(o))return o}}function yo(t){const s={};for(const[o,n]of Object.entries(t))n===void 0||n===""||(s[o]=n);return s}function Lt(t){return t.type==="pageBreak"?t.label?`New page: ${t.label}`:"New page":t.type==="paragraph"?So(t.help??"")||"Paragraph":t.label||t.name||i.FIELD_TYPE_LABELS[t.type]}function So(t,s=60){return t.length>s?`${t.slice(0,s-1)}…`:t}const No=t=>{if(t.trim()==="")return;const s=Number(t);return Number.isFinite(s)?s:void 0},Co={equals:"is",notEquals:"is not",contains:"contains",notContains:"does not contain",isEmpty:"is empty",isNotEmpty:"is not empty",greaterThan:"is greater than",lessThan:"is less than"};function ko({field:t,earlier:s,readOnly:o,stepId:n,onPatch:r}){const c=t.type,l=i.isInputField(c),f=i.CHOICE_FIELD_TYPES.has(c),d=i.TEXT_FIELD_TYPES.has(c),x=c==="checkboxes"||c==="select"&&t.multiple,h=(j,y,C={})=>e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:j}),C.area?e.jsx("textarea",{rows:3,value:String(t[y]??""),placeholder:C.placeholder,disabled:o,"aria-label":j,onChange:M=>r({[y]:M.target.value||void 0})}):e.jsx("input",{type:"text",value:String(t[y]??""),placeholder:C.placeholder,disabled:o,"aria-label":j,onChange:M=>r({[y]:M.target.value||void 0})}),C.hint&&e.jsx("span",{className:"w6w-hint",children:C.hint})]},String(y)),m=(j,y,C)=>e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:j}),e.jsx("input",{type:"number",value:t[y]===void 0?"":String(t[y]),placeholder:C,disabled:o,"aria-label":j,onChange:M=>r({[y]:No(M.target.value)})})]},String(y)),k=(j,y)=>e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!t[y],disabled:o,onChange:C=>r({[y]:C.target.checked||void 0})}),j]},String(y));return c==="pageBreak"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Next page title","label",{placeholder:"Optional"}),e.jsx("span",{className:"w6w-hint",children:"Everything below this starts a new page with Back / Next."})]}):c==="heading"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Heading","label"),h("Text under the heading","help",{area:!0}),e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]}):c==="paragraph"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Text","help",{area:!0}),e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]}):e.jsxs("div",{className:"w6w-form-field-body",children:[e.jsxs("div",{className:"w6w-field-row",children:[h(c==="hidden"?"Description":"Label","label"),h("Answer key","name",{hint:t.name?e.jsxs(e.Fragment,{children:["Use as ",e.jsx("code",{children:`{{ nodes.${n??"<trigger>"}.output.data.${t.name} }}`})]}):"Letters, digits and _."})]}),c==="hidden"?h("Value","defaultValue",{hint:"Recorded with every response. A ?name=value in the form URL overrides it."}):e.jsxs(e.Fragment,{children:[h("Help text","help",{placeholder:"Shown under the label"}),(d||c==="number"||c==="select")&&h("Placeholder","placeholder"),e.jsxs("div",{className:"w6w-form-checks",children:[l&&k("Required","required"),c==="select"&&k("Allow several choices","multiple"),f&&k('Offer an "Other" answer',"allowOther"),c==="file"&&k("Allow several files","multiple"),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:t.width==="half",disabled:o,onChange:j=>r({width:j.target.checked?"half":void 0})}),"Half width"]})]})]}),f&&e.jsx(Eo,{options:t.options??[],readOnly:o,onChange:j=>r({options:j})}),d&&e.jsxs("div",{className:"w6w-field-row",children:[m("Min length","minLength"),m("Max length","maxLength")]}),d&&c!=="email"&&c!=="url"&&e.jsxs("div",{className:"w6w-field-row",children:[h("Pattern (regular expression)","pattern",{placeholder:"e.g. [A-Z]{2}\\d{4}"}),t.pattern&&h("Message when it does not match","patternMessage")]}),c==="textarea"&&m("Rows","rows","4"),c==="number"&&e.jsxs("div",{className:"w6w-field-row",children:[m("Min","min"),m("Max","max"),m("Step","step","any")]}),c==="rating"&&m("Stars","max","5"),(c==="date"||c==="time"||c==="datetime")&&e.jsxs("div",{className:"w6w-field-row",children:[h("Earliest","minDate",{placeholder:rn(c)}),h("Latest","maxDate",{placeholder:rn(c)})]}),x&&e.jsxs("div",{className:"w6w-field-row",children:[m("Pick at least","minSelected"),m("Pick at most","maxSelected")]}),c==="file"&&e.jsxs("div",{className:"w6w-field-row",children:[h("Accepted types","accept",{placeholder:".pdf,image/*"}),m("Max size per file (MB)","maxFileSizeMb","10"),t.multiple&&m("Max files","maxFiles")]}),c!=="hidden"&&c!=="file"&&c!=="checkboxes"&&c!=="checkbox"&&!x&&h("Default answer","defaultValue",{hint:"A ?name=value in the form URL overrides it."}),c==="checkbox"&&e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:t.defaultValue===!0,disabled:o,onChange:j=>r({defaultValue:j.target.checked||void 0})}),"Checked by default"]}),c!=="hidden"&&e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]})}function rn(t){return t==="time"?"09:00":t==="datetime"?"2026-01-31T09:00":"2026-01-31"}function Zt({field:t,earlier:s,readOnly:o,onPatch:n}){var f;const r=t.showIf;if(!r)return s.length===0||o?null:e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-form-cond-add",onClick:()=>n({showIf:{field:s[s.length-1].name??"",op:"equals",value:""}}),children:"+ Show only when…"});const c=r.op!=="isEmpty"&&r.op!=="isNotEmpty",l=s.find(d=>d.name===r.field);return e.jsxs("div",{className:"w6w-form-cond","data-testid":"form-condition",children:[e.jsx("span",{className:"w6w-small",children:"Show only when"}),e.jsxs("select",{value:r.field,disabled:o,"aria-label":"Depends on",onChange:d=>n({showIf:{...r,field:d.target.value}}),children:[!l&&e.jsx("option",{value:r.field,children:r.field||"—"}),s.map(d=>e.jsx("option",{value:d.name,children:d.label||d.name},d.id))]}),e.jsx("select",{value:r.op,disabled:o,"aria-label":"Comparison",onChange:d=>n({showIf:{...r,op:d.target.value}}),children:i.CONDITION_OPS.map(d=>e.jsx("option",{value:d,children:Co[d]},d))}),c&&((f=l==null?void 0:l.options)!=null&&f.length?e.jsxs("select",{value:r.value??"",disabled:o,"aria-label":"Value",onChange:d=>n({showIf:{...r,value:d.target.value}}),children:[e.jsx("option",{value:"",children:"—"}),l.options.map(d=>e.jsx("option",{value:d.value||d.label,children:d.label},d.value??d.label))]}):e.jsx("input",{type:"text",value:r.value??"",disabled:o,"aria-label":"Value",placeholder:(l==null?void 0:l.type)==="checkbox"?"true":"value",onChange:d=>n({showIf:{...r,value:d.target.value}})})),e.jsx(i.DeleteButton,{label:"Remove condition",disabled:o,onClick:()=>n({showIf:void 0})})]})}function Eo({options:t,readOnly:s,onChange:o}){const[n,r]=u.useState(null),[c,l]=u.useState(null),f=(x,h)=>{if(h<0||h>=t.length||x===h)return;const m=[...t],[k]=m.splice(x,1);m.splice(h,0,k),o(m)},d=(x,h)=>o(t.map((m,k)=>{if(k!==x)return m;const{value:j,...y}={...m,...h};return j?{...y,value:j}:y}));return e.jsxs("div",{className:"w6w-form-options","data-testid":"form-options",children:[e.jsx("span",{className:"w6w-small w6w-muted",children:"Options · the value is recorded (defaults to the label)"}),t.map((x,h)=>e.jsxs("div",{className:`w6w-form-option${n===h?" is-dragging":""}${c===h?" is-drop-before":""}`,onDragOver:m=>{s||n===null||n===h||(m.preventDefault(),l(h))},onDrop:m=>{m.preventDefault(),n!==null&&f(n,h),r(null),l(null)},children:[e.jsx("button",{type:"button",className:"w6w-icon-btn w6w-router-grip",draggable:!s,disabled:s,"aria-label":`Reorder option ${x.label}`,title:"Drag to reorder · arrow keys to move",onDragStart:m=>{m.dataTransfer.effectAllowed="move",m.dataTransfer.setData("text/plain",String(h)),r(h)},onDragEnd:()=>{r(null),l(null)},onKeyDown:m=>{m.key!=="ArrowUp"&&m.key!=="ArrowDown"||(m.preventDefault(),f(h,h+(m.key==="ArrowUp"?-1:1)))},children:e.jsx(we.Icon,{name:"grip",size:12})}),e.jsx("input",{type:"text",value:x.label,disabled:s,"aria-label":`Option ${h+1} label`,onChange:m=>d(h,{label:m.target.value})}),e.jsx("input",{type:"text",value:x.value??"",placeholder:x.label,disabled:s,"aria-label":`Option ${h+1} value`,onChange:m=>d(h,{value:m.target.value})}),e.jsx(i.DeleteButton,{label:`Remove option ${x.label}`,disabled:s,onClick:()=>o(t.filter((m,k)=>k!==h))})]},h)),!s&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-router-add",onClick:()=>{let x=t.length+1;for(;t.some(h=>h.label===`Option ${x}`);)x++;o([...t,{label:`Option ${x}`}])},children:"+ Add option"})]})}function To({form:t,save:s,readOnly:o}){const n=t.completion??{},r=l=>{const f={...n,...l};for(const d of Object.keys(f))(f[d]===void 0||f[d]==="")&&delete f[d];s({completion:f})},c=n.type==="redirect";return e.jsxs("details",{className:"w6w-section w6w-form-group","data-testid":"form-completion",children:[e.jsxs("summary",{className:"w6w-section-summary",children:[e.jsx("span",{className:"w6w-section-title",children:"After submitting"}),e.jsx("span",{className:"w6w-section-subtitle",children:c?`Redirect to ${n.redirectUrl||"…"}`:n.title||"Thank-you message"})]}),e.jsxs("div",{className:"w6w-form-group-body",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Show"}),e.jsxs("select",{value:c?"redirect":"message",disabled:o,"aria-label":"Completion",onChange:l=>r({type:l.target.value}),children:[e.jsx("option",{value:"message",children:"A thank-you message"}),e.jsx("option",{value:"redirect",children:"Redirect to a URL"})]})]}),c?e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Redirect URL"}),e.jsx("input",{type:"text",value:n.redirectUrl??"",placeholder:"https://example.com/thanks?email={{email}}",disabled:o,"aria-label":"Redirect URL",onChange:l=>r({redirectUrl:l.target.value})}),e.jsxs("span",{className:"w6w-hint",children:[e.jsx("code",{children:"{{name}}"})," inserts that answer (URL-encoded)."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{type:"text",value:n.title??"",placeholder:"Thank you!",disabled:o,"aria-label":"Completion title",onChange:l=>r({title:l.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Message"}),e.jsx("textarea",{rows:2,value:n.message??"",disabled:o,"aria-label":"Completion message",onChange:l=>r({message:l.target.value})}),e.jsxs("span",{className:"w6w-hint",children:[e.jsx("code",{children:"{{name}}"})," inserts that answer. With “Wait for the workflow to finish”, a Respond to Webhook step can replace this screen."]})]}),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.allowAnother,disabled:o,onChange:l=>r({allowAnother:l.target.checked||void 0})}),"Offer “Submit another response”"]})]})]})]})}function Ao({form:t,save:s,readOnly:o}){const n=t.settings??{},r=l=>{const f={...n,...l};for(const d of Object.keys(f))(f[d]===void 0||f[d]==="")&&delete f[d];s({settings:f})},c=(l,f,d)=>e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:n[f]??d,disabled:o,onChange:x=>r({[f]:x.target.checked})}),l]});return e.jsxs("details",{className:"w6w-section w6w-form-group","data-testid":"form-settings",children:[e.jsxs("summary",{className:"w6w-section-summary",children:[e.jsx("span",{className:"w6w-section-title",children:"Page settings"}),e.jsxs("span",{className:"w6w-section-subtitle",children:[n.closed?"Closed":"Open"," · ",n.theme??"auto"," theme"]})]}),e.jsxs("div",{className:"w6w-form-group-body",children:[e.jsxs("div",{className:"w6w-form-checks",children:[c("Pre-fill from ?name=value in the URL","allowPrefill",!0),c("Show page progress","showProgress",!0),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.hideBranding,disabled:o,onChange:l=>r({hideBranding:l.target.checked||void 0})}),"Hide “Powered by w6w”"]})]}),e.jsxs("div",{className:"w6w-field-row",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Theme"}),e.jsxs("select",{value:n.theme??"auto",disabled:o,"aria-label":"Theme",onChange:l=>r({theme:l.target.value}),children:[e.jsx("option",{value:"auto",children:"Follow the visitor's system"}),e.jsx("option",{value:"light",children:"Light"}),e.jsx("option",{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Accent colour"}),e.jsxs("span",{className:"w6w-form-color",children:[e.jsx("input",{type:"color",value:/^#[0-9a-f]{6}$/i.test(n.accentColor??"")?n.accentColor:"#3355e6",disabled:o,"aria-label":"Accent colour picker",onChange:l=>r({accentColor:l.target.value})}),e.jsx("input",{type:"text",value:n.accentColor??"",placeholder:"#3355e6",disabled:o,"aria-label":"Accent colour",onChange:l=>r({accentColor:l.target.value})})]})]})]}),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.closed,disabled:o,onChange:l=>r({closed:l.target.checked||void 0})}),"Closed — stop accepting responses"]}),n.closed&&e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Closed message"}),e.jsx("input",{type:"text",value:n.closedMessage??"",placeholder:"This form is no longer accepting responses.",disabled:o,"aria-label":"Closed message",onChange:l=>r({closedMessage:l.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Custom CSS"}),e.jsx("textarea",{rows:8,className:"w6w-form-css",value:n.customCss??nn,spellCheck:!1,wrap:"off",disabled:o,"aria-label":"Custom CSS",onChange:l=>r({customCss:l.target.value===nn?void 0:l.target.value})})]})]})]})}function Io(t,s,o,n){return t.find(r=>r.nodeId===s&&r.appId===o&&r.triggerKey===n)??null}function Po(t){return(t??"").split(`
|
|
2
|
-
`).map(s=>s.trim().replace(/^(\d+[.)]|[-•*])\s+/,"")).filter(s=>s!=="")}function Ro({workflowId:t,nodeId:s,appId:o,triggerKey:n,appName:r,setup:c,connectionId:l,params:f,readOnly:d}){const x=i.useW6WApi(),[h,m]=u.useState(void 0),[k,j]=u.useState(null),y=u.useRef(null),C=JSON.stringify({connectionId:l,params:f});u.useEffect(()=>{const O=x.listSubscriptionsForWorkflow,I=x.createSubscription;if(!O){m(null);return}let R=!1;return m(void 0),j(null),y.current=null,(async()=>{const E=Io(await O.call(x,t),s,o,n);if(d||!I||E&&E.status!=="pending")return E;const V=await I.call(x,o,n,{workflowId:t,connectionId:l,params:f,nodeId:s});return y.current=C,V})().then(E=>!R&&m(E)).catch(E=>{R||(m(null),j(E instanceof Error?E.message:String(E)))}),()=>{R=!0}},[x,t,s,o,n,d]);const M=(h==null?void 0:h.status)==="pending"?h.id:null;u.useEffect(()=>{const O=x.createSubscription;if(!M||d||!O||y.current===null||y.current===C)return;const I=setTimeout(()=>{y.current=C,O.call(x,o,n,{workflowId:t,connectionId:l,params:f,nodeId:s}).then(R=>{j(null),m(R)}).catch(R=>j(R instanceof Error?R.message:String(R)))},600);return()=>clearTimeout(I)},[x,M,d,C,o,n,t,s]);const w=h==null?void 0:h.webhookUrl,F=Po(c.instructions),W=(h==null?void 0:h.lastFireAt)??null;return e.jsxs("div",{className:"w6w-stack w6w-url-panel","data-testid":"manual-webhook-panel",children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:[e.jsx("strong",{children:"Webhook URL"})," — ",r," sends its events here."]}),k&&e.jsx("div",{className:"w6w-result w6w-error",children:k}),w?e.jsx("div",{className:"w6w-listen-url",children:e.jsx(we.Copyable,{value:w,readOnly:!0,children:e.jsx("input",{type:"text",readOnly:!0,value:w,"aria-label":"Webhook URL"})})}):h===void 0?e.jsx("p",{className:"w6w-muted w6w-small",children:"Getting the webhook URL…"}):!k&&e.jsx("p",{className:"w6w-muted w6w-small",children:"The webhook URL appears once the workflow is saved."}),e.jsxs("div",{className:"w6w-manual-webhook-note",role:"note","data-testid":"manual-webhook-note",children:[e.jsxs("strong",{children:["Add this URL in ",r," before the trigger works."]})," W6W can't add it for you, and nothing reaches this trigger until it is there."]}),F.length>0&&e.jsxs("div",{className:"w6w-manual-webhook-steps",children:[e.jsxs("span",{className:"w6w-small",children:["How to add it in ",r]}),e.jsx("ol",{className:"w6w-small","data-testid":"manual-webhook-steps",children:F.map((O,I)=>e.jsx("li",{children:O},I))})]}),h&&e.jsx("p",{className:"w6w-muted w6w-small","data-testid":"manual-webhook-status",children:W?`Last event received ${new Date(W).toLocaleString()}.`:h.status==="registered"?`Listening. No event from ${r} yet.`:"Starts the workflow once it is published."})]})}function Fo(t,s){return s===void 0?[...t]:t.includes(s)?[...t]:[s]}function Do(t,s,o={}){const n=[],r=t.length;if(r>0){const c=r>1?` ${r} nodes`:"";n.push({action:"duplicate",label:`Duplicate${c}`,disabled:s}),r===1&&o.replaceableTrigger&&n.push({action:"replace-trigger",label:"Replace trigger",disabled:s}),n.push({action:"delete",label:`Delete${c}`,disabled:s,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:s,separated:r>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:s}),n}const Nn=200,Cn=200,kn=10240;function ns(t){const s={};for(const[o,n]of Object.entries(t))s[o]=Math.round(n);return s}const Lo=t=>!!t&&Number.isFinite(t.x)&&Number.isFinite(t.y),Mo=t=>!!t&&Number.isFinite(t.width)&&Number.isFinite(t.height);function an(t,s,o){return t&&t.map(n=>{const r=s==null?void 0:s[n.id],c=Lo(r==null?void 0:r.position)?r.position:n.position,l=Mo(r==null?void 0:r.size)?r.size:n.size;return{...n,position:ns(c),size:ns(l)}})}function En(t,s,o){if(!s)return t;const n={...t};return t.notes&&(n.notes=an(t.notes,o)),t.sections&&(n.sections=an(t.sections,o)),n}function us(t,s){return t.sections?{...t,sections:t.sections.map(o=>({...o,nodes:o.nodes.filter(n=>n!==s)}))}:t}function os(t,s,o){return t.sections?{...t,sections:t.sections.map(n=>({...n,nodes:n.nodes.map(r=>r===s?o:r)}))}:t}function is(t,s,o){if(!t.sections)return t;const n=new Set(o);return{...t,sections:t.sections.map(r=>{const c=r.nodes.filter(l=>!n.has(l));return r.id===s?{...r,nodes:[...new Set([...c,...o])]}:{...r,nodes:c}})}}function Tn(t,s){return(t.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function _o(t,s){const o=new TextEncoder;if(o.encode(t).length<=s)return t;let n="",r=0;for(const c of t){const l=o.encode(c).length;if(r+l>s)break;n+=c,r+=l}return n}function rs(t){const s={...t};return t.notes&&(s.notes=t.notes.slice(0,Nn).map(o=>({...o,content:_o(o.content,kn)}))),t.sections&&(s.sections=t.sections.slice(0,Cn)),s}function Oo(t,s,o){const n={};for(const l of[...t.notes??[],...t.sections??[]])n[l.id]={position:l.position,size:l.size};const r=(l,f)=>l==null?void 0:l.map(d=>{const x=f==null?void 0:f.find(h=>h.id===d.id);return x?{...d,position:x.position,size:x.size}:d}),c=o?t:{...t,...t.notes?{notes:r(t.notes,s==null?void 0:s.notes)}:{},...t.sections?{sections:r(t.sections,s==null?void 0:s.sections)}:{}};return En(c,o,n)}const ln=220;function $o(t){return t.length<=ln?{text:t,clipped:!1,length:t.length}:{text:t.slice(0,ln).trimEnd(),clipped:!0,length:t.length}}function Wo({params:t,values:s,testStartState:o,view:n="props",literalKeys:r}){const{sampleValues:c,nodeConfig:l,nodeMeta:f}=i.useExpressionOptions(),d=u.useMemo(()=>i.buildResolveScope(c,o,l,f),[c,o,l,f]),x=i.flattenParams(t),h=j=>{var y;return s[j]!==void 0?s[j]:(y=x.find(C=>C.key===j))==null?void 0:y.default},m=x.filter(j=>j.type!=="section"&&i.isParamVisible(j,h)).map(j=>Ae.effectiveParam(j,h));if(i.hasParamCustomization(s)){const j=i.previewCustomization(s.$merge,d,r),y=j!==null&&typeof j=="object"&&!Array.isArray(j),C=cn(m,s,d,r);for(const[w,F]of Object.entries(s))w!=="$merge"&&(C[w]=r!=null&&r.includes(w)?F:i.previewCustomization(F,d));const M=y?{...C,...j}:C;return e.jsxs("div",{className:"w6w-resolved-params",children:[e.jsx("p",{className:"w6w-muted w6w-small",children:y?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(j)}). Test the step to validate it.`}),n==="code"?e.jsx(i.JsonEditor,{value:JSON.stringify(M,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):e.jsx("div",{className:"w6w-resolved-table",children:Object.entries(M).map(([w,F])=>{var W;return e.jsx(as,{label:((W=x.find(O=>O.key===w))==null?void 0:W.label)??w,segments:[{status:"resolved",value:F}]},w)})})]})}if(n==="code"){const j=cn(m,s,d,r);return e.jsx("div",{className:"w6w-resolved-params",children:e.jsx(i.JsonEditor,{value:JSON.stringify(j,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const k=m.filter(j=>!i.deepEqual(h(j.key),j.default));return m.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):k.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):e.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:k.map(j=>j.type==="vars"?e.jsx(Bo,{param:j,value:s[j.key],scope:d},j.key):e.jsx(as,{label:j.label??j.key,segments:r!=null&&r.includes(j.key)?[{status:"resolved",value:h(j.key)}]:i.resolveParamValue(h(j.key),d)},j.key))})}function cn(t,s,o,n){const r={};for(const c of t)if(n!=null&&n.includes(c.key))r[c.key]=s[c.key]!==void 0?s[c.key]:c.default;else if(c.type==="vars"){const l=s[c.key]??c.default??[],f=i.dataVarRows(l);r[c.key]=f?i.resolveVarsJson(f,o):i.resolveParamJson(l,o)}else r[c.key]=i.resolveParamJson(s[c.key]!==void 0?s[c.key]:c.default,o);return r}function as({label:t,segments:s}){return e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t}),e.jsx("div",{className:"w6w-resolved-value",children:e.jsx(An,{segments:s})})]})}function Bo({param:t,value:s,scope:o}){const n=s??t.default??[],r=i.dataVarRows(n);return r===null?e.jsx(as,{label:t.label??t.key,segments:i.resolveParamValue(n,o)}):e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t.label??t.key}),r.length===0?e.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):e.jsx("div",{className:"w6w-stack",children:r.map((c,l)=>e.jsxs("div",{className:"w6w-resolved-value",children:[e.jsx("code",{children:c.key||"(no key)"})," → ",e.jsx(An,{segments:i.resolveParamValue(c.value,o)})]},l))})]})}function An({segments:t}){return e.jsx(e.Fragment,{children:t.map((s,o)=>e.jsx(Vo,{segment:s},o))})}function Vo({segment:t}){switch(t.status){case"resolved":return t.ref?e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx(dn,{value:t.value})]}):e.jsx(dn,{value:t.value});case"unresolved":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"expr"}),e.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return e.jsx(wt,{kind:"secret",refName:t.ref})}}function dn({value:t}){const[s,o]=u.useState(!1),n=Uo(t),r=$o(n);return r.clipped?e.jsxs(e.Fragment,{children:[s?e.jsx(we.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:e.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):e.jsxs("span",{children:[r.text,"…"]}),e.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>o(c=>!c),children:s?"Show less":`Show all (${r.length.toLocaleString()} characters)`})]}):e.jsx("span",{children:n})}const zo={var:"◆",secret:"🔒",expr:"ƒ"};function wt({kind:t,refName:s}){const o=t==="expr"?"expr":i.varLabel(s??"");return e.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${t}`,children:[e.jsx("span",{className:"w6w-expr-chip-sigil",children:zo[t]}),e.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function Uo(t){if(t===null)return"null";if(t===void 0)return"(not set)";if(t==="")return'""';if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t)}catch{return String(t)}}function In(t){return t.language==="python"||t.language==="typescript"?t.language:"javascript"}function Ho({enabled:t,values:s,onChange:o}){const[n,r]=u.useState(null),c=u.useRef(!1),l=typeof s.code=="string"?s.code:"";return u.useEffect(()=>{if(!t||c.current)return;c.current=!0;const f=i.convertCodeBindingsToReads(l,In(s));f.converted!==0&&(r({original:l,converted:f.converted}),o({...s,code:f.code}))},[t,l,s,o]),n?{converted:n.converted,undo:()=>{o({...s,code:n.original}),r(null)}}:null}function Jo({values:t,conversion:s,readOnly:o}){const n=typeof t.code=="string"?t.code:"",r=s,c=i.findCodeBindings(n,In(t)).length;return!r&&c===0?null:e.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[r&&e.jsxs(e.Fragment,{children:["Converted ",r.converted," reference",r.converted===1?"":"s"," to code reads",!o&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:r.undo,children:"Undo"})]}),c>0&&" · "]}),c>0&&e.jsxs(e.Fragment,{children:[c," ",e.jsx("code",{children:"{{ }}"})," left in the code stay",c===1?"s":""," literal text — read ",c===1?"it":"them"," from"," ",e.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function un(t,s){return{nodeIds:t.filter(o=>o.selected).map(o=>o.id),edgeIds:s.filter(o=>o.selected).map(o=>o.id)}}function qo(t,s,o,n){const r=new Set(t.nodeIds),c=new Set(t.edgeIds),l=s.filter(m=>r.has(m.id)),f=[...l.filter(m=>i.isForeachStep(m.data.step)),...l.filter(m=>!i.isForeachStep(m.data.step))];let d=s,x=o,h=n;for(const m of f)x=i.bridgeDeletedBodyStep(m.id,d,x),d=d.filter(k=>k.id!==m.id),h=us(h,m.id);return{nodes:d,edges:x.filter(m=>!c.has(m.id)),canvas:h}}function Go(t,s,o){var f;const n=new Set(t.nodeIds),r=new Set(t.edgeIds),c=o.filter(d=>r.has(d.id)&&!n.has(d.source)&&!n.has(d.target)),l=[];if(n.size===1)l.push(i.deleteStepMessage(t.nodeIds[0],s,o));else if(n.size>1){l.push(`Delete nodes ${[...n].map(x=>`"${x}"`).join(", ")}? Their connections are removed too.`);const d=new Set;for(const x of n)if(i.isForeachStep((f=s.find(h=>h.id===x))==null?void 0:f.data.step))for(const h of i.loopBody(x,s,o))n.has(h)||d.add(h);d.size&&l.push(`Loop body steps ${[...d].map(x=>`"${x}"`).join(", ")} stay as standalone steps.`)}return c.length&&l.push(`Delete ${c.length===1?"connection":"connections"} ${c.map(d=>`"${d.source} → ${d.target}"`).join(", ")}?`),l.join(" ")}function Mt(t,s,o,n,r){const c=i.flowToWorkflow({...t,connections:n},s,o);return{nodes:c.nodes.map(({with:l,...f})=>l&&Object.keys(l).length?{...f,with:l}:f),edges:c.edges??[],connections:c.connections??{},canvas:r,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function Ko(t,s){const o=i.workflowToFlow({...t,...s});return{...o,nodes:o.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class Yo{constructor(s,o=100){at(this,"past",[]);at(this,"future",[]);at(this,"present");at(this,"group");at(this,"limit");this.limit=o,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,o){const n=JSON.stringify(s);n!==this.present&&((!o||o!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=o,this.future=[])}mark(){return this.present}rollbackTo(s){if(this.present===s)return;const o=this.past.lastIndexOf(s);return o>=0&&(this.past.length=o),this.present=s,this.future=[],this.group=void 0,JSON.parse(s)}undo(){const s=this.past.pop();if(s!==void 0)return this.future.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}redo(){const s=this.future.pop();if(s!==void 0)return this.past.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}}function Qt(t){var o;const s=t;return!!(s!=null&&s.isContentEditable||(o=s==null?void 0:s.closest)!=null&&o.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Xo=64,gt=24,et=32;function _t(t){var s,o;return{width:((s=t.measured)==null?void 0:s.width)??t.width??200,height:((o=t.measured)==null?void 0:o.height)??t.height??64}}function Zo(t,s){return t.x<s.x+s.width&&t.x+t.width>s.x&&t.y<s.y+s.height&&t.y+t.height>s.y}function Qo(t){const s=(r,c)=>{const l=new Map;for(const x of t){const h=x.position[r];l.set(h,Math.max(l.get(h)??0,_t(x)[c]))}const f=new Map;let d=Number.NEGATIVE_INFINITY;for(const[x,h]of[...l].sort(([m],[k])=>m-k)){const m=Math.max(x,d);f.set(x,m),d=m+h+Xo}return f},o=s("x","width"),n=s("y","height");return t.map(r=>({...r,position:{x:o.get(r.position.x)??r.position.x,y:n.get(r.position.y)??r.position.y}}))}function ei(t,s,o){var f;const n=Qo(i.relayoutNodes(t,s));if(!((f=o.sections)!=null&&f.length))return{nodes:n,canvas:o};const r=new Map(n.map(d=>[d.id,d])),c=(o.notes??[]).map(d=>({...d.position,...d.size}));for(const d of o.sections)d.nodes.some(x=>r.has(x))||c.push({...d.position,...d.size,y:d.position.y-et,height:d.size.height+et});const l=o.sections.map(d=>{const x=new Set(d.nodes),h=n.filter(F=>x.has(F.id));if(!h.length)return d;const m=Math.min(...h.map(F=>F.position.x))-gt,k=Math.min(...h.map(F=>F.position.y))-gt,j=Math.max(...h.map(F=>F.position.x+_t(F).width)),y=Math.max(...h.map(F=>F.position.y+_t(F).height)),C={x:m,y:k,width:j+gt-m,height:y+gt-k},M=[...c,...[...r.values()].filter(F=>!x.has(F.id)).map(F=>({...F.position,..._t(F)}))].sort((F,W)=>F.y-W.y);for(const F of M){const W={...C,y:C.y-et,height:C.height+et};Zo(W,F)&&(C.y=F.y+F.height+gt+et)}const w=C.y-k;for(const F of h)r.set(F.id,{...F,position:{x:F.position.x,y:F.position.y+w}});return c.push({...C,y:C.y-et,height:C.height+et}),{...d,position:{x:C.x,y:C.y},size:{width:C.width,height:C.height}}});return{nodes:n.map(d=>r.get(d.id)??d),canvas:{...o,sections:l}}}const es=6;function ti(t){let s=2166136261;for(let o=0;o<t.length;o++)s^=t.charCodeAt(o),s=Math.imul(s,16777619);return s>>>0}function si(t){const s=new Map;let o=new Set;for(const n of[...new Set(t)].sort()){o.size===es&&(o=new Set);let r=ti(n)%es;for(;o.has(r);)r=(r+1)%es;o.add(r),s.set(n,r+1)}return s}function ps(t){return`var(--w6w-loop-${t})`}function Pn(t,s){const o=[],n=new Set([t]);for(let r=s.get(t);r&&!n.has(r);r=s.get(r))n.add(r),o.unshift(r);return o}function ni(t,s,o){return s.size===0?t:t.map(n=>{var l;if(((l=n.data)==null?void 0:l.when)!=="each")return n;const r=n.sourceHandle===i.EACH_SOURCE_HANDLE?n.source:o.get(n.source),c=r?s.get(r):void 0;return c===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":ps(c)}}})}function oi(t,s){const o=s.get(t);return o===void 0?void 0:{"--w6w-loop-color":ps(o)}}function ii(t){const s=[];for(const o of t){const n=i.isForeachStep(o.data.step);(n||o.data.loopOf)&&s.push([o.id,n?1:0,o.data.loopOf])}return JSON.stringify(s)}function ri(t){const s=JSON.parse(t);return{tones:si(s.filter(o=>o[1]===1).map(o=>o[0])),loopOf:new Map(s.map(o=>[o[0],o[2]]))}}const pn="Paused — test runs stop before this node",fn="Disabled — skipped in every run";function tt(t){var s;return((s=t.ui)==null?void 0:s.paused)===!0}function We(t){return t.disabled===!0}function Rn(t,s){const{ui:o,...n}=t,{paused:r,...c}=o??{},l=s?{...c,paused:!0}:c;return Object.keys(l).length>0?{...n,ui:l}:n}function Fn(t,s){const{disabled:o,...n}=t;return s?{...n,disabled:!0}:n}function ls(t,s){return t.filter(o=>o.id!==s&&tt(o)).map(o=>o.id)}const ai=["nodes","steps"];function hn(t,s){for(const o of ai){const n=`${o}.${s}.output`;if(!t.startsWith(n))continue;const r=t.slice(n.length);if(r===""||r[0]==="."||r[0]==="[")return`foreach.item${r}`}return null}function Ot(t,s,o){if(typeof t=="string"){if(!t.includes("{{"))return t;const n=i.parseRootAnchoredTemplate(t);let r=!1;const c=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const f=hn(l.ref,s);return f===null?l:(r=!0,o.includes(l.ref)||o.push(l.ref),{...l,ref:f})});return r?Ae.serializeTemplate(c):t}if(i.isDollarPath(t)){const n=t.$;if(typeof n!="string")return t;const r=hn(n,s);return r===null?t:(o.includes(n)||o.push(n),{$:r})}if(Array.isArray(t)){let n=!1;const r=t.map(c=>{const l=Ot(c,s,o);return l!==c&&(n=!0),l});return n?r:t}if(typeof t=="object"&&t!==null){let n=!1;const r={};for(const[c,l]of Object.entries(t)){const f=Ot(l,s,o);f!==l&&(n=!0),r[c]=f}return n?r:t}return t}function li(t){if(typeof t=="string"){if(!t.includes("{{"))return!1;const s=i.parseRootAnchoredTemplate(t);return s.length===1&&s[0].kind==="var"}return i.isDollarPath(t)&&typeof t.$=="string"}function Dn(t){return Array.isArray(t)&&t.length===1&&li(t[0])}function ci(t){var s;try{const o=i.normalizeInput(t);if(!Array.isArray(o.nodes))return{};const n={},r=(l,f)=>{const d=Object.hasOwn(n,l)?n[l]:[];d.push(f),n[l]=d},c=new Map(o.nodes.map(l=>[l.id,l]));for(const[l,f]of Object.entries(i.definitionLoops(o))){const d=c.get(l);if(d&&Dn((s=d.with)==null?void 0:s.items)&&r(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){r(l,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const x of f.body){const h=c.get(x);if(!(h!=null&&h.with))continue;const m=[];Ot(h.with,l,m),m.length>0&&r(x,{code:"foreach_body_refs_output",foreachId:l,refs:m,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function di(t){const s=new Set,o=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const r of n)o(r)};return o(t),s}function ui(t){var s,o;try{const n=i.normalizeInput(t);if(!Array.isArray(n.nodes))return[];const r=n.nodes.filter(I=>typeof I=="object"&&I!==null&&typeof I.id=="string"),c=i.effectiveEdges({...n,nodes:r}).filter(I=>typeof(I==null?void 0:I.from)=="string"&&typeof(I==null?void 0:I.to)=="string"),l=[];for(const I of r)try{const R=Ae.staticWritePaths(Ae.effectiveStateConfig((s=I.uses)==null?void 0:s.app,(o=I.uses)==null?void 0:o.action,I.state));R.length>0&&l.push({id:I.id,paths:R})}catch{}if(l.length<2)return[];const f=new Map;for(const I of r)for(const R of i.controlOwnedIds(I))f.has(R)||f.set(R,I.id);const d=I=>{const R=[I];let E=I;for(;f.has(E)&&(E=f.get(E),!R.includes(E));)R.push(E);return R},x=I=>{const R=d(I);return R[R.length-1]},h=new Map;for(const I of c){const R=h.get(I.from)??[];R.push(I.to),h.set(I.from,R)}const m=new Map,k=I=>{const R=m.get(I);if(R)return R;const E=new Set,V=[...h.get(I)??[]];for(;V.length>0;){const K=V.pop();if(!E.has(K)){E.add(K);for(const S of h.get(K)??[])V.push(S)}}return m.set(I,E),E},j=(I,R)=>I===R||k(I).has(R),y=r.filter(I=>{var R;return((R=I.uses)==null?void 0:R.app)===i.CONTROL_APP&&I.uses.action==="parallel"}).map(I=>{var E;const R=(E=I.with)==null?void 0:E.branches;return Array.isArray(R)?R.map(di):[]}),C=(I,R)=>{for(const E of d(R)){const V=I.findIndex(K=>K.has(E));if(V>=0)return V}return-1},M=[];for(const I of r){if(I.fanOut!=="parallel")continue;const R=new Map;for(const E of c){if(E.from!==I.id||i.isEachLink(E))continue;const V=E.when??"success",K=R.get(V)??[];K.push(E.to),R.set(V,K)}for(const E of R.values())E.length>=2&&M.push(E)}const w=(I,R)=>{for(const K of y){const S=C(K,I),g=C(K,R);if(S>=0&&g>=0&&S!==g)return!0}const E=x(I),V=x(R);return E===V||k(E).has(V)||k(V).has(E)?!1:M.some(K=>K.some((S,g)=>K.some((P,Y)=>g!==Y&&j(S,E)&&j(P,V))))},F=new Set,W=[];for(let I=0;I<l.length;I++)for(let R=I+1;R<l.length;R++){const E=l[I],V=l[R];if(!(E.id===V.id||!w(E.id,V.id)))for(const K of E.paths)for(const S of V.paths){if(!Ae.statePathsOverlap(K,S))continue;const g={code:"state_parallel_write",nodes:[E.id,V.id].sort(),path:[...K.length<=S.length?K:S]},P=JSON.stringify([g.nodes,g.path]);F.has(P)||(F.add(P),W.push(g))}}const O=(I,R)=>I<R?-1:I>R?1:0;return W.sort((I,R)=>O(I.code,R.code)||O(I.nodes.join(","),R.nodes.join(","))||O(I.path.join("."),R.path.join(".")))}catch{return[]}}function pi(t){try{const s={};for(const o of ui(t))for(const n of o.nodes){const r=Object.hasOwn(s,n)?s[n]:[];r.push({code:o.code,path:[...o.path],with:o.nodes.filter(c=>c!==n)}),s[n]=r}return s}catch{return{}}}function Ln(t,s){var o;if(s.code==="foreach_wrapped_items"){const n=(o=t.with)==null?void 0:o.items;return!t.with||!Dn(n)?t:{...t,with:{...t.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!t.with)return t;const n=Ot(t.with,s.foreachId,[]);return n===t.with?t:{...t,with:n}}return t}function mn(t,s,o){return t&&t.nodeId===s&&t.handleType===((o==null?void 0:o.type)??"source")?i.laneForSourceHandle(t.handleId):i.laneForSourceHandle(o==null?void 0:o.id)}function fi(t,s,o,n,r){var x;const c=(x=n.find(h=>h.id===t))==null?void 0:x.data.step,l=i.loopMembership(n,r)[t]!==void 0,f=o==="success"&&l?"each":o;if(f==="each"&&!l&&!i.isForeachStep(c))return null;const d=o==="success"&&i.isForeachStep(c)?i.FOREACH_DONE_ROUTE:void 0;return i.loopRefusal(t,s,f,n,r,d)}function $t(t,s){var o;return(o=t.nodes??t.steps)==null?void 0:o[s]}function cs(t,s){const o=$t(t,s);return(o==null?void 0:o.status)==="skipped"&&o.skipReason==="not_on_path"}const hi=new Set(["succeeded","failed","canceled"]);function mi(t,s,o=[]){var c,l;if(!t||[...o,s].some(f=>cs(t,f)))return"no-run";const n=$t(t,s);if(n)return n.status;const r=new Set;for(const f of Object.values(t.nodes??t.steps??{}))if(Array.isArray(f==null?void 0:f.iterations))for(const d of f.iterations){const x=(l=(c=d==null?void 0:d.nodes)==null?void 0:c[s])==null?void 0:l.status;x&&r.add(x)}for(const f of["failed","running","succeeded","skipped"])if(r.has(f))return f;return"pending"}const wn={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function Mn(t,s){const o=s!==void 0&&hi.has(s);switch(t){case"no-run":return wn;case"pending":return o?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return wn}}function wi(t,s,o,n,r){var l;if(!t||cs(t,s)||r!==void 0&&cs(t,r))return;const c=gi(t,s,o,n);return c==="taken"&&r!==void 0&&((l=$t(t,r))==null?void 0:l.status)==="skipped"?"skipped":c}function gi(t,s,o,n){const r=$t(t,s);if(!r)return;if(o==="each")return r.status==="skipped"?"skipped":void 0;const c=o??"success",l=r.output,f=n===i.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!f&&r.status==="succeeded")return l&&typeof l=="object"&&"matched"in l?n==="false"!=(l.matched===!0)?"taken":"skipped":l&&typeof l=="object"&&"route"in l&&l.route===n?"taken":"skipped";if(r.status==="succeeded")return c==="success"?"taken":"skipped";if(r.status==="failed")return c==="error"?"taken":"skipped";if(r.status==="skipped")return"skipped"}const gn={fields:[],sampleValues:{}};function fs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function xi(t,s){var x;const o=t.map(h=>h.id),n=new Set(o),r=new Map(o.map(h=>[h,0])),c=new Map(o.map(h=>[h,[]]));for(const h of s)!n.has(h.source)||!n.has(h.target)||((x=c.get(h.source))==null||x.push(h.target),r.set(h.target,(r.get(h.target)??0)+1));const l=[],f=o.filter(h=>r.get(h)===0);for(;f.length>0;){const h=f.shift();l.push(h);for(const m of c.get(h)??[]){const k=(r.get(m)??0)-1;r.set(m,k),k===0&&f.push(m)}}const d=new Set(l);for(const h of o)d.has(h)||l.push(h);return l}const bi=new Set(["string","number","boolean","object","array"]);function xt(t){if(!Array.isArray(t))return;const s={type:"object",fields:{}};let o=!1;for(const n of t){if(!fs(n)||typeof n.key!="string"||n.key==="")continue;const r=n.key.split(".");let c=s;for(const d of r.slice(0,-1)){const x=c.fields[d];(x==null?void 0:x.type)!=="object"&&(c.fields[d]={type:"object",fields:{}}),c=c.fields[d]}const l=typeof n.type=="string"&&bi.has(n.type)?n.type:"string";let f;if(l==="array"){const d=xt(n.items);f=d?{type:"array",items:d}:{type:"array"}}else l==="object"?f=xt(n.fields??n.properties)??{type:"object",fields:{}}:f={type:l};c.fields[r[r.length-1]]=f,o=!0}return o?s:void 0}function ji(t,s){var x,h,m,k,j,y,C;const o=t.data.step,n=((x=s.testOutputs)==null?void 0:x[o.id])??((h=s.persistedOutputs)==null?void 0:h[o.id]);if(n!=null)return n;const{app:r,action:c}=o.uses;if(r===i.TRIGGER_APP&&((m=i.internalNodeDef(r,c))==null?void 0:m.group)==="trigger"){const M=i.fieldsToParams(i.asFieldDefs((k=o.with)==null?void 0:k.fields)).map(w=>({key:w.key}));return i.shapeToSkeleton(xt(M))}const l=(j=i.internalNodeDef(r,c))==null?void 0:j.output;if(l&&l.length>0)return i.shapeToSkeleton(xt(l));const f=o.uses.trigger===!0?(y=s.triggerDef)==null?void 0:y.call(s,r,c):(C=s.actionDef)==null?void 0:C.call(s,r,c),d=xt(f==null?void 0:f.output);return d?i.shapeToSkeleton(d):f==null?void 0:f.sample}function vi(t,s){var f,d,x,h,m;const o=t.data.step,n=(f=s.previewOutputs)==null?void 0:f[o.id];if(n!=null)return n;const{app:r,action:c}=o.uses,l=o.uses.trigger===!0?(x=(d=s.shapes)==null?void 0:d.triggerDef)==null?void 0:x.call(d,r,c):(m=(h=s.shapes)==null?void 0:h.actionDef)==null?void 0:m.call(h,r,c);return l==null?void 0:l.sample}function yi(t){switch(t){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function xn(t,s){const o=fs(t.initialState)?{...t.initialState}:{};for(const n of t.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?o[n.key]=n.default:s||(o[n.key]=yi(n.type)));return o}function ts(t){return(i.inferOutputFields(t)??[]).map(s=>s.key)}function Si(t){const{anchorId:s,nodes:o,edges:n}=t;if(!s)return gn;const r=t.shapes??{},c=t.floating?new Set(o.map(E=>E.id)):i.ancestorIds(s,n);c.delete(s);const l=new Map(o.map(E=>[E.id,E])),f=[],d=[],x=new Map;for(const E of xi(o,n)){if(!c.has(E))continue;const V=l.get(E);if(!V)continue;const{app:K,action:S}=V.data.step.uses,g=Ae.effectiveStateConfig(K,S,V.data.step.state);if(g.mode==="off")continue;const P=ji(V,r);if(P!==void 0){const{ops:B}=Ae.computeStateWrites(g,P);f.push(...B);for(const ne of ts(Ae.foldState({},B))){const Z=x.get(ne)??new Set;Z.add(E),x.set(ne,Z)}}const Y=vi(V,t);Y!==void 0&&d.push(...Ae.computeStateWrites(g,Y).ops)}const h=xn(t,!1),m=Ae.foldState(h,f),k=ts(m);if(k.length===0)return gn;const j=new Set(ts(h)),y=new Map,C=new Map;for(const E of n)c.has(E.source)&&(!c.has(E.target)&&E.target!==s||(y.set(E.target,[...y.get(E.target)??[],E.source]),C.set(E.source,[...C.get(E.source)??[],E.target])));const M=[...c].filter(E=>!(y.get(E)??[]).length),w=E=>{const V=new Set,K=M.filter(S=>!E.has(S));for(;K.length>0;){const S=K.pop();if(S===s)return!1;if(!V.has(S)){V.add(S);for(const g of C.get(S)??[])E.has(g)||K.push(g)}}return!0},F=Ae.foldState(xn(t,!0),d),W=d.length>0?Ae.foldState({},d):void 0,O=fs(W)&&Object.keys(W).length>0?W:void 0,I=[],R={};for(const E of k){const V=x.get(E)??new Set,K=j.has(E)||V.size>0&&w(V);I.push({key:E,path:!0,paths:K?"all":"some"});const S=i.valueAtPath(F,E);S!==void 0&&(R[`state.${E}`]=S)}return{fields:I,sampleValues:R,...O?{written:O}:{}}}const Ni={registered:{label:"Registered",tone:"ok"},pending:{label:"Registering",tone:"pending"},failed:{label:"Registration failed",tone:"danger"},paused:{label:"Paused",tone:"muted"},destroying:{label:"Removing",tone:"muted"}},bn="Never fired";function Ci(t){if(!t)return bn;const s=new Date(t);return Number.isNaN(s.getTime())?bn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function ki(t,s){var r;if(!(t!=null&&t.status))return null;const o=Ni[t.status];if(!o)return null;const n=t.status==="failed";return{label:o.label,tone:o.tone,error:n?((r=t.lastError)==null?void 0:r.message)??null:null,lastFire:Ci(t.lastFireAt),retryVisible:n&&s}}function Ei(t){const s=new Map;for(const o of t)o.nodeId&&s.set(o.nodeId,o);return s}function Ti(t){return(t??[]).filter(s=>{var o;return((o=s.uses)==null?void 0:o.trigger)===!0})}function Ai(t,s){const[o,n]=u.useState({}),r=u.useRef(new Set),c=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return u.useEffect(()=>{const l=JSON.parse(c).filter(f=>!r.current.has(f));if(l.length!==0){for(const f of l)r.current.add(f);Promise.all(l.map(async f=>{try{return[f,await t.getAppActions(f)]}catch{return r.current.delete(f),null}})).then(f=>{const d=f.filter(x=>x!==null);d.length!==0&&n(x=>({...x,...Object.fromEntries(d)}))})}},[t,c]),o}function Ii(t,s){const[o,n]=u.useState({}),r=u.useRef(new Set),c=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return u.useEffect(()=>{const l=t.getAppTriggers;if(typeof l!="function")return;const f=JSON.parse(c).filter(d=>!r.current.has(d));if(f.length!==0){for(const d of f)r.current.add(d);Promise.all(f.map(async d=>{try{return[d,await l.call(t,d)]}catch{return r.current.delete(d),null}})).then(d=>{const x=d.filter(h=>h!==null);x.length!==0&&n(h=>({...h,...Object.fromEntries(x)}))})}},[t,c]),o}function Pi(t){return(s,o)=>{var n,r;return(r=(n=t[s])==null?void 0:n.find(c=>c.key===o))==null?void 0:r.ports}}const Ri="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function jn(t,s,o,n){const r=t.find(c=>c.id===s);return[o,n,r==null?void 0:r.source,r==null?void 0:r.target]}const hs=u.createContext(void 0),ms=u.createContext(new Map),ws=u.createContext({tones:new Map,loopOf:new Map});function vn(t){return`Can’t draw that edge: this node allows at most ${t} outgoing edge${t===1?"":"s"} per lane.`}const gs=u.createContext(new Map),_n=u.createContext({byNode:new Map,subs:[]});function Fi({apps:t,registration:s,children:o}){return e.jsx(gs.Provider,{value:t,children:e.jsx(_n.Provider,{value:s,children:o})})}const xs=u.createContext(null);function Di(t){return e.jsx(le.ReactFlowProvider,{children:e.jsx(Li,{...t})})}function yn(t,s){let o=s.length+1;for(;s.includes(`${t}-${o}`);)o++;return`${t}-${o}`}function ss(t){var s,o;return{x:t.position.x,y:t.position.y,w:((s=t.measured)==null?void 0:s.width)??t.width??200,h:((o=t.measured)==null?void 0:o.height)??t.height??64}}function Li({onConnectionResourcesChange:t,value:s,onChange:o,readOnly:n,height:r=480,apps:c,exprOptions:l,project:f,runState:d,stepProblems:x,onTestRun:h,fitViewKey:m,onRunFromNode:k}){var Ys,Xs,Zs,Qs,en,tn,sn;const j=i.useW6WApi(),y=u.useMemo(()=>new Map((c??[]).map(a=>[a.id,a])),[c]),C=Vi(s),[M,w]=u.useState(null),F=u.useMemo(()=>i.centralizeConnections(s),[s.id]),W=u.useMemo(()=>i.workflowToFlow(F),[F]),[O,I]=u.useState(F.connections??{}),R=u.useRef(O),E=u.useCallback(a=>{R.current=a,I(a)},[]),V=u.useCallback(a=>{const p=i.centralizeConnections({nodes:[a],connections:R.current});return p.connections!==R.current&&E(p.connections),p.nodes[0]},[E]),K=u.useMemo(()=>i.storedViewport(s),[s.id]),S=((Ys=s.settings)==null?void 0:Ys.savePosition)!==!1,[g,P,Y]=le.useNodesState(W.nodes),B=Ai(j,g),ne=Ii(j,g),Z=u.useMemo(()=>Pi(B),[B]),[A,X,D]=le.useEdgesState(W.edges),[z,U]=u.useState(null),ie=u.useMemo(()=>s.canvas??{},[s.id]),[J,H]=u.useState(ie),[q]=u.useState(()=>new Yo(Mt(F,W.nodes,W.edges,O,ie))),Q=u.useRef(),[fe,Je]=u.useState(0),[_e,lt]=u.useState(!1),[Se,qe]=u.useState(null),[Ie,ge]=u.useState(null),[ce,ke]=u.useState(null),[Be,oe]=u.useState(!1),bt=u.useRef({});u.useEffect(()=>{Be||(bt.current={})},[Be]);const[de,Pe]=u.useState(null),[Oe,Ee]=u.useState("props"),[xe,Ge]=u.useState(null),[ye,Ve]=u.useState(null),[Re,Fe]=u.useState(null),ct=u.useRef(!1),Ne=u.useRef(null),[be,$e]=u.useState(null),{screenToFlowPosition:De,fitView:Le}=le.useReactFlow(),dt=i.useEffectiveTheme();u.useEffect(()=>{P(W.nodes),X(W.edges),U(null),ke(null),Fe(null),Pe(null),Ge(null),H(ie),E(F.connections??{}),q.reset(Mt(F,W.nodes,W.edges,F.connections??{},ie)),Q.current=void 0},[W,ie,F,P,X,E,q]),u.useEffect(()=>{P(a=>{const p=new Map(i.stampLoopOf(a,A).map(b=>[b.id,b.data.loopOf]));return a.map(b=>{const v=mi(d,b.id,Pn(b.id,p));return b.data.stepStatus===v&&b.data.runStatus===(d==null?void 0:d.status)?b:{...b,data:{...b.data,stepStatus:v,runStatus:d==null?void 0:d.status}}})}),X(a=>a.map(p=>{var L;const b=i.edgeLane(p),v=wi(d,p.source,b,typeof((L=p.data)==null?void 0:L.route)=="string"?p.data.route:void 0,p.target),N=i.edgeVisuals(b,v);return p.className===N.className&&p.label===N.label?p:{...p,className:N.className,label:N.label}}))},[d,W,fe,P,X]),u.useEffect(()=>{P(a=>i.applyStepProblems(a,x))},[x,W,fe,P]);const st=u.useCallback((a,p)=>{var N,L;const{canvas:b,...v}=a;return!((N=p.notes)!=null&&N.length)&&!((L=p.sections)!=null&&L.length)?v:{...v,canvas:Oo(p,s.canvas,S)}},[s.canvas,S]),ee=u.useCallback((a,p,b)=>{q.record(Mt(s,a,p,R.current,b??J),Be?bt.current:Q.current),o(st(i.flowToWorkflow({...s,connections:R.current},a,p),b??J))},[s,o,J,st,q,Be]),nt=u.useRef(()=>{});nt.current=a=>{if(n)return;const p=i.editConnectionResources(g.map(v=>v.data.step),R.current,a),b=g.map((v,N)=>({...v,data:{...v.data,step:p.nodes[N]}}));E(p.connections),P(b),ee(b,A)};const Ke=u.useCallback(a=>nt.current(a),[]),jt=u.useCallback(a=>{U(a),ke(null),P(p=>p.map(b=>({...b,selected:b.id===a}))),X(p=>p.map(b=>({...b,selected:!1}))),Le({nodes:[{id:a}],duration:300,maxZoom:1})},[P,X,Le]),[ut,ue]=u.useState(null),vt=u.useMemo(()=>ut?g.map(a=>a.id===ut?{...a,className:`${a.className??""} w6w-connection-highlight`.trim()}:a):g,[g,ut]),pt=g.map(a=>({id:a.data.step.id,uses:a.data.step.uses})),Bt=JSON.stringify(pt),yt=JSON.stringify([...y]);u.useEffect(()=>{t==null||t({workflowId:s.id,nodes:pt,apps:y,connections:O,readOnly:n,edit:Ke,focusNode:jt,highlightNode:ue})},[t,s.id,Bt,yt,O,n,Ke,jt]),u.useEffect(()=>()=>t==null?void 0:t(null),[t]);const St=u.useCallback(a=>i.canConnect(a.source,a.target,g,A,Z,i.routeFromHandle(a.sourceHandle)),[g,A,Z]),[ot,Me]=u.useState(null),T=u.useRef(null),te=u.useRef(null);u.useEffect(()=>{P(a=>i.stampLoopOf(a,A))},[A,P]);const ae=u.useCallback(a=>{if(n)return;const p=i.applyConnect(a.source,a.target,g,A,i.laneForSourceHandle(a.sourceHandle),Z,i.routeFromHandle(a.sourceHandle));if(!p){const b=i.laneForSourceHandle(a.sourceHandle),v=i.connectRefusal(a.source,a.target,g,A,b,Z,i.routeFromHandle(a.sourceHandle));if(v&&v.refused==="loop"){Me({nodeId:a.source,reason:v.reason});return}if(v){const L=A.find($=>$.source===a.source&&i.edgeLane($)===b);L&&(X(A.map($=>({...$,selected:$.id===L.id}))),ke(L.id),Xe({edgeId:L.id,message:vn(v.cap)}));return}const N=i.connectConflict(a.source,a.target,g,A,i.laneForSourceHandle(a.sourceHandle));if(!N)return;X(A.map(L=>({...L,selected:L.id===N}))),ke(N),Xe({edgeId:N,message:i.idClashMessage("Can’t draw that edge",N,jn(A,N,a.source,a.target))});return}Xe(null),Me(null),X(p),ee(g,p)},[A,g,X,ee,n,Z]),je=u.useCallback((a,p)=>{var G,se,pe;if(n||p.isValid)return;const b=p.fromNode;if(!b)return;const v=((G=p.fromHandle)==null?void 0:G.type)==="target"?"target":"source",N=p.toNode;if(N&&v==="source"){const re=fi(b.id,N.id,mn(te.current,b.id,p.fromHandle),g,A);if(re){Me({nodeId:b.id,reason:re});return}}const L=(se=g.find(re=>re.id===b.id))==null?void 0:se.data.step;if(L){const re=i.nodePortsForStep(L,Z);if((v==="source"?re.out:re.in)<1)return}const $="changedTouches"in a?a.changedTouches[0]:a,_=De({x:$.clientX,y:$.clientY});$e({nodeId:b.id,handleType:v,position:_,lane:mn(te.current,b.id,p.fromHandle),route:i.routeFromHandle((pe=p.fromHandle)==null?void 0:pe.id)}),oe(!0)},[n,De,g,A,Z]),Ye=u.useCallback((a,p,b)=>{if(n)return;const v=g.find(G=>G.id===a);if(!v)return;const N=ss(v),L=i.laneForSourceHandle(b),$=120,_=p==="target"?{x:N.x-N.w-$,y:N.y}:L==="error"?{x:N.x,y:N.y+N.h+$}:L==="each"?{x:N.x+N.w+$,y:N.y-N.h-$/2}:{x:N.x+N.w+$,y:N.y};$e({nodeId:a,handleType:p,position:_,lane:L,route:i.routeFromHandle(b)}),oe(!0)},[n,g]),js=u.useCallback(a=>{n||Fe({nodeIds:[a],edgeIds:[]})},[n]),Gn=u.useCallback(a=>{if(n)return;const p=qo(a,g,A,J);P(p.nodes),X(p.edges),H(p.canvas),p.nodes.some(b=>b.id===z)||U(null),p.nodes.some(b=>b.id===de)||Pe(null),p.edges.some(b=>b.id===ce)||ke(null),ee(p.nodes,p.edges,p.canvas)},[g,A,J,P,X,ee,n,z,de,ce]),vs=u.useCallback(()=>{if(n)return;const a=ei(g,A,J);P(a.nodes),H(a.canvas),ct.current=!0,ee(a.nodes,A,a.canvas)},[g,A,J,P,ee,n]),Kn=u.useCallback(()=>{n||vs()},[n,vs]);u.useEffect(()=>{ct.current&&(ct.current=!1,Le({duration:300}))},[g,Le]);const ys=u.useRef(m);u.useEffect(()=>{Object.is(ys.current,m)||(ys.current=m,Le({duration:300}))},[m,Le]);const[Nt,Xe]=u.useState(null),it=u.useMemo(()=>A.find(a=>a.id===ce)??null,[A,ce]),Yn=u.useCallback(a=>{if(n||!ce)return;const p=A.find($=>$.id===ce);if(!p||i.edgeLane(p)===a)return;const b=i.edgeWhenConflict(A,ce,a,g),v=i.relaneRefusal(A,ce,a,g,Z),N=b||v?null:i.setEdgeWhen(A,ce,a,g,Z);if(!N){if(v){Xe({edgeId:ce,message:vn(v.cap)});return}Xe({edgeId:ce,message:b?i.idClashMessage("Can’t switch this edge",b,jn(A,b,p.source,p.target)):"This edge can’t be switched right now."});return}Xe(null),X(N);const L=N.find($=>$.source===p.source&&$.target===p.target&&i.edgeLane($)===a);ke((L==null?void 0:L.id)??null),ee(g,N)},[A,g,X,ee,n,ce,Z]),Xn=u.useCallback(a=>{if(n)return;const p=A.filter(b=>b.id!==a);p.length!==A.length&&(X(p),ce===a&&ke(null),ee(g,p))},[g,A,X,ee,n,ce]),Vt=u.useCallback(a=>{if(n)return;const p=a.map(L=>g.find($=>$.id===L)).filter(L=>L!==void 0);if(p.length===0)return;const b=g.map(L=>L.id),v=p.map(L=>{const $=i.suggestStepId(b,`${L.data.step.id}_copy`);b.push($);const _={...i.stripBody(structuredClone(L.data.step)),id:$};return{id:$,type:L.type,position:{x:L.position.x+40,y:L.position.y+60},data:{step:_,isInternal:L.data.isInternal},...p.length>1?{selected:!0}:{}}}),N=[...p.length>1?g.map(L=>L.selected?{...L,selected:!1}:L):g,...v];P(N),U(v[0].id),ee(N,A)},[g,A,P,ee,n]),Ss=u.useCallback(a=>Vt([a]),[Vt]),Zn=u.useCallback(a=>{if(n)return;const p=i.isInternalApp(a.uses.app),b=g.map(re=>re.id),v=a.id&&!i.stepNameError(a.id,b)?a.id:i.suggestStepId(b,i.slugifyLabel(i.internalNodeLabel(a.uses.app,a.uses.action))),N=V({id:v,uses:a.uses,...a.with&&Object.keys(a.with).length>0?{with:a.with}:{}}),L={id:v,type:p?"control":"step",position:(be==null?void 0:be.position)??(ye==null?void 0:ye.position)??{x:80,y:80+g.length*24},data:{step:N,isInternal:p}},$=ye!=null&&ye.replaces?g.find(re=>re.id===ye.replaces):void 0;if($&&i.isTriggerStep(a.uses)){const re={...L,position:$.position},he=[...g.filter(mt=>mt.id!==$.id),re],me=i.renameStepInEdges(A,$.id,v),Te=os(J,$.id,v);return P(he),X(me),H(Te),Me(null),U(v),ee(he,me,Te),v}const _=[...g,L];let G=A,se=null;const pe=(re,he,me,Te)=>{const mt=i.connectRefusal(re,he,_,A,me,Z);mt&&mt.refused==="loop"&&(se={nodeId:Te,reason:mt.reason})};if(be){const[re,he]=be.handleType==="target"?[v,be.nodeId]:[be.nodeId,v],me=i.applyConnect(re,he,_,A,be.lane,Z,be.route);me||pe(re,he,be.lane,be.nodeId),G=me??A}else{const re=g.find(he=>i.isTriggerStep(he.data.step.uses));if(i.isTriggerStep(a.uses)){if(!re){const he=i.findChainRoot(g,A);if(he){const me=i.applyConnect(v,he.id,_,A,"success",Z);me||pe(v,he.id,"success",he.id),G=me??A}}}else{const me=(re&&!A.some(Te=>Te.source===re.id)?re:void 0)??i.findChainTail(g,A);if(me){const Te=i.applyConnect(me.id,v,_,A,"success",Z);Te||pe(me.id,v,"success",me.id),G=Te??A}}}return P(_),G!==A&&X(G),Me(se),U(v),ee(_,G),v},[g,A,P,X,ee,n,be,ye,Z,V,J]),Ns=u.useCallback((a,p)=>{var G;let b=p;const v=(G=g.find(se=>se.id===a))==null?void 0:G.data.step;if(p.uses.connection&&!p.uses.connectionRef&&(v!=null&&v.uses.connectionRef)&&v.uses.app===p.uses.app){const se=i.selectNodeConnection(i.withConnectionRef(p,v.uses.connectionRef),p.uses.connection,g.map(pe=>pe.data.step),R.current);E(se.connections),b=se.step}else b=V(p);const N=b.id!==a;if(N&&g.some(se=>se.id===b.id))return;const L=g.map(se=>se.id===a?{...se,id:b.id,data:{step:b,isInternal:i.isInternalApp(b.uses.app)}}:se);if(N){const se=i.renameStepInEdges(A,a,b.id),pe=os(J,a,b.id);P(L),X(se),H(pe),z===a&&U(b.id),de===a&&Pe(b.id),ee(L,se,pe);return}P(L);const $=new Set(i.routesForStep(b).map(se=>se.id)),_=A.filter(se=>{var pe;return se.source!==b.id||((pe=se.data)==null?void 0:pe.route)===void 0||$.has(String(se.data.route))});_.length!==A.length&&X(_),ee(L,_)},[g,A,J,P,X,z,de,ee,V,E]),Ze=u.useCallback(a=>{n||(H(a),ee(g,A,a))},[n,g,A,ee]),Qn=u.useCallback(()=>{var N;if(n)return;const a=(N=Ne.current)==null?void 0:N.getBoundingClientRect(),p=a?De({x:a.left+a.width/2,y:a.top+a.height/2}):{x:0,y:0},b=J.notes??[],v={id:yn("note",b.map(L=>L.id)),color:"#facc15",position:{x:Math.round(p.x-100),y:Math.round(p.y-60)},size:{width:200,height:120},content:""};Ze(rs({...J,notes:[...b,v]}))},[n,J,De,Ze]),eo=u.useCallback((a,p)=>{if(n)return;const b=p?Math.min(a.x,p.x):a.x,v=p?Math.min(a.y,p.y):a.y,N=p?Math.abs(p.x-a.x):360,L=p?Math.abs(p.y-a.y):240,$=g.filter(re=>{const he=ss(re),me=he.x+he.w/2,Te=he.y+he.h/2;return me>=b&&me<=b+N&&Te>=v&&Te<=v+L}).map(re=>re.id),_=J.sections??[],G=yn("section",_.map(re=>re.id)),se={id:G,title:"Section",color:"#6366f1",position:{x:Math.round(b),y:Math.round(v)},size:{width:Math.round(N),height:Math.round(L)},nodes:[]},pe={...J,sections:[..._,se]};Ze(rs(is(pe,G,$)))},[n,g,J,Ze]);u.useEffect(()=>{if(!_e)return;const a=p=>{p.key==="Escape"&&(lt(!1),qe(null))};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[_e]);const to=u.useCallback((a,p)=>{var $;if(n)return;const b=($=J.sections)==null?void 0:$.find(_=>_.id===a);if(!b)return;const v=new Set(b.nodes),N=g.map(_=>v.has(_.id)?{..._,position:{x:_.position.x+p.dx,y:_.position.y+p.dy}}:_),L={...J,sections:(J.sections??[]).map(_=>_.id===a?{..._,position:{x:_.position.x+p.dx,y:_.position.y+p.dy}}:_)};P(N),H(L),ee(N,A,L)},[n,J,g,A,P,ee]),so=u.useCallback((a,p)=>{if(n)return;const b=a==="note"?{...J,notes:(J.notes??[]).filter(v=>v.id!==p)}:{...J,sections:(J.sections??[]).filter(v=>v.id!==p)};Ze(b)},[n,J,Ze]),no=a=>{let p=J;for(const b of a){const v=ss(b),N=v.x+v.w/2,L=v.y+v.h/2,$=(p.sections??[]).find(G=>N>=G.position.x&&N<=G.position.x+G.size.width&&L>=G.position.y&&L<=G.position.y+G.size.height),_=Tn(p,b.id);$?(_.length!==1||_[0]!==$.id)&&(p=is(p,$.id,[b.id])):_.length>0&&(p=us(p,b.id))}return p},zt=u.useCallback((a,p,b)=>{(async()=>{const v=await j.saveStepTest(s.id,a,p).catch(N=>(console.error("step run fixture save failed",N),null));await j.recordStepTestRun(s.id,a,{stepTestId:(v==null?void 0:v.id)??null,status:b.status,input:p.input,output:b.output,error:b.error,...b.meta?{meta:b.meta}:{}})})().catch(v=>{console.error("step run persist failed",v)})},[j,s.id]),Cs=u.useCallback(a=>{const p=g.find(b=>b.id===a);!p||!k&&i.isControlApp(p.data.step.uses.app)||w({stepId:a,status:"collect"})},[g,k]),oo=u.useCallback(async(a,p,b)=>{if(!k)return;const v=g.find($=>$.id===a);if(!v)return;const N=i.isTriggerStep(v.data.step.uses),L={stopAt:ls(g.map($=>$.data.step),a),...b?{state:b}:{},...N?{input:p}:{}};w({stepId:a,status:"running"});try{await k(a,L),w(null)}catch($){const _=$;w({stepId:a,status:"error",error:_.message??String($),errorCode:_.code})}},[g,k]),Ct=u.useCallback((a,p)=>{if(n)return;const b=g.map(v=>v.id===a?{...v,data:{...v.data,step:p(v.data.step)}}:v);P(b),ee(b,A)},[g,A,P,ee,n]),ks=u.useCallback(a=>Ct(a,p=>Rn(p,!tt(p))),[Ct]),Es=u.useCallback(a=>Ct(a,p=>Fn(p,!We(p))),[Ct]),io=u.useCallback(async(a,p,b)=>{h==null||h();const v=g.find(G=>G.id===a);if(!v)return;const N=v.data.step,L=i.isTriggerStep(N.uses),$=L?{input:p}:{...N.with??{},...p},_=L?{input:p,with:p}:{input:p,with:$};w({stepId:a,status:"running"});try{const G=await j.invokeAction(N.uses.app,N.uses.action,$,{connectionId:i.connectionIdFor(N,R.current),project:f,...b?{state:b}:{},workflowId:s.id}),se=G.logs,pe=G.meta;w({stepId:a,status:"done",value:G.value,logs:se,...pe?{meta:pe}:{}}),zt(a,_,{status:"succeeded",output:G.value,...pe?{meta:pe}:{}})}catch(G){const se=G;w({stepId:a,status:"error",error:se.message??String(G),errorCode:se.code}),zt(a,_,{status:"failed",error:se.message??String(G)})}},[g,j,zt,f,h,s.id]),Ut=u.useMemo(()=>({onEdit:a=>{Ee("props"),Pe(a)},onEditJson:a=>{Ee("json"),Pe(a)},onRun:Cs,onDuplicate:Ss,onDelete:js,onTogglePause:ks,onToggleDisable:Es,runsFromNode:!!k,onAddFromPort:Ye,readOnly:n}),[Cs,Ss,js,ks,Es,k,Ye,n]);u.useEffect(()=>{const a=Ne.current;if(!a)return;const p=b=>{const v=b.target.closest(".react-flow__node");if(!v)return;const N=v.getAttribute("data-id");N&&(b.stopPropagation(),Ut.onEdit(N))};return a.addEventListener("dblclick",p,!0),()=>a.removeEventListener("dblclick",p,!0)},[Ut]);const rt=g.find(a=>a.id===de),kt=(rt==null?void 0:rt.data.step)??null,Ht=M?((Xs=g.find(a=>a.id===M.stepId))==null?void 0:Xs.data.step)??null:null,Jt=(M==null?void 0:M.status)==="collect"&&!!Ht,Ts=u.useMemo(()=>{const a=new Map;for(const p of g)a.set(p.id,i.fanOutState(p.id,A).count);return a},[g,A]),As=ii(g),Et=u.useMemo(()=>ri(As),[As]),ro=u.useMemo(()=>ni(A,Et.tones,Et.loopOf),[A,Et]),ao=u.useMemo(()=>({step:Ui,control:Hi}),[]),[Tt,Is]=u.useState({}),[At,Ps]=u.useState({}),[Rs,Fs]=u.useState({}),[It,Ds]=u.useState({}),[ze,Pt]=u.useState(null),[Ls,Ms]=u.useState([]),lo=de??ze??"";u.useEffect(()=>{const a=j.loadNodeSamples;if(typeof a!="function"||!s.id){Ms([]);return}let p=!1;return a(s.id).then(b=>{p||Ms(Array.isArray(b)?b:[])},()=>{}),()=>{p=!0}},[j,s.id,lo]);const Rt=u.useMemo(()=>i.indexNodeSamples(Ls),[Ls]),qt=u.useMemo(()=>i.splitNodeOutputs(Tt,Rt,It),[Tt,Rt,It]),Ue=u.useMemo(()=>i.splitPreviewOutputs(Tt,Rt,It),[Tt,Rt,It]),Ce=u.useMemo(()=>({actionDef:(a,p)=>{var b;return(b=B[a])==null?void 0:b.find(v=>v.key===p)},triggerDef:(a,p)=>{var b;return(b=ne[a])==null?void 0:b.find(v=>v.key===p)},testOutputs:qt.fresh,persistedOutputs:qt.persisted,loopSamples:Rs}),[B,ne,qt,Rs]),Qe=u.useMemo(()=>M?i.upstreamStateSources(M.stepId,g,A,Ce):void 0,[M,g,A,Ce]),co=u.useMemo(()=>(Qe==null?void 0:Qe.steps)??[],[Qe]),ve=u.useMemo(()=>{const a=i.upstreamStateSources(de,g,A,Ce,ze);return{...a,steps:i.excludeSelfStep(a.steps,de??ze)}},[de,ze,g,A,Ce]),ft=u.useMemo(()=>Si({anchorId:de??ze,nodes:g,edges:A,floating:i.isFloatingDraft(de,ze,g,A),initialState:s.initialState,variables:s.variables,shapes:Ce,previewOutputs:{...Ue.persisted,...Ue.fresh}}),[de,ze,g,A,s.initialState,s.variables,Ce,Ue]),_s=JSON.stringify([...ve.steps.map(a=>a.id),...ve.extraSampleIds??[]]);u.useEffect(()=>{const a=JSON.parse(_s);if(!de&&!ze||a.length===0){Is({}),Ps({}),Fs({}),Ds({});return}let p=!1;return Promise.all(a.map(async b=>{try{const v=await j.listStepTests(s.id,b),N=v.length?v[v.length-1]:null;return N?{id:b,output:N.lastRunOutput,runAt:N.lastRunAt,meta:N.lastRunMeta,loopSample:i.foreachTestSample(N)}:null}catch{return null}})).then(b=>{if(p)return;const v={},N={},L={},$={};for(const _ of b)_!=null&&_.meta&&(N[_.id]=_.meta),_!=null&&_.loopSample&&(L[_.id]=_.loopSample),!(!_||_.output===void 0||_.output===null)&&(v[_.id]=_.output,$[_.id]=_.runAt);Is(v),Ds($),Ps(N),Fs(L)}),()=>{p=!0}},[j,s.id,de,ze,_s]);const Gt=u.useMemo(()=>i.declaredSamples(g,Ce),[g,Ce]),Ft=u.useMemo(()=>({persisted:Ue.persisted,samples:Gt.samples,event:Gt.event}),[Ue.persisted,Gt]),Os=u.useMemo(()=>i.upstreamSampleValues(ve.steps,Ue.fresh,At,ve.loop,Ft),[ve.steps,ve.loop,Ue.fresh,At,Ft]),$s=u.useMemo(()=>i.upstreamSampleValueSources(ve.steps,Ue.fresh,At,ve.loop,Ft),[ve.steps,ve.loop,Ue.fresh,At,Ft]),Ws=i.useExpressionOptions(),Bs=u.useMemo(()=>i.nodeConfigSources(g),[g]),Vs=u.useMemo(()=>i.nodeConfigValues(g,C.subs),[g,C.subs]),Kt=u.useMemo(()=>i.nodeMetaValues(g,C.subs,y,O),[g,C.subs,y,O]),zs=u.useMemo(()=>[...new Set(Object.values(O).flatMap(a=>a.connection?[a.connection]:[]))].sort().join(","),[O]),[Us,uo]=u.useState(()=>new Map);u.useEffect(()=>{if(!zs)return;let a=!0;return j.listConnections().then(p=>{a&&uo(new Map(p.map(b=>[b.id,b])))}).catch(()=>{}),()=>{a=!1}},[j,zs]);const Yt=u.useMemo(()=>i.connectionExpressionSources(O,Us,y),[O,Us,y]),Xt=u.useMemo(()=>({...l??{},connections:Yt.sources,steps:ve.steps,hasTrigger:ve.hasTrigger,eventOutputs:ve.eventOutputs,eventOutputsFrom:ve.eventOutputsFrom,loop:ve.loop,stateShape:{fields:ft.fields,...ft.written?{written:ft.written}:{}},nodeConfigs:Bs,nodeConfig:Vs,nodeMeta:Kt,valueSources:$s,sampleValues:{...Ws.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...Yt.sampleValues,...i.nodeMetaSampleValues(Kt),...Os,...ft.sampleValues}}),[l,Ws.sampleValues,ve,ft,Os,$s,Bs,Vs,Kt,Yt]),ht=u.useRef(null);Be||de?ht.current===null&&(ht.current=q.mark()):ht.current=null;const Hs=()=>{oe(!1),$e(null),Ve(null),Pt(null)},Js=()=>{const a=ht.current;if(ht.current=null,n||a===null)return;const p=q.rollbackTo(a);p&&Gs(p)},qs=a=>{if(n)return;const p=q[a]();p&&Gs(p)},Gs=a=>{var v;const p=Ko(s,a);P(p.nodes.map(N=>({...N,selected:N.id===z}))),X(p.edges.map(N=>({...N,selected:N.id===ce}))),H(a.canvas),E(a.connections),p.nodes.some(N=>N.id===z)||U(null),p.edges.some(N=>N.id===ce)||ke(null);const b=p.nodes.some(N=>N.id===de);b||Pe(null),oe(!1),Pt(null),$e(null),Fe(null),ge(null),Ve(null),Ge(null),Me(null),Xe(null),Q.current=void 0,Je(N=>N+1),o(st(i.flowToWorkflow({...s,nodes:a.nodes,connections:a.connections},p.nodes,p.edges),a.canvas)),!b&&!M&&((v=Ne.current)==null||v.focus({preventScroll:!0}))},Ks=u.useRef(qs);Ks.current=qs,u.useEffect(()=>{const a=Ne.current;if(!a)return;let p=a.contains(document.activeElement);const b=N=>{N.type==="focusin"&&N.target===document.body||(p=a.contains(N.target))},v=N=>{if(n||N.defaultPrevented||Qt(N.target)||!a.contains(N.target)&&!(p&&N.target===document.body))return;const L=N.key.toLowerCase();!(N.ctrlKey||N.metaKey)||N.altKey||L!=="z"&&!(L==="y"&&!N.shiftKey)||(N.preventDefault(),Ks.current(L==="y"||N.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",b),document.addEventListener("focusin",b),document.addEventListener("keydown",v),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("focusin",b),document.removeEventListener("keydown",v)}},[n]);const Dt=u.useCallback((a,p)=>{var _;if(Qt(a.target))return;const b=(_=Ne.current)==null?void 0:_.getBoundingClientRect();if(!b)return;a.preventDefault();const v=un(g,A),N=v.nodeIds,L=Fo(N,p),$=p!==void 0&&!N.includes(p);$&&P(g.map(G=>G.selected!==(G.id===p)?{...G,selected:G.id===p}:G)),Ge({x:a.clientX-b.left,y:a.clientY-b.top,flow:De({x:a.clientX,y:a.clientY}),nodeIds:L,edgeIds:$?[]:v.edgeIds})},[g,A,P,De]),po=u.useCallback(a=>{var p;Ge(null),a&&((p=Ne.current)==null||p.focus({preventScroll:!0}))},[]),fo=a=>{const p=xe;if(!(!p||n))if(a==="duplicate")Vt(p.nodeIds);else if(a==="delete")Fe({nodeIds:p.nodeIds,edgeIds:p.edgeIds});else if(a==="replace-trigger"){const b=g.find(v=>v.id===p.nodeIds[0]);if(!b)return;$e(null),Ve({position:b.position,tab:"triggers",replaces:b.id}),oe(!0)}else $e(null),Ve({position:p.flow,...a==="add-trigger"?{tab:"triggers"}:{}}),oe(!0)},ho=e.jsx(xs.Provider,{value:Ut,children:e.jsx(hs.Provider,{value:Z,children:e.jsx(ms.Provider,{value:Ts,children:e.jsx(ws.Provider,{value:Et,children:e.jsx(Fi,{apps:y,registration:C,children:e.jsx(i.WorkflowProjectProvider,{project:f,workflowId:s.id,children:e.jsx(i.ExpressionOptionsProvider,{value:Xt,children:e.jsxs("section",{ref:Ne,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:r,position:"relative"},onFocusCapture:a=>{Q.current=Qt(a.target)?{}:void 0},onBlurCapture:()=>{Q.current=void 0},onKeyDown:a=>{if(a.defaultPrevented||a.key!=="Backspace"&&a.key!=="Delete"||n||de||Be||Re)return;const p=a.target;if(p.isContentEditable||p.tagName==="INPUT"||p.tagName==="TEXTAREA"||p.tagName==="SELECT"||p.closest("dialog, .w6w-modal")!==null)return;const b=un(g,A);!b.nodeIds.length&&!b.edgeIds.length||(a.preventDefault(),!b.nodeIds.length&&b.edgeIds.length===1?Xn(b.edgeIds[0]):Fe(b))},children:[e.jsxs(le.ReactFlow,{nodes:vt,edges:ro,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:le.ConnectionLineType.SmoothStep,onNodesChange:Y,onEdgesChange:D,onConnect:ae,onConnectStart:(a,p)=>{te.current=p},onConnectEnd:je,onPaneClick:()=>Me(null),onPaneContextMenu:a=>Dt(a),onNodeContextMenu:(a,p)=>Dt(a,p.id),onEdgeContextMenu:a=>Dt(a),onSelectionContextMenu:a=>Dt(a),onMoveStart:()=>Ge(null),isValidConnection:St,onNodeDragStop:(a,p,b)=>{const v=no(b),N=v!==J;if(N&&H(v),!S&&!N){q.record(Mt(s,g,A,R.current,v));return}ee(g,A,v)},onMoveEnd:(a,p)=>{if(!a||n)return;const b=i.flowToWorkflow(s,g,A),v=i.withViewport(b,p);v!==b&&o(v,{viewportOnly:!0})},onSelectionChange:({nodes:a,edges:p})=>{var b,v,N,L;U(((b=a[0])==null?void 0:b.id)??null),ke(((v=p[0])==null?void 0:v.id)??null),T.current!==(((N=a[0])==null?void 0:N.id)??null)&&(T.current=((L=a[0])==null?void 0:L.id)??null,Me(null))},nodeTypes:ao,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...K?{defaultViewport:K}:{fitView:!0,fitViewOptions:{maxZoom:1}},deleteKeyCode:null,colorMode:dt,proOptions:{hideAttribution:!0},children:[e.jsx(le.Background,{gap:16}),e.jsx(le.Controls,{showInteractive:!1,children:!n&&e.jsx(le.ControlButton,{onClick:Kn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:e.jsx(we.Icon,{name:"layout"})})}),e.jsx(le.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&e.jsxs(le.Panel,{position:"top-left",className:"w6w-flow-tools",children:[e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>oe(!0),children:"+ Node"}),e.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Qn}),e.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${_e?" active":""}`,"aria-pressed":_e,"data-testid":"draw-section",onClick:()=>{lt(!_e),qe(null)}})]}),!n&&_e&&e.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:a=>{if(a.button!==0)return;a.currentTarget.setPointerCapture(a.pointerId);const{clientX:p,clientY:b}=a;qe({sx:p,sy:b,ex:p,ey:b})},onPointerMove:a=>{const{clientX:p,clientY:b}=a;qe(v=>v&&{...v,ex:p,ey:b})},onPointerUp:()=>{const a=Se;if(qe(null),lt(!1),!a)return;const p=De({x:a.sx,y:a.sy}),b=Math.abs(a.ex-a.sx)>6||Math.abs(a.ey-a.sy)>6;eo(p,b?De({x:a.ex,y:a.ey}):null)},children:Se&&(()=>{var v;const a=(v=Ne.current)==null?void 0:v.getBoundingClientRect(),p=(a==null?void 0:a.left)??0,b=(a==null?void 0:a.top)??0;return e.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(Se.sx,Se.ex)-p,top:Math.min(Se.sy,Se.ey)-b,width:Math.abs(Se.ex-Se.sx),height:Math.abs(Se.ey-Se.sy)}})})()}),!n&&it&&i.edgeLane(it)!=="each"&&((Zs=g.find(a=>a.id===it.source))==null?void 0:Zs.data.step.uses.app)!==i.ROUTER_APP&&e.jsx(le.Panel,{position:"top-right",children:e.jsxs("div",{className:"w6w-edge-lane",children:[e.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(a=>e.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${i.edgeLane(it)===a?" active":""}`,"aria-pressed":i.edgeLane(it)===a,title:Ri,onClick:()=>Yn(a),children:a==="success"?"Success":"Error"},a)),(Nt==null?void 0:Nt.edgeId)===it.id&&e.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:Nt.message})]})}),ot&&e.jsx(le.NodeToolbar,{nodeId:ot.nodeId,position:le.Position.Bottom,isVisible:!0,children:e.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:i.loopRefusalMessage(ot.reason)})}),e.jsx(i.CanvasLayer,{canvas:J,readOnly:n,savePosition:S,onChange:Ze,onSectionDrop:to,onRequestDelete:(a,p)=>!n&&ge({kind:a,id:p})})]}),Ie&&e.jsx(i.ConfirmModal,{title:Ie.kind==="note"?"Delete note":"Delete section",message:Ie.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{so(Ie.kind,Ie.id),ge(null)},onClose:()=>ge(null)}),Be&&e.jsx(i.StepBuilderModal,{initialTab:ye==null?void 0:ye.tab,onClose:()=>{Js(),Hs()},onDone:Hs,onAdd:a=>{const p=Zn(a);return p&&Pt(p),p},onDraftChange:(a,p)=>Ns(a,{id:a,...p}),stepIds:g.map(a=>a.id),onOpenStep:a=>{oe(!1),$e(null),Ve(null),Pt(null),Ee("props"),Pe(a)},workflowId:s.id,upstreamSteps:i.stepBuilderUpstreamSteps(be,g,A),loop:i.stepBuilderLoop(be,g,A,Ce)}),kt&&de&&e.jsx(qi,{workflowId:s.id,step:kt,restoreVersion:fe,upstreamSteps:Xt.steps??[],loop:Xt.loop,readOnly:n,fanOutCount:Ts.get(de)??0,stateOutputFields:(sn=i.resolveOutputShape((Qs=Ce.actionDef)==null?void 0:Qs.call(Ce,kt.uses.app,kt.uses.action),(en=Ce.testOutputs)==null?void 0:en[de],(tn=Ce.persistedOutputs)==null?void 0:tn[de]))==null?void 0:sn.fields.map(a=>a.key),initialView:Oe,stepProblems:rt==null?void 0:rt.data.stepProblems,otherStepIds:g.filter(a=>a.id!==de).map(a=>a.id),onChange:a=>Ns(de,a),onClose:()=>Pe(null),onCancel:()=>{Js(),Pe(null)},onTestRun:h}),M&&e.jsxs(i.Modal,{title:`${Jt?"Run node":"Test run"}: ${M.stepId}`,onClose:()=>w(null),children:[Jt&&Ht&&e.jsx($i,{workflowId:s.id,step:Ht,upstreamSteps:co,loop:Qe==null?void 0:Qe.loop,continues:k?{stopAt:ls(g.map(a=>a.data.step),M.stepId)}:void 0,onCancel:()=>w(null),onRun:(a,p)=>k?oo(M.stepId,a,p):io(M.stepId,a,p)},M.stepId),!Jt&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w6w-modal-body",children:[M.status==="running"&&e.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),M.status==="error"&&e.jsxs("div",{className:"w6w-result w6w-error",children:[M.errorCode&&e.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:e.jsx("code",{children:M.errorCode})}),M.error||"The node failed with no error message."]}),M.status==="done"&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),e.jsx(i.ResultViewer,{value:M.value,maxHeight:360}),M.meta&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),e.jsx(i.ResultViewer,{value:M.meta,maxHeight:360})]})]}),M.logs&&M.logs.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),e.jsx(we.Copyable,{value:M.logs.join(`
|
|
1
|
+
"use client";"use strict";var go=Object.defineProperty;var xo=(t,s,o)=>s in t?go(t,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[s]=o;var at=(t,s,o)=>xo(t,typeof s!="symbol"?s+"":s,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),le=require("@xyflow/react"),u=require("react"),i=require("./connection-app-meta-DID4zDg-.cjs"),we=require("./CodeBlock-85y9qvE3.cjs"),Ae=require("@w6w/expr");function bo({x:t,y:s,items:o,onAction:n,onClose:r}){const c=u.useRef(null),[l,f]=u.useState({left:t,top:s});u.useLayoutEffect(()=>{const x=c.current,h=x==null?void 0:x.offsetParent;if(!x||!h)return;const m=x.offsetWidth,k=x.offsetHeight;f({left:t+m>h.clientWidth?Math.max(0,t-m):t,top:s+k>h.clientHeight?Math.max(0,s-k):s})},[t,s]),u.useEffect(()=>{var x,h;(h=(x=c.current)==null?void 0:x.querySelector("[role=menuitem]"))==null||h.focus({preventScroll:!0})},[]),u.useEffect(()=>{const x=k=>{var j;(j=c.current)!=null&&j.contains(k.target)||r(!1)},h=k=>{var j;(j=c.current)!=null&&j.contains(k.target)||r(!1)},m=()=>r(!1);return document.addEventListener("pointerdown",x,!0),document.addEventListener("scroll",h,!0),document.addEventListener("wheel",h,{capture:!0,passive:!0}),window.addEventListener("blur",m),window.addEventListener("resize",m),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("scroll",h,!0),document.removeEventListener("wheel",h,!0),window.removeEventListener("blur",m),window.removeEventListener("resize",m)}},[r]);const d=x=>{x.disabled||(r(!1),n(x.action))};return e.jsx("div",{ref:c,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:l.left,top:l.top},onContextMenu:x=>x.preventDefault(),onKeyDown:x=>{var j;x.stopPropagation();const h=[...((j=c.current)==null?void 0:j.querySelectorAll("[role=menuitem]"))??[]],m=h.indexOf(document.activeElement),k=y=>{var C;return(C=h[(y+h.length)%h.length])==null?void 0:C.focus()};if(x.key==="ArrowDown")k(m+1);else if(x.key==="ArrowUp")k(m<0?-1:m-1);else if(x.key==="Home")k(0);else if(x.key==="End")k(-1);else if(x.key==="Escape"||x.key==="Tab")r(!0);else if(x.key==="Enter"||x.key===" ")m>=0&&d(o[m]);else return;x.preventDefault()},children:o.map(x=>e.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":x.disabled||void 0,className:`w6w-note-menu-item${x.danger?" danger":""}${x.separated?" separated":""}`,"data-action":x.action,onClick:()=>d(x),children:x.label},x.action))})}const nn=i.customCssTemplate();function jo({value:t,onChange:s,readOnly:o,stepId:n}){const r=u.useMemo(()=>So(t),[t]),c=u.useMemo(()=>{var S;return r?((S=i.parseFormDefinition(r))==null?void 0:S.problems)??[]:[]},[r]),[l,f]=u.useState(null),[d,x]=u.useState(null),[h,m]=u.useState(null),[k,j]=u.useState(0);if(!r)return e.jsxs("div",{className:"w6w-result w6w-error",children:["This form is not a form definition (it may be set by an expression). Edit it in the Parameters code view, or reset it.",!o&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-sm",onClick:()=>s(i.defaultFormDefinition()),children:"Reset to a starter form"})})]});const y=r.fields,C=S=>s({...r,...S}),M=S=>C({fields:S}),w=S=>new Set(y.filter(g=>g.id!==S&&g.name).map(g=>g.name)),F=(S,g)=>{const R=y.find(ne=>ne.id===S);if(!R)return;let Y=No({...R,...g});if(g.label!==void 0&&i.isInputField(R.type)){const ne=w(S),Z=i.uniqueName(i.slugName(R.label??""),ne);(!R.name||R.name===Z)&&(Y={...Y,name:i.uniqueName(i.slugName(g.label||R.type),ne)})}const B=R.name&&Y.name!==R.name?R.name:null;M(y.map(ne=>{var Z;return ne.id===S?Y:B&&((Z=ne.showIf)==null?void 0:Z.field)===B&&Y.name?{...ne,showIf:{...ne.showIf,field:Y.name}}:ne}))},W=(S,g=y.length)=>{const R=on(y),Y=i.newField(S,R,w()),B=[...y];B.splice(g,0,Y),M(B),f(R)},O=(S,g)=>{const R=y.findIndex(Z=>Z.id===S);if(R<0)return;const Y=g>R?g-1:g;if(Y===R||Y<0||Y>=y.length)return;const B=[...y],[ne]=B.splice(R,1);B.splice(Y,0,ne),M(B)},I=S=>{const g=on(y),R={...structuredClone(S),id:g};R.name&&(R.name=i.uniqueName(R.name,w()));const Y=y.findIndex(ne=>ne.id===S.id)+1,B=[...y];B.splice(Y,0,R),M(B),f(g)},P=()=>{x(null),m(null)},E=(S,g)=>{if(S.preventDefault(),o)return P();d&&O(d,g),P()},V=(S,g)=>{if(o||!d)return;S.preventDefault(),S.dataTransfer.dropEffect="move";const R=S.currentTarget.getBoundingClientRect();m(S.clientY>R.top+R.height/2?g+1:g)},K=y.filter(S=>i.isInputField(S.type)&&S.name);return e.jsxs("div",{className:"w6w-form-builder","data-testid":"form-builder",children:[c.length>0&&e.jsx("ul",{className:"w6w-form-problems","data-testid":"form-problems",children:c.map(S=>e.jsxs("li",{children:[e.jsx(we.Icon,{name:"warning",size:12})," ",S.fieldId?e.jsx("button",{type:"button",className:"w6w-form-problem-link",onClick:()=>f(S.fieldId??null),children:S.message}):S.message]},`${S.fieldId??"form"}:${S.message}`))}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Form title"}),e.jsx("input",{type:"text",value:r.title??"",disabled:o,"aria-label":"Form title",onChange:S=>C({title:S.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Description"}),e.jsx("textarea",{rows:2,value:r.description??"",disabled:o,"aria-label":"Form description",onChange:S=>C({description:S.target.value||void 0})})]}),e.jsxs("div",{className:"w6w-form-section-label",children:["Fields ",e.jsx("span",{className:"w6w-muted",children:"· drag to reorder"})]}),e.jsxs("div",{className:"w6w-form-fields","data-testid":"form-fields",onDragLeave:S=>{S.currentTarget.contains(S.relatedTarget)||m(null)},children:[y.length===0&&e.jsx("div",{className:`w6w-form-empty${h===0?" is-drop-target":""}`,onDragOver:S=>{o||!d||(S.preventDefault(),m(0))},onDrop:S=>E(S,0),children:"No fields yet. Add one below."}),y.map((S,g)=>{const R=l===S.id,Y=["w6w-form-field",R?"is-open":"",d===S.id?"is-dragging":"",h===g?"is-drop-before":"",h===g+1&&g===y.length-1?"is-drop-after":"",S.type==="pageBreak"?"is-page-break":""].filter(Boolean).join(" ");return e.jsxs("div",{className:Y,"data-field-id":S.id,onDragOver:B=>V(B,g),onDrop:B=>E(B,h??g),children:[e.jsxs("div",{className:"w6w-form-field-head",children:[e.jsx("button",{type:"button",className:"w6w-icon-btn w6w-router-grip",draggable:!o,disabled:o,"aria-label":`Reorder ${Dt(S)}`,title:"Drag to reorder · arrow keys to move",onDragStart:B=>{B.dataTransfer.effectAllowed="move",B.dataTransfer.setData("text/plain",S.id);const ne=B.currentTarget.closest(".w6w-form-field");ne&&B.dataTransfer.setDragImage(ne,16,16),x(S.id)},onDragEnd:P,onKeyDown:B=>{B.key!=="ArrowUp"&&B.key!=="ArrowDown"||(B.preventDefault(),O(S.id,B.key==="ArrowUp"?g-1:g+2))},children:e.jsx(we.Icon,{name:"grip",size:14})}),e.jsxs("button",{type:"button",className:"w6w-form-field-summary","aria-expanded":R,onClick:()=>f(R?null:S.id),children:[e.jsx("span",{className:"w6w-form-field-type",children:i.FIELD_TYPE_LABELS[S.type]}),e.jsxs("span",{className:"w6w-form-field-label",children:[Dt(S),S.required?e.jsx("span",{className:"w6w-form-req",children:" *"}):null]}),S.name&&i.isInputField(S.type)&&e.jsx("code",{className:"w6w-form-field-name",children:S.name}),S.showIf&&e.jsx("span",{className:"w6w-form-field-badge",title:"Shown only when a condition holds",children:"if"}),e.jsx(we.Icon,{name:"chevron-down",size:12})]}),!o&&e.jsx(i.IconButton,{label:`Duplicate ${Dt(S)}`,icon:"copy",onClick:()=>I(S)}),e.jsx(i.DeleteButton,{label:`Remove ${Dt(S)}`,disabled:o,onClick:()=>M(y.filter(B=>B.id!==S.id))})]}),R&&e.jsx(To,{field:S,earlier:K.filter(B=>y.indexOf(B)<g&&B.id!==S.id),readOnly:o,stepId:n,onPatch:B=>F(S.id,B)})]},S.id)})]}),!o&&e.jsx(i.Combobox,{className:"w6w-form-add",mode:"combobox","aria-label":"Add a field",placeholder:"+ Add a field…",options:yo,value:"",onChange:S=>{W(S),j(g=>g+1)}},k),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Submit button label"}),e.jsx("input",{type:"text",value:r.submitLabel??"",placeholder:"Submit",disabled:o,"aria-label":"Submit button label",onChange:S=>C({submitLabel:S.target.value||void 0})})]}),e.jsx(Io,{form:r,save:C,readOnly:o}),e.jsx(Ro,{form:r,save:C,readOnly:o})]})}const vo=[{title:"Text",types:["text","textarea","email","number","phone","url","password"]},{title:"Choice",types:["select","radio","checkboxes","checkbox","rating"]},{title:"Date & time",types:["date","time","datetime"]},{title:"Other",types:["file","hidden"]},{title:"Layout",types:["heading","paragraph","pageBreak"]}],yo=vo.flatMap(t=>t.types.map(s=>({value:s,label:i.FIELD_TYPE_LABELS[s],group:t.title,keywords:`${t.title} ${s}`})));function So(t){if(t==null||t==="")return i.defaultFormDefinition();let s=t;if(typeof s=="string")try{s=JSON.parse(s)}catch{return null}if(!s||typeof s!="object"||Array.isArray(s))return null;const o=s;if(!Array.isArray(o.fields))return null;if(o.fields.every(r=>r&&typeof r.id=="string"&&r.id))return o;const n=new Set;return{...o,fields:o.fields.filter(r=>r&&typeof r=="object").map((r,c)=>{let l=typeof r.id=="string"&&r.id&&!n.has(r.id)?r.id:`f_${c+1}`;for(;n.has(l);)l=`${l}_`;return n.add(l),{...r,id:l}})}}function on(t){const s=new Set(t.map(o=>o.id));for(;;){const o=`f_${Math.random().toString(36).slice(2,8)}`;if(!s.has(o))return o}}function No(t){const s={};for(const[o,n]of Object.entries(t))n===void 0||n===""||(s[o]=n);return s}function Dt(t){return t.type==="pageBreak"?t.label?`New page: ${t.label}`:"New page":t.type==="paragraph"?Co(t.help??"")||"Paragraph":t.label||t.name||i.FIELD_TYPE_LABELS[t.type]}function Co(t,s=60){return t.length>s?`${t.slice(0,s-1)}…`:t}const ko=t=>{if(t.trim()==="")return;const s=Number(t);return Number.isFinite(s)?s:void 0},Eo={equals:"is",notEquals:"is not",contains:"contains",notContains:"does not contain",isEmpty:"is empty",isNotEmpty:"is not empty",greaterThan:"is greater than",lessThan:"is less than"};function To({field:t,earlier:s,readOnly:o,stepId:n,onPatch:r}){const c=t.type,l=i.isInputField(c),f=i.CHOICE_FIELD_TYPES.has(c),d=i.TEXT_FIELD_TYPES.has(c),x=c==="checkboxes"||c==="select"&&t.multiple,h=(j,y,C={})=>e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:j}),C.area?e.jsx("textarea",{rows:3,value:String(t[y]??""),placeholder:C.placeholder,disabled:o,"aria-label":j,onChange:M=>r({[y]:M.target.value||void 0})}):e.jsx("input",{type:"text",value:String(t[y]??""),placeholder:C.placeholder,disabled:o,"aria-label":j,onChange:M=>r({[y]:M.target.value||void 0})}),C.hint&&e.jsx("span",{className:"w6w-hint",children:C.hint})]},String(y)),m=(j,y,C)=>e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:j}),e.jsx("input",{type:"number",value:t[y]===void 0?"":String(t[y]),placeholder:C,disabled:o,"aria-label":j,onChange:M=>r({[y]:ko(M.target.value)})})]},String(y)),k=(j,y)=>e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!t[y],disabled:o,onChange:C=>r({[y]:C.target.checked||void 0})}),j]},String(y));return c==="pageBreak"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Next page title","label",{placeholder:"Optional"}),e.jsx("span",{className:"w6w-hint",children:"Everything below this starts a new page with Back / Next."})]}):c==="heading"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Heading","label"),h("Text under the heading","help",{area:!0}),e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]}):c==="paragraph"?e.jsxs("div",{className:"w6w-form-field-body",children:[h("Text","help",{area:!0}),e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]}):e.jsxs("div",{className:"w6w-form-field-body",children:[e.jsxs("div",{className:"w6w-field-row",children:[h(c==="hidden"?"Description":"Label","label"),h("Answer key","name",{hint:t.name?e.jsxs(e.Fragment,{children:["Use as ",e.jsx("code",{children:`{{ nodes.${n??"<trigger>"}.output.data.${t.name} }}`})]}):"Letters, digits and _."})]}),c==="hidden"?h("Value","defaultValue",{hint:"Recorded with every response. A ?name=value in the form URL overrides it."}):e.jsxs(e.Fragment,{children:[h("Help text","help",{placeholder:"Shown under the label"}),(d||c==="number"||c==="select")&&h("Placeholder","placeholder"),e.jsxs("div",{className:"w6w-form-checks",children:[l&&k("Required","required"),c==="select"&&k("Allow several choices","multiple"),f&&k('Offer an "Other" answer',"allowOther"),c==="file"&&k("Allow several files","multiple"),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:t.width==="half",disabled:o,onChange:j=>r({width:j.target.checked?"half":void 0})}),"Half width"]})]})]}),f&&e.jsxs("div",{className:"w6w-form-options","data-testid":"form-choices",children:[e.jsx(rn,{label:"Choices",modes:[["fixed","Fixed list"],["data","From data"]],value:t.optionsFrom?"data":"fixed",readOnly:o,onChange:j=>r({optionsFrom:j==="data"?{items:""}:void 0})}),t.optionsFrom?e.jsx(an,{source:t.optionsFrom,withValue:!0,readOnly:o,onChange:j=>r({optionsFrom:j})}):e.jsx(Ao,{options:t.options??[],readOnly:o,onChange:j=>r({options:j})})]}),c==="text"&&e.jsxs("div",{className:"w6w-form-options","data-testid":"form-suggestions",children:[e.jsx(rn,{label:"Suggestions as they type",modes:[["none","None"],["fixed","Fixed list"],["data","From data"]],value:t.suggestionsFrom?"data":t.suggestions?"fixed":"none",readOnly:o,onChange:j=>r({suggestions:j==="fixed"?[]:void 0,suggestionsFrom:j==="data"?{items:""}:void 0})}),t.suggestionsFrom?e.jsx(an,{source:t.suggestionsFrom,readOnly:o,onChange:j=>r({suggestionsFrom:j})}):t.suggestions?e.jsx("textarea",{rows:3,value:t.suggestions.join(`
|
|
2
|
+
`),placeholder:"One per line",disabled:o,"aria-label":"Suggestions",onChange:j=>r({suggestions:j.target.value.split(`
|
|
3
|
+
`)})}):null,(t.suggestions||t.suggestionsFrom)&&e.jsx("span",{className:"w6w-hint",children:"Offered as they type; any other answer is accepted too."})]}),d&&e.jsxs("div",{className:"w6w-field-row",children:[m("Min length","minLength"),m("Max length","maxLength")]}),d&&c!=="email"&&c!=="url"&&e.jsxs("div",{className:"w6w-field-row",children:[h("Pattern (regular expression)","pattern",{placeholder:"e.g. [A-Z]{2}\\d{4}"}),t.pattern&&h("Message when it does not match","patternMessage")]}),c==="textarea"&&m("Rows","rows","4"),c==="number"&&e.jsxs("div",{className:"w6w-field-row",children:[m("Min","min"),m("Max","max"),m("Step","step","any")]}),c==="rating"&&m("Stars","max","5"),(c==="date"||c==="time"||c==="datetime")&&e.jsxs("div",{className:"w6w-field-row",children:[h("Earliest","minDate",{placeholder:ln(c)}),h("Latest","maxDate",{placeholder:ln(c)})]}),x&&e.jsxs("div",{className:"w6w-field-row",children:[m("Pick at least","minSelected"),m("Pick at most","maxSelected")]}),c==="file"&&e.jsxs("div",{className:"w6w-field-row",children:[h("Accepted types","accept",{placeholder:".pdf,image/*"}),m("Max size per file (MB)","maxFileSizeMb","10"),t.multiple&&m("Max files","maxFiles")]}),c!=="hidden"&&c!=="file"&&c!=="checkboxes"&&c!=="checkbox"&&!x&&h("Default answer","defaultValue",{hint:e.jsxs(e.Fragment,{children:["A ?name=value in the form URL overrides it. Can read a pre-form step, e.g."," ",e.jsx("code",{children:"{{ nodes.lookup.output.email }}"}),"."]})}),c==="checkbox"&&e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:t.defaultValue===!0,disabled:o,onChange:j=>r({defaultValue:j.target.checked||void 0})}),"Checked by default"]}),c!=="hidden"&&e.jsx(Zt,{field:t,earlier:s,readOnly:o,onPatch:r})]})}function rn({label:t,modes:s,value:o,readOnly:n,onChange:r}){return e.jsxs("div",{className:"w6w-form-mode",children:[e.jsx("span",{className:"w6w-small w6w-muted",children:t}),e.jsx("div",{role:"group","aria-label":t,className:"w6w-form-mode-buttons",children:s.map(([c,l])=>e.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${o===c?" active":""}`,"aria-pressed":o===c,disabled:n,onClick:()=>o!==c&&r(c),children:l},c))})]})}function an({source:t,withValue:s,readOnly:o,onChange:n}){const r=(c,l,f)=>e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:l}),e.jsx("input",{type:"text",value:t[c]??"",placeholder:f,disabled:o,"aria-label":l,onChange:d=>n({...t,[c]:d.target.value||void 0})})]});return e.jsxs("div",{className:"w6w-stack","data-testid":"form-data-source",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"List"}),e.jsx(i.ExpressionInput,{value:typeof t.items=="string"?t.items:void 0,readOnly:o,placeholder:"{{ nodes.get_products.output.items }}","aria-label":"List",onChange:c=>n({...t,items:c})}),e.jsx("span",{className:"w6w-hint",children:"Wire a step into this form trigger: it runs each time the page opens, and this list is read from its output."})]}),e.jsxs("div",{className:"w6w-field-row",children:[r("label","Label key","label · name · title"),s&&r("value","Value key","value · id")]})]})}function ln(t){return t==="time"?"09:00":t==="datetime"?"2026-01-31T09:00":"2026-01-31"}function Zt({field:t,earlier:s,readOnly:o,onPatch:n}){var f;const r=t.showIf;if(!r)return s.length===0||o?null:e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-form-cond-add",onClick:()=>n({showIf:{field:s[s.length-1].name??"",op:"equals",value:""}}),children:"+ Show only when…"});const c=r.op!=="isEmpty"&&r.op!=="isNotEmpty",l=s.find(d=>d.name===r.field);return e.jsxs("div",{className:"w6w-form-cond","data-testid":"form-condition",children:[e.jsx("span",{className:"w6w-small",children:"Show only when"}),e.jsxs("select",{value:r.field,disabled:o,"aria-label":"Depends on",onChange:d=>n({showIf:{...r,field:d.target.value}}),children:[!l&&e.jsx("option",{value:r.field,children:r.field||"—"}),s.map(d=>e.jsx("option",{value:d.name,children:d.label||d.name},d.id))]}),e.jsx("select",{value:r.op,disabled:o,"aria-label":"Comparison",onChange:d=>n({showIf:{...r,op:d.target.value}}),children:i.CONDITION_OPS.map(d=>e.jsx("option",{value:d,children:Eo[d]},d))}),c&&((f=l==null?void 0:l.options)!=null&&f.length?e.jsxs("select",{value:r.value??"",disabled:o,"aria-label":"Value",onChange:d=>n({showIf:{...r,value:d.target.value}}),children:[e.jsx("option",{value:"",children:"—"}),l.options.map(d=>e.jsx("option",{value:d.value||d.label,children:d.label},d.value??d.label))]}):e.jsx("input",{type:"text",value:r.value??"",disabled:o,"aria-label":"Value",placeholder:(l==null?void 0:l.type)==="checkbox"?"true":"value",onChange:d=>n({showIf:{...r,value:d.target.value}})})),e.jsx(i.DeleteButton,{label:"Remove condition",disabled:o,onClick:()=>n({showIf:void 0})})]})}function Ao({options:t,readOnly:s,onChange:o}){const[n,r]=u.useState(null),[c,l]=u.useState(null),f=(x,h)=>{if(h<0||h>=t.length||x===h)return;const m=[...t],[k]=m.splice(x,1);m.splice(h,0,k),o(m)},d=(x,h)=>o(t.map((m,k)=>{if(k!==x)return m;const{value:j,...y}={...m,...h};return j?{...y,value:j}:y}));return e.jsxs("div",{className:"w6w-form-options","data-testid":"form-options",children:[e.jsx("span",{className:"w6w-small w6w-muted",children:"Options · the value is recorded (defaults to the label)"}),t.map((x,h)=>e.jsxs("div",{className:`w6w-form-option${n===h?" is-dragging":""}${c===h?" is-drop-before":""}`,onDragOver:m=>{s||n===null||n===h||(m.preventDefault(),l(h))},onDrop:m=>{m.preventDefault(),n!==null&&f(n,h),r(null),l(null)},children:[e.jsx("button",{type:"button",className:"w6w-icon-btn w6w-router-grip",draggable:!s,disabled:s,"aria-label":`Reorder option ${x.label}`,title:"Drag to reorder · arrow keys to move",onDragStart:m=>{m.dataTransfer.effectAllowed="move",m.dataTransfer.setData("text/plain",String(h)),r(h)},onDragEnd:()=>{r(null),l(null)},onKeyDown:m=>{m.key!=="ArrowUp"&&m.key!=="ArrowDown"||(m.preventDefault(),f(h,h+(m.key==="ArrowUp"?-1:1)))},children:e.jsx(we.Icon,{name:"grip",size:12})}),e.jsx("input",{type:"text",value:x.label,disabled:s,"aria-label":`Option ${h+1} label`,onChange:m=>d(h,{label:m.target.value})}),e.jsx("input",{type:"text",value:x.value??"",placeholder:x.label,disabled:s,"aria-label":`Option ${h+1} value`,onChange:m=>d(h,{value:m.target.value})}),e.jsx(i.DeleteButton,{label:`Remove option ${x.label}`,disabled:s,onClick:()=>o(t.filter((m,k)=>k!==h))})]},h)),!s&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-router-add",onClick:()=>{let x=t.length+1;for(;t.some(h=>h.label===`Option ${x}`);)x++;o([...t,{label:`Option ${x}`}])},children:"+ Add option"})]})}function Io({form:t,save:s,readOnly:o}){const n=t.completion??{},r=l=>{const f={...n,...l};for(const d of Object.keys(f))(f[d]===void 0||f[d]==="")&&delete f[d];s({completion:f})},c=n.type==="redirect";return e.jsxs("details",{className:"w6w-section w6w-form-group","data-testid":"form-completion",children:[e.jsxs("summary",{className:"w6w-section-summary",children:[e.jsx("span",{className:"w6w-section-title",children:"After submitting"}),e.jsx("span",{className:"w6w-section-subtitle",children:c?`Redirect to ${n.redirectUrl||"…"}`:n.title||"Thank-you message"})]}),e.jsxs("div",{className:"w6w-form-group-body",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Show"}),e.jsxs("select",{value:c?"redirect":"message",disabled:o,"aria-label":"Completion",onChange:l=>r({type:l.target.value}),children:[e.jsx("option",{value:"message",children:"A thank-you message"}),e.jsx("option",{value:"redirect",children:"Redirect to a URL"})]})]}),c?e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Redirect URL"}),e.jsx("input",{type:"text",value:n.redirectUrl??"",placeholder:"https://example.com/thanks?email={{email}}",disabled:o,"aria-label":"Redirect URL",onChange:l=>r({redirectUrl:l.target.value})}),e.jsxs("span",{className:"w6w-hint",children:[e.jsx("code",{children:"{{name}}"})," inserts that answer (URL-encoded)."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{type:"text",value:n.title??"",placeholder:"Thank you!",disabled:o,"aria-label":"Completion title",onChange:l=>r({title:l.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Message"}),e.jsx("textarea",{rows:2,value:n.message??"",disabled:o,"aria-label":"Completion message",onChange:l=>r({message:l.target.value})}),e.jsxs("span",{className:"w6w-hint",children:[e.jsx("code",{children:"{{name}}"})," inserts that answer. With “Wait for the workflow to finish”, a Respond to Webhook step can replace this screen."]})]}),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.allowAnother,disabled:o,onChange:l=>r({allowAnother:l.target.checked||void 0})}),"Offer “Submit another response”"]})]})]})]})}function Ro({form:t,save:s,readOnly:o}){const n=t.settings??{},r=l=>{const f={...n,...l};for(const d of Object.keys(f))(f[d]===void 0||f[d]==="")&&delete f[d];s({settings:f})},c=(l,f,d)=>e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:n[f]??d,disabled:o,onChange:x=>r({[f]:x.target.checked})}),l]});return e.jsxs("details",{className:"w6w-section w6w-form-group","data-testid":"form-settings",children:[e.jsxs("summary",{className:"w6w-section-summary",children:[e.jsx("span",{className:"w6w-section-title",children:"Page settings"}),e.jsxs("span",{className:"w6w-section-subtitle",children:[n.closed?"Closed":"Open"," · ",n.theme??"auto"," theme"]})]}),e.jsxs("div",{className:"w6w-form-group-body",children:[e.jsxs("div",{className:"w6w-form-checks",children:[c("Pre-fill from ?name=value in the URL","allowPrefill",!0),c("Show page progress","showProgress",!0),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.hideBranding,disabled:o,onChange:l=>r({hideBranding:l.target.checked||void 0})}),"Hide “Powered by w6w”"]})]}),e.jsxs("div",{className:"w6w-field-row",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Theme"}),e.jsxs("select",{value:n.theme??"auto",disabled:o,"aria-label":"Theme",onChange:l=>r({theme:l.target.value}),children:[e.jsx("option",{value:"auto",children:"Follow the visitor's system"}),e.jsx("option",{value:"light",children:"Light"}),e.jsx("option",{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Accent colour"}),e.jsxs("span",{className:"w6w-form-color",children:[e.jsx("input",{type:"color",value:/^#[0-9a-f]{6}$/i.test(n.accentColor??"")?n.accentColor:"#3355e6",disabled:o,"aria-label":"Accent colour picker",onChange:l=>r({accentColor:l.target.value})}),e.jsx("input",{type:"text",value:n.accentColor??"",placeholder:"#3355e6",disabled:o,"aria-label":"Accent colour",onChange:l=>r({accentColor:l.target.value})})]})]})]}),e.jsxs("label",{className:"w6w-form-check",children:[e.jsx("input",{type:"checkbox",checked:!!n.closed,disabled:o,onChange:l=>r({closed:l.target.checked||void 0})}),"Closed — stop accepting responses"]}),n.closed&&e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Closed message"}),e.jsx("input",{type:"text",value:n.closedMessage??"",placeholder:"This form is no longer accepting responses.",disabled:o,"aria-label":"Closed message",onChange:l=>r({closedMessage:l.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Custom CSS"}),e.jsx("textarea",{rows:8,className:"w6w-form-css",value:n.customCss??nn,spellCheck:!1,wrap:"off",disabled:o,"aria-label":"Custom CSS",onChange:l=>r({customCss:l.target.value===nn?void 0:l.target.value})})]})]})]})}function Po(t,s,o,n){return t.find(r=>r.nodeId===s&&r.appId===o&&r.triggerKey===n)??null}function Fo(t){return(t??"").split(`
|
|
4
|
+
`).map(s=>s.trim().replace(/^(\d+[.)]|[-•*])\s+/,"")).filter(s=>s!=="")}function Lo({workflowId:t,nodeId:s,appId:o,triggerKey:n,appName:r,setup:c,connectionId:l,params:f,readOnly:d}){const x=i.useW6WApi(),[h,m]=u.useState(void 0),[k,j]=u.useState(null),y=u.useRef(null),C=JSON.stringify({connectionId:l,params:f});u.useEffect(()=>{const O=x.listSubscriptionsForWorkflow,I=x.createSubscription;if(!O){m(null);return}let P=!1;return m(void 0),j(null),y.current=null,(async()=>{const E=Po(await O.call(x,t),s,o,n);if(d||!I||E&&E.status!=="pending")return E;const V=await I.call(x,o,n,{workflowId:t,connectionId:l,params:f,nodeId:s});return y.current=C,V})().then(E=>!P&&m(E)).catch(E=>{P||(m(null),j(E instanceof Error?E.message:String(E)))}),()=>{P=!0}},[x,t,s,o,n,d]);const M=(h==null?void 0:h.status)==="pending"?h.id:null;u.useEffect(()=>{const O=x.createSubscription;if(!M||d||!O||y.current===null||y.current===C)return;const I=setTimeout(()=>{y.current=C,O.call(x,o,n,{workflowId:t,connectionId:l,params:f,nodeId:s}).then(P=>{j(null),m(P)}).catch(P=>j(P instanceof Error?P.message:String(P)))},600);return()=>clearTimeout(I)},[x,M,d,C,o,n,t,s]);const w=h==null?void 0:h.webhookUrl,F=Fo(c.instructions),W=(h==null?void 0:h.lastFireAt)??null;return e.jsxs("div",{className:"w6w-stack w6w-url-panel","data-testid":"manual-webhook-panel",children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:[e.jsx("strong",{children:"Webhook URL"})," — ",r," sends its events here."]}),k&&e.jsx("div",{className:"w6w-result w6w-error",children:k}),w?e.jsx("div",{className:"w6w-listen-url",children:e.jsx(we.Copyable,{value:w,readOnly:!0,children:e.jsx("input",{type:"text",readOnly:!0,value:w,"aria-label":"Webhook URL"})})}):h===void 0?e.jsx("p",{className:"w6w-muted w6w-small",children:"Getting the webhook URL…"}):!k&&e.jsx("p",{className:"w6w-muted w6w-small",children:"The webhook URL appears once the workflow is saved."}),e.jsxs("div",{className:"w6w-manual-webhook-note",role:"note","data-testid":"manual-webhook-note",children:[e.jsxs("strong",{children:["Add this URL in ",r," before the trigger works."]})," W6W can't add it for you, and nothing reaches this trigger until it is there."]}),F.length>0&&e.jsxs("div",{className:"w6w-manual-webhook-steps",children:[e.jsxs("span",{className:"w6w-small",children:["How to add it in ",r]}),e.jsx("ol",{className:"w6w-small","data-testid":"manual-webhook-steps",children:F.map((O,I)=>e.jsx("li",{children:O},I))})]}),h&&e.jsx("p",{className:"w6w-muted w6w-small","data-testid":"manual-webhook-status",children:W?`Last event received ${new Date(W).toLocaleString()}.`:h.status==="registered"?`Listening. No event from ${r} yet.`:"Starts the workflow once it is published."})]})}function Do(t,s){return s===void 0?[...t]:t.includes(s)?[...t]:[s]}function Mo(t,s,o={}){const n=[],r=t.length;if(r>0){const c=r>1?` ${r} nodes`:"";n.push({action:"duplicate",label:`Duplicate${c}`,disabled:s}),r===1&&o.replaceableTrigger&&n.push({action:"replace-trigger",label:"Replace trigger",disabled:s}),n.push({action:"delete",label:`Delete${c}`,disabled:s,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:s,separated:r>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:s}),n}const kn=200,En=200,Tn=10240;function ns(t){const s={};for(const[o,n]of Object.entries(t))s[o]=Math.round(n);return s}const _o=t=>!!t&&Number.isFinite(t.x)&&Number.isFinite(t.y),Oo=t=>!!t&&Number.isFinite(t.width)&&Number.isFinite(t.height);function cn(t,s,o){return t&&t.map(n=>{const r=s==null?void 0:s[n.id],c=_o(r==null?void 0:r.position)?r.position:n.position,l=Oo(r==null?void 0:r.size)?r.size:n.size;return{...n,position:ns(c),size:ns(l)}})}function An(t,s,o){if(!s)return t;const n={...t};return t.notes&&(n.notes=cn(t.notes,o)),t.sections&&(n.sections=cn(t.sections,o)),n}function us(t,s){return t.sections?{...t,sections:t.sections.map(o=>({...o,nodes:o.nodes.filter(n=>n!==s)}))}:t}function os(t,s,o){return t.sections?{...t,sections:t.sections.map(n=>({...n,nodes:n.nodes.map(r=>r===s?o:r)}))}:t}function is(t,s,o){if(!t.sections)return t;const n=new Set(o);return{...t,sections:t.sections.map(r=>{const c=r.nodes.filter(l=>!n.has(l));return r.id===s?{...r,nodes:[...new Set([...c,...o])]}:{...r,nodes:c}})}}function In(t,s){return(t.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function $o(t,s){const o=new TextEncoder;if(o.encode(t).length<=s)return t;let n="",r=0;for(const c of t){const l=o.encode(c).length;if(r+l>s)break;n+=c,r+=l}return n}function rs(t){const s={...t};return t.notes&&(s.notes=t.notes.slice(0,kn).map(o=>({...o,content:$o(o.content,Tn)}))),t.sections&&(s.sections=t.sections.slice(0,En)),s}function Wo(t,s,o){const n={};for(const l of[...t.notes??[],...t.sections??[]])n[l.id]={position:l.position,size:l.size};const r=(l,f)=>l==null?void 0:l.map(d=>{const x=f==null?void 0:f.find(h=>h.id===d.id);return x?{...d,position:x.position,size:x.size}:d}),c=o?t:{...t,...t.notes?{notes:r(t.notes,s==null?void 0:s.notes)}:{},...t.sections?{sections:r(t.sections,s==null?void 0:s.sections)}:{}};return An(c,o,n)}const dn=220;function Bo(t){return t.length<=dn?{text:t,clipped:!1,length:t.length}:{text:t.slice(0,dn).trimEnd(),clipped:!0,length:t.length}}function Vo({params:t,values:s,testStartState:o,view:n="props",literalKeys:r}){const{sampleValues:c,nodeConfig:l,nodeMeta:f}=i.useExpressionOptions(),d=u.useMemo(()=>i.buildResolveScope(c,o,l,f),[c,o,l,f]),x=i.flattenParams(t),h=j=>{var y;return s[j]!==void 0?s[j]:(y=x.find(C=>C.key===j))==null?void 0:y.default},m=x.filter(j=>j.type!=="section"&&i.isParamVisible(j,h)).map(j=>Ae.effectiveParam(j,h));if(i.hasParamCustomization(s)){const j=i.previewCustomization(s.$merge,d,r),y=j!==null&&typeof j=="object"&&!Array.isArray(j),C=un(m,s,d,r);for(const[w,F]of Object.entries(s))w!=="$merge"&&(C[w]=r!=null&&r.includes(w)?F:i.previewCustomization(F,d));const M=y?{...C,...j}:C;return e.jsxs("div",{className:"w6w-resolved-params",children:[e.jsx("p",{className:"w6w-muted w6w-small",children:y?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(j)}). Test the step to validate it.`}),n==="code"?e.jsx(i.JsonEditor,{value:JSON.stringify(M,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):e.jsx("div",{className:"w6w-resolved-table",children:Object.entries(M).map(([w,F])=>{var W;return e.jsx(as,{label:((W=x.find(O=>O.key===w))==null?void 0:W.label)??w,segments:[{status:"resolved",value:F}]},w)})})]})}if(n==="code"){const j=un(m,s,d,r);return e.jsx("div",{className:"w6w-resolved-params",children:e.jsx(i.JsonEditor,{value:JSON.stringify(j,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const k=m.filter(j=>!i.deepEqual(h(j.key),j.default));return m.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):k.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):e.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:k.map(j=>j.type==="vars"?e.jsx(zo,{param:j,value:s[j.key],scope:d},j.key):e.jsx(as,{label:j.label??j.key,segments:r!=null&&r.includes(j.key)?[{status:"resolved",value:h(j.key)}]:i.resolveParamValue(h(j.key),d)},j.key))})}function un(t,s,o,n){const r={};for(const c of t)if(n!=null&&n.includes(c.key))r[c.key]=s[c.key]!==void 0?s[c.key]:c.default;else if(c.type==="vars"){const l=s[c.key]??c.default??[],f=i.dataVarRows(l);r[c.key]=f?i.resolveVarsJson(f,o):i.resolveParamJson(l,o)}else r[c.key]=i.resolveParamJson(s[c.key]!==void 0?s[c.key]:c.default,o);return r}function as({label:t,segments:s}){return e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t}),e.jsx("div",{className:"w6w-resolved-value",children:e.jsx(Rn,{segments:s})})]})}function zo({param:t,value:s,scope:o}){const n=s??t.default??[],r=i.dataVarRows(n);return r===null?e.jsx(as,{label:t.label??t.key,segments:i.resolveParamValue(n,o)}):e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t.label??t.key}),r.length===0?e.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):e.jsx("div",{className:"w6w-stack",children:r.map((c,l)=>e.jsxs("div",{className:"w6w-resolved-value",children:[e.jsx("code",{children:c.key||"(no key)"})," → ",e.jsx(Rn,{segments:i.resolveParamValue(c.value,o)})]},l))})]})}function Rn({segments:t}){return e.jsx(e.Fragment,{children:t.map((s,o)=>e.jsx(Uo,{segment:s},o))})}function Uo({segment:t}){switch(t.status){case"resolved":return t.ref?e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx(pn,{value:t.value})]}):e.jsx(pn,{value:t.value});case"unresolved":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"var",refName:t.ref}),e.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return e.jsxs(e.Fragment,{children:[e.jsx(wt,{kind:"expr"}),e.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return e.jsx(wt,{kind:"secret",refName:t.ref})}}function pn({value:t}){const[s,o]=u.useState(!1),n=Jo(t),r=Bo(n);return r.clipped?e.jsxs(e.Fragment,{children:[s?e.jsx(we.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:e.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):e.jsxs("span",{children:[r.text,"…"]}),e.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>o(c=>!c),children:s?"Show less":`Show all (${r.length.toLocaleString()} characters)`})]}):e.jsx("span",{children:n})}const Ho={var:"◆",secret:"🔒",expr:"ƒ"};function wt({kind:t,refName:s}){const o=t==="expr"?"expr":i.varLabel(s??"");return e.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${t}`,children:[e.jsx("span",{className:"w6w-expr-chip-sigil",children:Ho[t]}),e.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function Jo(t){if(t===null)return"null";if(t===void 0)return"(not set)";if(t==="")return'""';if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t)}catch{return String(t)}}function Pn(t){return t.language==="python"||t.language==="typescript"?t.language:"javascript"}function qo({enabled:t,values:s,onChange:o}){const[n,r]=u.useState(null),c=u.useRef(!1),l=typeof s.code=="string"?s.code:"";return u.useEffect(()=>{if(!t||c.current)return;c.current=!0;const f=i.convertCodeBindingsToReads(l,Pn(s));f.converted!==0&&(r({original:l,converted:f.converted}),o({...s,code:f.code}))},[t,l,s,o]),n?{converted:n.converted,undo:()=>{o({...s,code:n.original}),r(null)}}:null}function Go({values:t,conversion:s,readOnly:o}){const n=typeof t.code=="string"?t.code:"",r=s,c=i.findCodeBindings(n,Pn(t)).length;return!r&&c===0?null:e.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[r&&e.jsxs(e.Fragment,{children:["Converted ",r.converted," reference",r.converted===1?"":"s"," to code reads",!o&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:r.undo,children:"Undo"})]}),c>0&&" · "]}),c>0&&e.jsxs(e.Fragment,{children:[c," ",e.jsx("code",{children:"{{ }}"})," left in the code stay",c===1?"s":""," literal text — read ",c===1?"it":"them"," from"," ",e.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function fn(t,s){return{nodeIds:t.filter(o=>o.selected).map(o=>o.id),edgeIds:s.filter(o=>o.selected).map(o=>o.id)}}function Ko(t,s,o,n){const r=new Set(t.nodeIds),c=new Set(t.edgeIds),l=s.filter(m=>r.has(m.id)),f=[...l.filter(m=>i.isForeachStep(m.data.step)),...l.filter(m=>!i.isForeachStep(m.data.step))];let d=s,x=o,h=n;for(const m of f)x=i.bridgeDeletedBodyStep(m.id,d,x),d=d.filter(k=>k.id!==m.id),h=us(h,m.id);return{nodes:d,edges:x.filter(m=>!c.has(m.id)),canvas:h}}function Yo(t,s,o){var f;const n=new Set(t.nodeIds),r=new Set(t.edgeIds),c=o.filter(d=>r.has(d.id)&&!n.has(d.source)&&!n.has(d.target)),l=[];if(n.size===1)l.push(i.deleteStepMessage(t.nodeIds[0],s,o));else if(n.size>1){l.push(`Delete nodes ${[...n].map(x=>`"${x}"`).join(", ")}? Their connections are removed too.`);const d=new Set;for(const x of n)if(i.isForeachStep((f=s.find(h=>h.id===x))==null?void 0:f.data.step))for(const h of i.loopBody(x,s,o))n.has(h)||d.add(h);d.size&&l.push(`Loop body steps ${[...d].map(x=>`"${x}"`).join(", ")} stay as standalone steps.`)}return c.length&&l.push(`Delete ${c.length===1?"connection":"connections"} ${c.map(d=>`"${d.source} → ${d.target}"`).join(", ")}?`),l.join(" ")}function Mt(t,s,o,n,r){const c=i.flowToWorkflow({...t,connections:n},s,o);return{nodes:c.nodes.map(({with:l,...f})=>l&&Object.keys(l).length?{...f,with:l}:f),edges:c.edges??[],connections:c.connections??{},canvas:r,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function Xo(t,s){const o=i.workflowToFlow({...t,...s});return{...o,nodes:o.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class Zo{constructor(s,o=100){at(this,"past",[]);at(this,"future",[]);at(this,"present");at(this,"group");at(this,"limit");this.limit=o,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,o){const n=JSON.stringify(s);n!==this.present&&((!o||o!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=o,this.future=[])}mark(){return this.present}rollbackTo(s){if(this.present===s)return;const o=this.past.lastIndexOf(s);return o>=0&&(this.past.length=o),this.present=s,this.future=[],this.group=void 0,JSON.parse(s)}undo(){const s=this.past.pop();if(s!==void 0)return this.future.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}redo(){const s=this.future.pop();if(s!==void 0)return this.past.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}}function Qt(t){var o;const s=t;return!!(s!=null&&s.isContentEditable||(o=s==null?void 0:s.closest)!=null&&o.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Qo=64,gt=24,et=32;function _t(t){var s,o;return{width:((s=t.measured)==null?void 0:s.width)??t.width??200,height:((o=t.measured)==null?void 0:o.height)??t.height??64}}function ei(t,s){return t.x<s.x+s.width&&t.x+t.width>s.x&&t.y<s.y+s.height&&t.y+t.height>s.y}function ti(t){const s=(r,c)=>{const l=new Map;for(const x of t){const h=x.position[r];l.set(h,Math.max(l.get(h)??0,_t(x)[c]))}const f=new Map;let d=Number.NEGATIVE_INFINITY;for(const[x,h]of[...l].sort(([m],[k])=>m-k)){const m=Math.max(x,d);f.set(x,m),d=m+h+Qo}return f},o=s("x","width"),n=s("y","height");return t.map(r=>({...r,position:{x:o.get(r.position.x)??r.position.x,y:n.get(r.position.y)??r.position.y}}))}function si(t,s,o){var f;const n=ti(i.relayoutNodes(t,s));if(!((f=o.sections)!=null&&f.length))return{nodes:n,canvas:o};const r=new Map(n.map(d=>[d.id,d])),c=(o.notes??[]).map(d=>({...d.position,...d.size}));for(const d of o.sections)d.nodes.some(x=>r.has(x))||c.push({...d.position,...d.size,y:d.position.y-et,height:d.size.height+et});const l=o.sections.map(d=>{const x=new Set(d.nodes),h=n.filter(F=>x.has(F.id));if(!h.length)return d;const m=Math.min(...h.map(F=>F.position.x))-gt,k=Math.min(...h.map(F=>F.position.y))-gt,j=Math.max(...h.map(F=>F.position.x+_t(F).width)),y=Math.max(...h.map(F=>F.position.y+_t(F).height)),C={x:m,y:k,width:j+gt-m,height:y+gt-k},M=[...c,...[...r.values()].filter(F=>!x.has(F.id)).map(F=>({...F.position,..._t(F)}))].sort((F,W)=>F.y-W.y);for(const F of M){const W={...C,y:C.y-et,height:C.height+et};ei(W,F)&&(C.y=F.y+F.height+gt+et)}const w=C.y-k;for(const F of h)r.set(F.id,{...F,position:{x:F.position.x,y:F.position.y+w}});return c.push({...C,y:C.y-et,height:C.height+et}),{...d,position:{x:C.x,y:C.y},size:{width:C.width,height:C.height}}});return{nodes:n.map(d=>r.get(d.id)??d),canvas:{...o,sections:l}}}const es=6;function ni(t){let s=2166136261;for(let o=0;o<t.length;o++)s^=t.charCodeAt(o),s=Math.imul(s,16777619);return s>>>0}function oi(t){const s=new Map;let o=new Set;for(const n of[...new Set(t)].sort()){o.size===es&&(o=new Set);let r=ni(n)%es;for(;o.has(r);)r=(r+1)%es;o.add(r),s.set(n,r+1)}return s}function ps(t){return`var(--w6w-loop-${t})`}function Fn(t,s){const o=[],n=new Set([t]);for(let r=s.get(t);r&&!n.has(r);r=s.get(r))n.add(r),o.unshift(r);return o}function ii(t,s,o){return s.size===0?t:t.map(n=>{var l;if(((l=n.data)==null?void 0:l.when)!=="each")return n;const r=n.sourceHandle===i.EACH_SOURCE_HANDLE?n.source:o.get(n.source),c=r?s.get(r):void 0;return c===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":ps(c)}}})}function ri(t,s){const o=s.get(t);return o===void 0?void 0:{"--w6w-loop-color":ps(o)}}function ai(t){const s=[];for(const o of t){const n=i.isForeachStep(o.data.step);(n||o.data.loopOf)&&s.push([o.id,n?1:0,o.data.loopOf])}return JSON.stringify(s)}function li(t){const s=JSON.parse(t);return{tones:oi(s.filter(o=>o[1]===1).map(o=>o[0])),loopOf:new Map(s.map(o=>[o[0],o[2]]))}}const hn="Paused — test runs stop before this node",mn="Disabled — skipped in every run";function tt(t){var s;return((s=t.ui)==null?void 0:s.paused)===!0}function We(t){return t.disabled===!0}function Ln(t,s){const{ui:o,...n}=t,{paused:r,...c}=o??{},l=s?{...c,paused:!0}:c;return Object.keys(l).length>0?{...n,ui:l}:n}function Dn(t,s){const{disabled:o,...n}=t;return s?{...n,disabled:!0}:n}function ls(t,s){return t.filter(o=>o.id!==s&&tt(o)).map(o=>o.id)}const ci=["nodes","steps"];function wn(t,s){for(const o of ci){const n=`${o}.${s}.output`;if(!t.startsWith(n))continue;const r=t.slice(n.length);if(r===""||r[0]==="."||r[0]==="[")return`foreach.item${r}`}return null}function Ot(t,s,o){if(typeof t=="string"){if(!t.includes("{{"))return t;const n=i.parseRootAnchoredTemplate(t);let r=!1;const c=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const f=wn(l.ref,s);return f===null?l:(r=!0,o.includes(l.ref)||o.push(l.ref),{...l,ref:f})});return r?Ae.serializeTemplate(c):t}if(i.isDollarPath(t)){const n=t.$;if(typeof n!="string")return t;const r=wn(n,s);return r===null?t:(o.includes(n)||o.push(n),{$:r})}if(Array.isArray(t)){let n=!1;const r=t.map(c=>{const l=Ot(c,s,o);return l!==c&&(n=!0),l});return n?r:t}if(typeof t=="object"&&t!==null){let n=!1;const r={};for(const[c,l]of Object.entries(t)){const f=Ot(l,s,o);f!==l&&(n=!0),r[c]=f}return n?r:t}return t}function di(t){if(typeof t=="string"){if(!t.includes("{{"))return!1;const s=i.parseRootAnchoredTemplate(t);return s.length===1&&s[0].kind==="var"}return i.isDollarPath(t)&&typeof t.$=="string"}function Mn(t){return Array.isArray(t)&&t.length===1&&di(t[0])}function ui(t){var s;try{const o=i.normalizeInput(t);if(!Array.isArray(o.nodes))return{};const n={},r=(l,f)=>{const d=Object.hasOwn(n,l)?n[l]:[];d.push(f),n[l]=d},c=new Map(o.nodes.map(l=>[l.id,l]));for(const[l,f]of Object.entries(i.definitionLoops(o))){const d=c.get(l);if(d&&Mn((s=d.with)==null?void 0:s.items)&&r(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){r(l,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const x of f.body){const h=c.get(x);if(!(h!=null&&h.with))continue;const m=[];Ot(h.with,l,m),m.length>0&&r(x,{code:"foreach_body_refs_output",foreachId:l,refs:m,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function pi(t){const s=new Set,o=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const r of n)o(r)};return o(t),s}function fi(t){var s,o;try{const n=i.normalizeInput(t);if(!Array.isArray(n.nodes))return[];const r=n.nodes.filter(I=>typeof I=="object"&&I!==null&&typeof I.id=="string"),c=i.effectiveEdges({...n,nodes:r}).filter(I=>typeof(I==null?void 0:I.from)=="string"&&typeof(I==null?void 0:I.to)=="string"),l=[];for(const I of r)try{const P=Ae.staticWritePaths(Ae.effectiveStateConfig((s=I.uses)==null?void 0:s.app,(o=I.uses)==null?void 0:o.action,I.state));P.length>0&&l.push({id:I.id,paths:P})}catch{}if(l.length<2)return[];const f=new Map;for(const I of r)for(const P of i.controlOwnedIds(I))f.has(P)||f.set(P,I.id);const d=I=>{const P=[I];let E=I;for(;f.has(E)&&(E=f.get(E),!P.includes(E));)P.push(E);return P},x=I=>{const P=d(I);return P[P.length-1]},h=new Map;for(const I of c){const P=h.get(I.from)??[];P.push(I.to),h.set(I.from,P)}const m=new Map,k=I=>{const P=m.get(I);if(P)return P;const E=new Set,V=[...h.get(I)??[]];for(;V.length>0;){const K=V.pop();if(!E.has(K)){E.add(K);for(const S of h.get(K)??[])V.push(S)}}return m.set(I,E),E},j=(I,P)=>I===P||k(I).has(P),y=r.filter(I=>{var P;return((P=I.uses)==null?void 0:P.app)===i.CONTROL_APP&&I.uses.action==="parallel"}).map(I=>{var E;const P=(E=I.with)==null?void 0:E.branches;return Array.isArray(P)?P.map(pi):[]}),C=(I,P)=>{for(const E of d(P)){const V=I.findIndex(K=>K.has(E));if(V>=0)return V}return-1},M=[];for(const I of r){if(I.fanOut!=="parallel")continue;const P=new Map;for(const E of c){if(E.from!==I.id||i.isEachLink(E))continue;const V=E.when??"success",K=P.get(V)??[];K.push(E.to),P.set(V,K)}for(const E of P.values())E.length>=2&&M.push(E)}const w=(I,P)=>{for(const K of y){const S=C(K,I),g=C(K,P);if(S>=0&&g>=0&&S!==g)return!0}const E=x(I),V=x(P);return E===V||k(E).has(V)||k(V).has(E)?!1:M.some(K=>K.some((S,g)=>K.some((R,Y)=>g!==Y&&j(S,E)&&j(R,V))))},F=new Set,W=[];for(let I=0;I<l.length;I++)for(let P=I+1;P<l.length;P++){const E=l[I],V=l[P];if(!(E.id===V.id||!w(E.id,V.id)))for(const K of E.paths)for(const S of V.paths){if(!Ae.statePathsOverlap(K,S))continue;const g={code:"state_parallel_write",nodes:[E.id,V.id].sort(),path:[...K.length<=S.length?K:S]},R=JSON.stringify([g.nodes,g.path]);F.has(R)||(F.add(R),W.push(g))}}const O=(I,P)=>I<P?-1:I>P?1:0;return W.sort((I,P)=>O(I.code,P.code)||O(I.nodes.join(","),P.nodes.join(","))||O(I.path.join("."),P.path.join(".")))}catch{return[]}}function hi(t){try{const s={};for(const o of fi(t))for(const n of o.nodes){const r=Object.hasOwn(s,n)?s[n]:[];r.push({code:o.code,path:[...o.path],with:o.nodes.filter(c=>c!==n)}),s[n]=r}return s}catch{return{}}}function _n(t,s){var o;if(s.code==="foreach_wrapped_items"){const n=(o=t.with)==null?void 0:o.items;return!t.with||!Mn(n)?t:{...t,with:{...t.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!t.with)return t;const n=Ot(t.with,s.foreachId,[]);return n===t.with?t:{...t,with:n}}return t}function gn(t,s,o){return t&&t.nodeId===s&&t.handleType===((o==null?void 0:o.type)??"source")?i.laneForSourceHandle(t.handleId):i.laneForSourceHandle(o==null?void 0:o.id)}function mi(t,s,o,n,r){var x;const c=(x=n.find(h=>h.id===t))==null?void 0:x.data.step,l=i.loopMembership(n,r)[t]!==void 0,f=o==="success"&&l?"each":o;if(f==="each"&&!l&&!i.isForeachStep(c))return null;const d=o==="success"&&i.isForeachStep(c)?i.FOREACH_DONE_ROUTE:void 0;return i.loopRefusal(t,s,f,n,r,d)}function $t(t,s){var o;return(o=t.nodes??t.steps)==null?void 0:o[s]}function cs(t,s){const o=$t(t,s);return(o==null?void 0:o.status)==="skipped"&&o.skipReason==="not_on_path"}const wi=new Set(["succeeded","failed","canceled"]);function gi(t,s,o=[]){var c,l;if(!t||[...o,s].some(f=>cs(t,f)))return"no-run";const n=$t(t,s);if(n)return n.status;const r=new Set;for(const f of Object.values(t.nodes??t.steps??{}))if(Array.isArray(f==null?void 0:f.iterations))for(const d of f.iterations){const x=(l=(c=d==null?void 0:d.nodes)==null?void 0:c[s])==null?void 0:l.status;x&&r.add(x)}for(const f of["failed","running","succeeded","skipped"])if(r.has(f))return f;return"pending"}const xn={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function On(t,s){const o=s!==void 0&&wi.has(s);switch(t){case"no-run":return xn;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 xn}}function xi(t,s,o,n,r){var l;if(!t||cs(t,s)||r!==void 0&&cs(t,r))return;const c=bi(t,s,o,n);return c==="taken"&&r!==void 0&&((l=$t(t,r))==null?void 0:l.status)==="skipped"?"skipped":c}function bi(t,s,o,n){const r=$t(t,s);if(!r)return;if(o==="each")return r.status==="skipped"?"skipped":void 0;const c=o??"success",l=r.output,f=n===i.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!f&&r.status==="succeeded")return l&&typeof l=="object"&&"matched"in l?n==="false"!=(l.matched===!0)?"taken":"skipped":l&&typeof l=="object"&&"route"in l&&l.route===n?"taken":"skipped";if(r.status==="succeeded")return c==="success"?"taken":"skipped";if(r.status==="failed")return c==="error"?"taken":"skipped";if(r.status==="skipped")return"skipped"}const bn={fields:[],sampleValues:{}};function fs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ji(t,s){var x;const o=t.map(h=>h.id),n=new Set(o),r=new Map(o.map(h=>[h,0])),c=new Map(o.map(h=>[h,[]]));for(const h of s)!n.has(h.source)||!n.has(h.target)||((x=c.get(h.source))==null||x.push(h.target),r.set(h.target,(r.get(h.target)??0)+1));const l=[],f=o.filter(h=>r.get(h)===0);for(;f.length>0;){const h=f.shift();l.push(h);for(const m of c.get(h)??[]){const k=(r.get(m)??0)-1;r.set(m,k),k===0&&f.push(m)}}const d=new Set(l);for(const h of o)d.has(h)||l.push(h);return l}const vi=new Set(["string","number","boolean","object","array"]);function xt(t){if(!Array.isArray(t))return;const s={type:"object",fields:{}};let o=!1;for(const n of t){if(!fs(n)||typeof n.key!="string"||n.key==="")continue;const r=n.key.split(".");let c=s;for(const d of r.slice(0,-1)){const x=c.fields[d];(x==null?void 0:x.type)!=="object"&&(c.fields[d]={type:"object",fields:{}}),c=c.fields[d]}const l=typeof n.type=="string"&&vi.has(n.type)?n.type:"string";let f;if(l==="array"){const d=xt(n.items);f=d?{type:"array",items:d}:{type:"array"}}else l==="object"?f=xt(n.fields??n.properties)??{type:"object",fields:{}}:f={type:l};c.fields[r[r.length-1]]=f,o=!0}return o?s:void 0}function yi(t,s){var x,h,m,k,j,y,C;const o=t.data.step,n=((x=s.testOutputs)==null?void 0:x[o.id])??((h=s.persistedOutputs)==null?void 0:h[o.id]);if(n!=null)return n;const{app:r,action:c}=o.uses;if(r===i.TRIGGER_APP&&((m=i.internalNodeDef(r,c))==null?void 0:m.group)==="trigger"){const M=i.fieldsToParams(i.asFieldDefs((k=o.with)==null?void 0:k.fields)).map(w=>({key:w.key}));return i.shapeToSkeleton(xt(M))}const l=(j=i.internalNodeDef(r,c))==null?void 0:j.output;if(l&&l.length>0)return i.shapeToSkeleton(xt(l));const f=o.uses.trigger===!0?(y=s.triggerDef)==null?void 0:y.call(s,r,c):(C=s.actionDef)==null?void 0:C.call(s,r,c),d=xt(f==null?void 0:f.output);return d?i.shapeToSkeleton(d):f==null?void 0:f.sample}function Si(t,s){var f,d,x,h,m;const o=t.data.step,n=(f=s.previewOutputs)==null?void 0:f[o.id];if(n!=null)return n;const{app:r,action:c}=o.uses,l=o.uses.trigger===!0?(x=(d=s.shapes)==null?void 0:d.triggerDef)==null?void 0:x.call(d,r,c):(m=(h=s.shapes)==null?void 0:h.actionDef)==null?void 0:m.call(h,r,c);return l==null?void 0:l.sample}function Ni(t){switch(t){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function jn(t,s){const o=fs(t.initialState)?{...t.initialState}:{};for(const n of t.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?o[n.key]=n.default:s||(o[n.key]=Ni(n.type)));return o}function ts(t){return(i.inferOutputFields(t)??[]).map(s=>s.key)}function Ci(t){const{anchorId:s,nodes:o,edges:n}=t;if(!s)return bn;const r=t.shapes??{},c=t.floating?new Set(o.map(E=>E.id)):i.ancestorIds(s,n);c.delete(s);const l=new Map(o.map(E=>[E.id,E])),f=[],d=[],x=new Map;for(const E of ji(o,n)){if(!c.has(E))continue;const V=l.get(E);if(!V)continue;const{app:K,action:S}=V.data.step.uses,g=Ae.effectiveStateConfig(K,S,V.data.step.state);if(g.mode==="off")continue;const R=yi(V,r);if(R!==void 0){const{ops:B}=Ae.computeStateWrites(g,R);f.push(...B);for(const ne of ts(Ae.foldState({},B))){const Z=x.get(ne)??new Set;Z.add(E),x.set(ne,Z)}}const Y=Si(V,t);Y!==void 0&&d.push(...Ae.computeStateWrites(g,Y).ops)}const h=jn(t,!1),m=Ae.foldState(h,f),k=ts(m);if(k.length===0)return bn;const j=new Set(ts(h)),y=new Map,C=new Map;for(const E of n)c.has(E.source)&&(!c.has(E.target)&&E.target!==s||(y.set(E.target,[...y.get(E.target)??[],E.source]),C.set(E.source,[...C.get(E.source)??[],E.target])));const M=[...c].filter(E=>!(y.get(E)??[]).length),w=E=>{const V=new Set,K=M.filter(S=>!E.has(S));for(;K.length>0;){const S=K.pop();if(S===s)return!1;if(!V.has(S)){V.add(S);for(const g of C.get(S)??[])E.has(g)||K.push(g)}}return!0},F=Ae.foldState(jn(t,!0),d),W=d.length>0?Ae.foldState({},d):void 0,O=fs(W)&&Object.keys(W).length>0?W:void 0,I=[],P={};for(const E of k){const V=x.get(E)??new Set,K=j.has(E)||V.size>0&&w(V);I.push({key:E,path:!0,paths:K?"all":"some"});const S=i.valueAtPath(F,E);S!==void 0&&(P[`state.${E}`]=S)}return{fields:I,sampleValues:P,...O?{written:O}:{}}}const ki={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"}},vn="Never fired";function Ei(t){if(!t)return vn;const s=new Date(t);return Number.isNaN(s.getTime())?vn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function Ti(t,s){var r;if(!(t!=null&&t.status))return null;const o=ki[t.status];if(!o)return null;const n=t.status==="failed";return{label:o.label,tone:o.tone,error:n?((r=t.lastError)==null?void 0:r.message)??null:null,lastFire:Ei(t.lastFireAt),retryVisible:n&&s}}function Ai(t){const s=new Map;for(const o of t)o.nodeId&&s.set(o.nodeId,o);return s}function Ii(t){return(t??[]).filter(s=>{var o;return((o=s.uses)==null?void 0:o.trigger)===!0})}function Ri(t,s){const[o,n]=u.useState({}),r=u.useRef(new Set),c=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return u.useEffect(()=>{const l=JSON.parse(c).filter(f=>!r.current.has(f));if(l.length!==0){for(const f of l)r.current.add(f);Promise.all(l.map(async f=>{try{return[f,await t.getAppActions(f)]}catch{return r.current.delete(f),null}})).then(f=>{const d=f.filter(x=>x!==null);d.length!==0&&n(x=>({...x,...Object.fromEntries(d)}))})}},[t,c]),o}function Pi(t,s){const[o,n]=u.useState({}),r=u.useRef(new Set),c=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return u.useEffect(()=>{const l=t.getAppTriggers;if(typeof l!="function")return;const f=JSON.parse(c).filter(d=>!r.current.has(d));if(f.length!==0){for(const d of f)r.current.add(d);Promise.all(f.map(async d=>{try{return[d,await l.call(t,d)]}catch{return r.current.delete(d),null}})).then(d=>{const x=d.filter(h=>h!==null);x.length!==0&&n(h=>({...h,...Object.fromEntries(x)}))})}},[t,c]),o}function Fi(t){return(s,o)=>{var n,r;return(r=(n=t[s])==null?void 0:n.find(c=>c.key===o))==null?void 0:r.ports}}const Li="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 yn(t,s,o,n){const r=t.find(c=>c.id===s);return[o,n,r==null?void 0:r.source,r==null?void 0:r.target]}const hs=u.createContext(void 0),ms=u.createContext(new Map),ws=u.createContext({tones:new Map,loopOf:new Map});function Sn(t){return`Can’t draw that edge: this node allows at most ${t} outgoing edge${t===1?"":"s"} per lane.`}const gs=u.createContext(new Map),$n=u.createContext({byNode:new Map,subs:[]});function Di({apps:t,registration:s,children:o}){return e.jsx(gs.Provider,{value:t,children:e.jsx($n.Provider,{value:s,children:o})})}const xs=u.createContext(null);function Mi(t){return e.jsx(le.ReactFlowProvider,{children:e.jsx(_i,{...t})})}function Nn(t,s){let o=s.length+1;for(;s.includes(`${t}-${o}`);)o++;return`${t}-${o}`}function ss(t){var s,o;return{x:t.position.x,y:t.position.y,w:((s=t.measured)==null?void 0:s.width)??t.width??200,h:((o=t.measured)==null?void 0:o.height)??t.height??64}}function _i({onConnectionResourcesChange:t,value:s,onChange:o,readOnly:n,height:r=480,apps:c,exprOptions:l,project:f,runState:d,stepProblems:x,onTestRun:h,fitViewKey:m,onRunFromNode:k}){var Ys,Xs,Zs,Qs,en,tn,sn;const j=i.useW6WApi(),y=u.useMemo(()=>new Map((c??[]).map(a=>[a.id,a])),[c]),C=Ui(s),[M,w]=u.useState(null),F=u.useMemo(()=>i.centralizeConnections(s),[s.id]),W=u.useMemo(()=>i.workflowToFlow(F),[F]),[O,I]=u.useState(F.connections??{}),P=u.useRef(O),E=u.useCallback(a=>{P.current=a,I(a)},[]),V=u.useCallback(a=>{const p=i.centralizeConnections({nodes:[a],connections:P.current});return p.connections!==P.current&&E(p.connections),p.nodes[0]},[E]),K=u.useMemo(()=>i.storedViewport(s),[s.id]),S=((Ys=s.settings)==null?void 0:Ys.savePosition)!==!1,[g,R,Y]=le.useNodesState(W.nodes),B=Ri(j,g),ne=Pi(j,g),Z=u.useMemo(()=>Fi(B),[B]),[A,X,L]=le.useEdgesState(W.edges),[z,U]=u.useState(null),ie=u.useMemo(()=>s.canvas??{},[s.id]),[J,H]=u.useState(ie),[q]=u.useState(()=>new Zo(Mt(F,W.nodes,W.edges,O,ie))),Q=u.useRef(),[fe,Je]=u.useState(0),[_e,lt]=u.useState(!1),[Se,qe]=u.useState(null),[Ie,ge]=u.useState(null),[ce,ke]=u.useState(null),[Be,oe]=u.useState(!1),bt=u.useRef({});u.useEffect(()=>{Be||(bt.current={})},[Be]);const[de,Re]=u.useState(null),[Oe,Ee]=u.useState("props"),[xe,Ge]=u.useState(null),[ye,Ve]=u.useState(null),[Pe,Fe]=u.useState(null),ct=u.useRef(!1),Ne=u.useRef(null),[be,$e]=u.useState(null),{screenToFlowPosition:Le,fitView:De}=le.useReactFlow(),dt=i.useEffectiveTheme();u.useEffect(()=>{R(W.nodes),X(W.edges),U(null),ke(null),Fe(null),Re(null),Ge(null),H(ie),E(F.connections??{}),q.reset(Mt(F,W.nodes,W.edges,F.connections??{},ie)),Q.current=void 0},[W,ie,F,R,X,E,q]),u.useEffect(()=>{R(a=>{const p=new Map(i.stampLoopOf(a,A).map(b=>[b.id,b.data.loopOf]));return a.map(b=>{const v=gi(d,b.id,Fn(b.id,p));return b.data.stepStatus===v&&b.data.runStatus===(d==null?void 0:d.status)?b:{...b,data:{...b.data,stepStatus:v,runStatus:d==null?void 0:d.status}}})}),X(a=>a.map(p=>{var D;const b=i.edgeLane(p),v=xi(d,p.source,b,typeof((D=p.data)==null?void 0:D.route)=="string"?p.data.route:void 0,p.target),N=i.edgeVisuals(b,v);return p.className===N.className&&p.label===N.label?p:{...p,className:N.className,label:N.label}}))},[d,W,fe,R,X]),u.useEffect(()=>{R(a=>i.applyStepProblems(a,x))},[x,W,fe,R]);const st=u.useCallback((a,p)=>{var N,D;const{canvas:b,...v}=a;return!((N=p.notes)!=null&&N.length)&&!((D=p.sections)!=null&&D.length)?v:{...v,canvas:Wo(p,s.canvas,S)}},[s.canvas,S]),ee=u.useCallback((a,p,b)=>{q.record(Mt(s,a,p,P.current,b??J),Be?bt.current:Q.current),o(st(i.flowToWorkflow({...s,connections:P.current},a,p),b??J))},[s,o,J,st,q,Be]),nt=u.useRef(()=>{});nt.current=a=>{if(n)return;const p=i.editConnectionResources(g.map(v=>v.data.step),P.current,a),b=g.map((v,N)=>({...v,data:{...v.data,step:p.nodes[N]}}));E(p.connections),R(b),ee(b,A)};const Ke=u.useCallback(a=>nt.current(a),[]),jt=u.useCallback(a=>{U(a),ke(null),R(p=>p.map(b=>({...b,selected:b.id===a}))),X(p=>p.map(b=>({...b,selected:!1}))),De({nodes:[{id:a}],duration:300,maxZoom:1})},[R,X,De]),[ut,ue]=u.useState(null),vt=u.useMemo(()=>ut?g.map(a=>a.id===ut?{...a,className:`${a.className??""} w6w-connection-highlight`.trim()}:a):g,[g,ut]),pt=g.map(a=>({id:a.data.step.id,uses:a.data.step.uses})),Bt=JSON.stringify(pt),yt=JSON.stringify([...y]);u.useEffect(()=>{t==null||t({workflowId:s.id,nodes:pt,apps:y,connections:O,readOnly:n,edit:Ke,focusNode:jt,highlightNode:ue})},[t,s.id,Bt,yt,O,n,Ke,jt]),u.useEffect(()=>()=>t==null?void 0:t(null),[t]);const St=u.useCallback(a=>i.canConnect(a.source,a.target,g,A,Z,i.routeFromHandle(a.sourceHandle)),[g,A,Z]),[ot,Me]=u.useState(null),T=u.useRef(null),te=u.useRef(null);u.useEffect(()=>{R(a=>i.stampLoopOf(a,A))},[A,R]);const ae=u.useCallback(a=>{if(n)return;const p=i.applyConnect(a.source,a.target,g,A,i.laneForSourceHandle(a.sourceHandle),Z,i.routeFromHandle(a.sourceHandle));if(!p){const b=i.laneForSourceHandle(a.sourceHandle),v=i.connectRefusal(a.source,a.target,g,A,b,Z,i.routeFromHandle(a.sourceHandle));if(v&&v.refused==="loop"){Me({nodeId:a.source,reason:v.reason});return}if(v){const D=A.find($=>$.source===a.source&&i.edgeLane($)===b);D&&(X(A.map($=>({...$,selected:$.id===D.id}))),ke(D.id),Xe({edgeId:D.id,message:Sn(v.cap)}));return}const N=i.connectConflict(a.source,a.target,g,A,i.laneForSourceHandle(a.sourceHandle));if(!N)return;X(A.map(D=>({...D,selected:D.id===N}))),ke(N),Xe({edgeId:N,message:i.idClashMessage("Can’t draw that edge",N,yn(A,N,a.source,a.target))});return}Xe(null),Me(null),X(p),ee(g,p)},[A,g,X,ee,n,Z]),je=u.useCallback((a,p)=>{var G,se,pe;if(n||p.isValid)return;const b=p.fromNode;if(!b)return;const v=((G=p.fromHandle)==null?void 0:G.type)==="target"?"target":"source",N=p.toNode;if(N&&v==="source"){const re=mi(b.id,N.id,gn(te.current,b.id,p.fromHandle),g,A);if(re){Me({nodeId:b.id,reason:re});return}}const D=(se=g.find(re=>re.id===b.id))==null?void 0:se.data.step;if(D){const re=i.nodePortsForStep(D,Z);if((v==="source"?re.out:re.in)<1)return}const $="changedTouches"in a?a.changedTouches[0]:a,_=Le({x:$.clientX,y:$.clientY});$e({nodeId:b.id,handleType:v,position:_,lane:gn(te.current,b.id,p.fromHandle),route:i.routeFromHandle((pe=p.fromHandle)==null?void 0:pe.id)}),oe(!0)},[n,Le,g,A,Z]),Ye=u.useCallback((a,p,b)=>{if(n)return;const v=g.find(G=>G.id===a);if(!v)return;const N=ss(v),D=i.laneForSourceHandle(b),$=120,_=p==="target"?{x:N.x-N.w-$,y:N.y}:D==="error"?{x:N.x,y:N.y+N.h+$}:D==="each"?{x:N.x+N.w+$,y:N.y-N.h-$/2}:{x:N.x+N.w+$,y:N.y};$e({nodeId:a,handleType:p,position:_,lane:D,route:i.routeFromHandle(b)}),oe(!0)},[n,g]),js=u.useCallback(a=>{n||Fe({nodeIds:[a],edgeIds:[]})},[n]),Yn=u.useCallback(a=>{if(n)return;const p=Ko(a,g,A,J);R(p.nodes),X(p.edges),H(p.canvas),p.nodes.some(b=>b.id===z)||U(null),p.nodes.some(b=>b.id===de)||Re(null),p.edges.some(b=>b.id===ce)||ke(null),ee(p.nodes,p.edges,p.canvas)},[g,A,J,R,X,ee,n,z,de,ce]),vs=u.useCallback(()=>{if(n)return;const a=si(g,A,J);R(a.nodes),H(a.canvas),ct.current=!0,ee(a.nodes,A,a.canvas)},[g,A,J,R,ee,n]),Xn=u.useCallback(()=>{n||vs()},[n,vs]);u.useEffect(()=>{ct.current&&(ct.current=!1,De({duration:300}))},[g,De]);const ys=u.useRef(m);u.useEffect(()=>{Object.is(ys.current,m)||(ys.current=m,De({duration:300}))},[m,De]);const[Nt,Xe]=u.useState(null),it=u.useMemo(()=>A.find(a=>a.id===ce)??null,[A,ce]),Zn=u.useCallback(a=>{if(n||!ce)return;const p=A.find($=>$.id===ce);if(!p||i.edgeLane(p)===a)return;const b=i.edgeWhenConflict(A,ce,a,g),v=i.relaneRefusal(A,ce,a,g,Z),N=b||v?null:i.setEdgeWhen(A,ce,a,g,Z);if(!N){if(v){Xe({edgeId:ce,message:Sn(v.cap)});return}Xe({edgeId:ce,message:b?i.idClashMessage("Can’t switch this edge",b,yn(A,b,p.source,p.target)):"This edge can’t be switched right now."});return}Xe(null),X(N);const D=N.find($=>$.source===p.source&&$.target===p.target&&i.edgeLane($)===a);ke((D==null?void 0:D.id)??null),ee(g,N)},[A,g,X,ee,n,ce,Z]),Qn=u.useCallback(a=>{if(n)return;const p=A.filter(b=>b.id!==a);p.length!==A.length&&(X(p),ce===a&&ke(null),ee(g,p))},[g,A,X,ee,n,ce]),Vt=u.useCallback(a=>{if(n)return;const p=a.map(D=>g.find($=>$.id===D)).filter(D=>D!==void 0);if(p.length===0)return;const b=g.map(D=>D.id),v=p.map(D=>{const $=i.suggestStepId(b,`${D.data.step.id}_copy`);b.push($);const _={...i.stripBody(structuredClone(D.data.step)),id:$};return{id:$,type:D.type,position:{x:D.position.x+40,y:D.position.y+60},data:{step:_,isInternal:D.data.isInternal},...p.length>1?{selected:!0}:{}}}),N=[...p.length>1?g.map(D=>D.selected?{...D,selected:!1}:D):g,...v];R(N),U(v[0].id),ee(N,A)},[g,A,R,ee,n]),Ss=u.useCallback(a=>Vt([a]),[Vt]),eo=u.useCallback(a=>{if(n)return;const p=i.isInternalApp(a.uses.app),b=g.map(re=>re.id),v=a.id&&!i.stepNameError(a.id,b)?a.id:i.suggestStepId(b,i.slugifyLabel(i.internalNodeLabel(a.uses.app,a.uses.action))),N=V({id:v,uses:a.uses,...a.with&&Object.keys(a.with).length>0?{with:a.with}:{}}),D={id:v,type:p?"control":"step",position:(be==null?void 0:be.position)??(ye==null?void 0:ye.position)??{x:80,y:80+g.length*24},data:{step:N,isInternal:p}},$=ye!=null&&ye.replaces?g.find(re=>re.id===ye.replaces):void 0;if($&&i.isTriggerStep(a.uses)){const re={...D,position:$.position},he=[...g.filter(mt=>mt.id!==$.id),re],me=i.renameStepInEdges(A,$.id,v),Te=os(J,$.id,v);return R(he),X(me),H(Te),Me(null),U(v),ee(he,me,Te),v}const _=[...g,D];let G=A,se=null;const pe=(re,he,me,Te)=>{const mt=i.connectRefusal(re,he,_,A,me,Z);mt&&mt.refused==="loop"&&(se={nodeId:Te,reason:mt.reason})};if(be){const[re,he]=be.handleType==="target"?[v,be.nodeId]:[be.nodeId,v],me=i.applyConnect(re,he,_,A,be.lane,Z,be.route);me||pe(re,he,be.lane,be.nodeId),G=me??A}else{const re=g.find(he=>i.isTriggerStep(he.data.step.uses));if(i.isTriggerStep(a.uses)){if(!re){const he=i.findChainRoot(g,A);if(he){const me=i.applyConnect(v,he.id,_,A,"success",Z);me||pe(v,he.id,"success",he.id),G=me??A}}}else{const me=(re&&!A.some(Te=>Te.source===re.id)?re:void 0)??i.findChainTail(g,A);if(me){const Te=i.applyConnect(me.id,v,_,A,"success",Z);Te||pe(me.id,v,"success",me.id),G=Te??A}}}return R(_),G!==A&&X(G),Me(se),U(v),ee(_,G),v},[g,A,R,X,ee,n,be,ye,Z,V,J]),Ns=u.useCallback((a,p)=>{var G;let b=p;const v=(G=g.find(se=>se.id===a))==null?void 0:G.data.step;if(p.uses.connection&&!p.uses.connectionRef&&(v!=null&&v.uses.connectionRef)&&v.uses.app===p.uses.app){const se=i.selectNodeConnection(i.withConnectionRef(p,v.uses.connectionRef),p.uses.connection,g.map(pe=>pe.data.step),P.current);E(se.connections),b=se.step}else b=V(p);const N=b.id!==a;if(N&&g.some(se=>se.id===b.id))return;const D=g.map(se=>se.id===a?{...se,id:b.id,data:{step:b,isInternal:i.isInternalApp(b.uses.app)}}:se);if(N){const se=i.renameStepInEdges(A,a,b.id),pe=os(J,a,b.id);R(D),X(se),H(pe),z===a&&U(b.id),de===a&&Re(b.id),ee(D,se,pe);return}R(D);const $=new Set(i.routesForStep(b).map(se=>se.id)),_=A.filter(se=>{var pe;return se.source!==b.id||((pe=se.data)==null?void 0:pe.route)===void 0||$.has(String(se.data.route))});_.length!==A.length&&X(_),ee(D,_)},[g,A,J,R,X,z,de,ee,V,E]),Ze=u.useCallback(a=>{n||(H(a),ee(g,A,a))},[n,g,A,ee]),to=u.useCallback(()=>{var N;if(n)return;const a=(N=Ne.current)==null?void 0:N.getBoundingClientRect(),p=a?Le({x:a.left+a.width/2,y:a.top+a.height/2}):{x:0,y:0},b=J.notes??[],v={id:Nn("note",b.map(D=>D.id)),color:"#facc15",position:{x:Math.round(p.x-100),y:Math.round(p.y-60)},size:{width:200,height:120},content:""};Ze(rs({...J,notes:[...b,v]}))},[n,J,Le,Ze]),so=u.useCallback((a,p)=>{if(n)return;const b=p?Math.min(a.x,p.x):a.x,v=p?Math.min(a.y,p.y):a.y,N=p?Math.abs(p.x-a.x):360,D=p?Math.abs(p.y-a.y):240,$=g.filter(re=>{const he=ss(re),me=he.x+he.w/2,Te=he.y+he.h/2;return me>=b&&me<=b+N&&Te>=v&&Te<=v+D}).map(re=>re.id),_=J.sections??[],G=Nn("section",_.map(re=>re.id)),se={id:G,title:"Section",color:"#6366f1",position:{x:Math.round(b),y:Math.round(v)},size:{width:Math.round(N),height:Math.round(D)},nodes:[]},pe={...J,sections:[..._,se]};Ze(rs(is(pe,G,$)))},[n,g,J,Ze]);u.useEffect(()=>{if(!_e)return;const a=p=>{p.key==="Escape"&&(lt(!1),qe(null))};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[_e]);const no=u.useCallback((a,p)=>{var $;if(n)return;const b=($=J.sections)==null?void 0:$.find(_=>_.id===a);if(!b)return;const v=new Set(b.nodes),N=g.map(_=>v.has(_.id)?{..._,position:{x:_.position.x+p.dx,y:_.position.y+p.dy}}:_),D={...J,sections:(J.sections??[]).map(_=>_.id===a?{..._,position:{x:_.position.x+p.dx,y:_.position.y+p.dy}}:_)};R(N),H(D),ee(N,A,D)},[n,J,g,A,R,ee]),oo=u.useCallback((a,p)=>{if(n)return;const b=a==="note"?{...J,notes:(J.notes??[]).filter(v=>v.id!==p)}:{...J,sections:(J.sections??[]).filter(v=>v.id!==p)};Ze(b)},[n,J,Ze]),io=a=>{let p=J;for(const b of a){const v=ss(b),N=v.x+v.w/2,D=v.y+v.h/2,$=(p.sections??[]).find(G=>N>=G.position.x&&N<=G.position.x+G.size.width&&D>=G.position.y&&D<=G.position.y+G.size.height),_=In(p,b.id);$?(_.length!==1||_[0]!==$.id)&&(p=is(p,$.id,[b.id])):_.length>0&&(p=us(p,b.id))}return p},zt=u.useCallback((a,p,b)=>{(async()=>{const v=await j.saveStepTest(s.id,a,p).catch(N=>(console.error("step run fixture save failed",N),null));await j.recordStepTestRun(s.id,a,{stepTestId:(v==null?void 0:v.id)??null,status:b.status,input:p.input,output:b.output,error:b.error,...b.meta?{meta:b.meta}:{}})})().catch(v=>{console.error("step run persist failed",v)})},[j,s.id]),Cs=u.useCallback(a=>{const p=g.find(b=>b.id===a);!p||!k&&i.isControlApp(p.data.step.uses.app)||w({stepId:a,status:"collect"})},[g,k]),ro=u.useCallback(async(a,p,b)=>{if(!k)return;const v=g.find($=>$.id===a);if(!v)return;const N=i.isTriggerStep(v.data.step.uses),D={stopAt:ls(g.map($=>$.data.step),a),...b?{state:b}:{},...N?{input:p}:{}};w({stepId:a,status:"running"});try{await k(a,D),w(null)}catch($){const _=$;w({stepId:a,status:"error",error:_.message??String($),errorCode:_.code})}},[g,k]),Ct=u.useCallback((a,p)=>{if(n)return;const b=g.map(v=>v.id===a?{...v,data:{...v.data,step:p(v.data.step)}}:v);R(b),ee(b,A)},[g,A,R,ee,n]),ks=u.useCallback(a=>Ct(a,p=>Ln(p,!tt(p))),[Ct]),Es=u.useCallback(a=>Ct(a,p=>Dn(p,!We(p))),[Ct]),ao=u.useCallback(async(a,p,b)=>{h==null||h();const v=g.find(G=>G.id===a);if(!v)return;const N=v.data.step,D=i.isTriggerStep(N.uses),$=D?{input:p}:{...N.with??{},...p},_=D?{input:p,with:p}:{input:p,with:$};w({stepId:a,status:"running"});try{const G=await j.invokeAction(N.uses.app,N.uses.action,$,{connectionId:i.connectionIdFor(N,P.current),project:f,...b?{state:b}:{},workflowId:s.id,...N.timeoutMs?{timeoutMs:N.timeoutMs}:{}}),se=G.logs,pe=G.meta;w({stepId:a,status:"done",value:G.value,logs:se,...pe?{meta:pe}:{}}),zt(a,_,{status:"succeeded",output:G.value,...pe?{meta:pe}:{}})}catch(G){const se=G;w({stepId:a,status:"error",error:se.message??String(G),errorCode:se.code}),zt(a,_,{status:"failed",error:se.message??String(G)})}},[g,j,zt,f,h,s.id]),Ut=u.useMemo(()=>({onEdit:a=>{Ee("props"),Re(a)},onEditJson:a=>{Ee("json"),Re(a)},onRun:Cs,onDuplicate:Ss,onDelete:js,onTogglePause:ks,onToggleDisable:Es,runsFromNode:!!k,onAddFromPort:Ye,readOnly:n}),[Cs,Ss,js,ks,Es,k,Ye,n]);u.useEffect(()=>{const a=Ne.current;if(!a)return;const p=b=>{const v=b.target.closest(".react-flow__node");if(!v)return;const N=v.getAttribute("data-id");N&&(b.stopPropagation(),Ut.onEdit(N))};return a.addEventListener("dblclick",p,!0),()=>a.removeEventListener("dblclick",p,!0)},[Ut]);const rt=g.find(a=>a.id===de),kt=(rt==null?void 0:rt.data.step)??null,Ht=M?((Xs=g.find(a=>a.id===M.stepId))==null?void 0:Xs.data.step)??null:null,Jt=(M==null?void 0:M.status)==="collect"&&!!Ht,Ts=u.useMemo(()=>{const a=new Map;for(const p of g)a.set(p.id,i.fanOutState(p.id,A).count);return a},[g,A]),As=ai(g),Et=u.useMemo(()=>li(As),[As]),lo=u.useMemo(()=>ii(A,Et.tones,Et.loopOf),[A,Et]),co=u.useMemo(()=>({step:Ji,control:qi}),[]),[Tt,Is]=u.useState({}),[At,Rs]=u.useState({}),[Ps,Fs]=u.useState({}),[It,Ls]=u.useState({}),[ze,Rt]=u.useState(null),[Ds,Ms]=u.useState([]),uo=de??ze??"";u.useEffect(()=>{const a=j.loadNodeSamples;if(typeof a!="function"||!s.id){Ms([]);return}let p=!1;return a(s.id).then(b=>{p||Ms(Array.isArray(b)?b:[])},()=>{}),()=>{p=!0}},[j,s.id,uo]);const Pt=u.useMemo(()=>i.indexNodeSamples(Ds),[Ds]),qt=u.useMemo(()=>i.splitNodeOutputs(Tt,Pt,It),[Tt,Pt,It]),Ue=u.useMemo(()=>i.splitPreviewOutputs(Tt,Pt,It),[Tt,Pt,It]),Ce=u.useMemo(()=>({actionDef:(a,p)=>{var b;return(b=B[a])==null?void 0:b.find(v=>v.key===p)},triggerDef:(a,p)=>{var b;return(b=ne[a])==null?void 0:b.find(v=>v.key===p)},testOutputs:qt.fresh,persistedOutputs:qt.persisted,loopSamples:Ps}),[B,ne,qt,Ps]),Qe=u.useMemo(()=>M?i.upstreamStateSources(M.stepId,g,A,Ce):void 0,[M,g,A,Ce]),po=u.useMemo(()=>(Qe==null?void 0:Qe.steps)??[],[Qe]),ve=u.useMemo(()=>{const a=i.upstreamStateSources(de,g,A,Ce,ze);return{...a,steps:i.excludeSelfStep(a.steps,de??ze)}},[de,ze,g,A,Ce]),ft=u.useMemo(()=>Ci({anchorId:de??ze,nodes:g,edges:A,floating:i.isFloatingDraft(de,ze,g,A),initialState:s.initialState,variables:s.variables,shapes:Ce,previewOutputs:{...Ue.persisted,...Ue.fresh}}),[de,ze,g,A,s.initialState,s.variables,Ce,Ue]),_s=JSON.stringify([...ve.steps.map(a=>a.id),...ve.extraSampleIds??[]]);u.useEffect(()=>{const a=JSON.parse(_s);if(!de&&!ze||a.length===0){Is({}),Rs({}),Fs({}),Ls({});return}let p=!1;return Promise.all(a.map(async b=>{try{const v=await j.listStepTests(s.id,b),N=v.length?v[v.length-1]:null;return N?{id:b,output:N.lastRunOutput,runAt:N.lastRunAt,meta:N.lastRunMeta,loopSample:i.foreachTestSample(N)}:null}catch{return null}})).then(b=>{if(p)return;const v={},N={},D={},$={};for(const _ of b)_!=null&&_.meta&&(N[_.id]=_.meta),_!=null&&_.loopSample&&(D[_.id]=_.loopSample),!(!_||_.output===void 0||_.output===null)&&(v[_.id]=_.output,$[_.id]=_.runAt);Is(v),Ls($),Rs(N),Fs(D)}),()=>{p=!0}},[j,s.id,de,ze,_s]);const Gt=u.useMemo(()=>i.declaredSamples(g,Ce),[g,Ce]),Ft=u.useMemo(()=>({persisted:Ue.persisted,samples:Gt.samples,event:Gt.event}),[Ue.persisted,Gt]),Os=u.useMemo(()=>i.upstreamSampleValues(ve.steps,Ue.fresh,At,ve.loop,Ft),[ve.steps,ve.loop,Ue.fresh,At,Ft]),$s=u.useMemo(()=>i.upstreamSampleValueSources(ve.steps,Ue.fresh,At,ve.loop,Ft),[ve.steps,ve.loop,Ue.fresh,At,Ft]),Ws=i.useExpressionOptions(),Bs=u.useMemo(()=>i.nodeConfigSources(g),[g]),Vs=u.useMemo(()=>i.nodeConfigValues(g,C.subs),[g,C.subs]),Kt=u.useMemo(()=>i.nodeMetaValues(g,C.subs,y,O),[g,C.subs,y,O]),zs=u.useMemo(()=>[...new Set(Object.values(O).flatMap(a=>a.connection?[a.connection]:[]))].sort().join(","),[O]),[Us,fo]=u.useState(()=>new Map);u.useEffect(()=>{if(!zs)return;let a=!0;return j.listConnections().then(p=>{a&&fo(new Map(p.map(b=>[b.id,b])))}).catch(()=>{}),()=>{a=!1}},[j,zs]);const Yt=u.useMemo(()=>i.connectionExpressionSources(O,Us,y),[O,Us,y]),Xt=u.useMemo(()=>({...l??{},connections:Yt.sources,steps:ve.steps,hasTrigger:ve.hasTrigger,eventOutputs:ve.eventOutputs,eventOutputsFrom:ve.eventOutputsFrom,loop:ve.loop,stateShape:{fields:ft.fields,...ft.written?{written:ft.written}:{}},nodeConfigs:Bs,nodeConfig:Vs,nodeMeta:Kt,valueSources:$s,sampleValues:{...Ws.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...Yt.sampleValues,...i.nodeMetaSampleValues(Kt),...Os,...ft.sampleValues}}),[l,Ws.sampleValues,ve,ft,Os,$s,Bs,Vs,Kt,Yt]),ht=u.useRef(null);Be||de?ht.current===null&&(ht.current=q.mark()):ht.current=null;const Hs=()=>{oe(!1),$e(null),Ve(null),Rt(null)},Js=()=>{const a=ht.current;if(ht.current=null,n||a===null)return;const p=q.rollbackTo(a);p&&Gs(p)},qs=a=>{if(n)return;const p=q[a]();p&&Gs(p)},Gs=a=>{var v;const p=Xo(s,a);R(p.nodes.map(N=>({...N,selected:N.id===z}))),X(p.edges.map(N=>({...N,selected:N.id===ce}))),H(a.canvas),E(a.connections),p.nodes.some(N=>N.id===z)||U(null),p.edges.some(N=>N.id===ce)||ke(null);const b=p.nodes.some(N=>N.id===de);b||Re(null),oe(!1),Rt(null),$e(null),Fe(null),ge(null),Ve(null),Ge(null),Me(null),Xe(null),Q.current=void 0,Je(N=>N+1),o(st(i.flowToWorkflow({...s,nodes:a.nodes,connections:a.connections},p.nodes,p.edges),a.canvas)),!b&&!M&&((v=Ne.current)==null||v.focus({preventScroll:!0}))},Ks=u.useRef(qs);Ks.current=qs,u.useEffect(()=>{const a=Ne.current;if(!a)return;let p=a.contains(document.activeElement);const b=N=>{N.type==="focusin"&&N.target===document.body||(p=a.contains(N.target))},v=N=>{if(n||N.defaultPrevented||Qt(N.target)||!a.contains(N.target)&&!(p&&N.target===document.body))return;const D=N.key.toLowerCase();!(N.ctrlKey||N.metaKey)||N.altKey||D!=="z"&&!(D==="y"&&!N.shiftKey)||(N.preventDefault(),Ks.current(D==="y"||N.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",b),document.addEventListener("focusin",b),document.addEventListener("keydown",v),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("focusin",b),document.removeEventListener("keydown",v)}},[n]);const Lt=u.useCallback((a,p)=>{var _;if(Qt(a.target))return;const b=(_=Ne.current)==null?void 0:_.getBoundingClientRect();if(!b)return;a.preventDefault();const v=fn(g,A),N=v.nodeIds,D=Do(N,p),$=p!==void 0&&!N.includes(p);$&&R(g.map(G=>G.selected!==(G.id===p)?{...G,selected:G.id===p}:G)),Ge({x:a.clientX-b.left,y:a.clientY-b.top,flow:Le({x:a.clientX,y:a.clientY}),nodeIds:D,edgeIds:$?[]:v.edgeIds})},[g,A,R,Le]),ho=u.useCallback(a=>{var p;Ge(null),a&&((p=Ne.current)==null||p.focus({preventScroll:!0}))},[]),mo=a=>{const p=xe;if(!(!p||n))if(a==="duplicate")Vt(p.nodeIds);else if(a==="delete")Fe({nodeIds:p.nodeIds,edgeIds:p.edgeIds});else if(a==="replace-trigger"){const b=g.find(v=>v.id===p.nodeIds[0]);if(!b)return;$e(null),Ve({position:b.position,tab:"triggers",replaces:b.id}),oe(!0)}else $e(null),Ve({position:p.flow,...a==="add-trigger"?{tab:"triggers"}:{}}),oe(!0)},wo=e.jsx(xs.Provider,{value:Ut,children:e.jsx(hs.Provider,{value:Z,children:e.jsx(ms.Provider,{value:Ts,children:e.jsx(ws.Provider,{value:Et,children:e.jsx(Di,{apps:y,registration:C,children:e.jsx(i.WorkflowProjectProvider,{project:f,workflowId:s.id,children:e.jsx(i.ExpressionOptionsProvider,{value:Xt,children:e.jsxs("section",{ref:Ne,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:r,position:"relative"},onFocusCapture:a=>{Q.current=Qt(a.target)?{}:void 0},onBlurCapture:()=>{Q.current=void 0},onKeyDown:a=>{if(a.defaultPrevented||a.key!=="Backspace"&&a.key!=="Delete"||n||de||Be||Pe)return;const p=a.target;if(p.isContentEditable||p.tagName==="INPUT"||p.tagName==="TEXTAREA"||p.tagName==="SELECT"||p.closest("dialog, .w6w-modal")!==null)return;const b=fn(g,A);!b.nodeIds.length&&!b.edgeIds.length||(a.preventDefault(),!b.nodeIds.length&&b.edgeIds.length===1?Qn(b.edgeIds[0]):Fe(b))},children:[e.jsxs(le.ReactFlow,{nodes:vt,edges:lo,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:le.ConnectionLineType.SmoothStep,onNodesChange:Y,onEdgesChange:L,onConnect:ae,onConnectStart:(a,p)=>{te.current=p},onConnectEnd:je,onPaneClick:()=>Me(null),onPaneContextMenu:a=>Lt(a),onNodeContextMenu:(a,p)=>Lt(a,p.id),onEdgeContextMenu:a=>Lt(a),onSelectionContextMenu:a=>Lt(a),onMoveStart:()=>Ge(null),isValidConnection:St,onNodeDragStop:(a,p,b)=>{const v=io(b),N=v!==J;if(N&&H(v),!S&&!N){q.record(Mt(s,g,A,P.current,v));return}ee(g,A,v)},onMoveEnd:(a,p)=>{if(!a||n)return;const b=i.flowToWorkflow(s,g,A),v=i.withViewport(b,p);v!==b&&o(v,{viewportOnly:!0})},onSelectionChange:({nodes:a,edges:p})=>{var b,v,N,D;U(((b=a[0])==null?void 0:b.id)??null),ke(((v=p[0])==null?void 0:v.id)??null),T.current!==(((N=a[0])==null?void 0:N.id)??null)&&(T.current=((D=a[0])==null?void 0:D.id)??null,Me(null))},nodeTypes:co,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...K?{defaultViewport:K}:{fitView:!0,fitViewOptions:{maxZoom:1}},deleteKeyCode:null,colorMode:dt,proOptions:{hideAttribution:!0},children:[e.jsx(le.Background,{gap:16}),e.jsx(le.Controls,{showInteractive:!1,children:!n&&e.jsx(le.ControlButton,{onClick:Xn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:e.jsx(we.Icon,{name:"layout"})})}),e.jsx(le.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&e.jsxs(le.Panel,{position:"top-left",className:"w6w-flow-tools",children:[e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>oe(!0),children:"+ Node"}),e.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:to}),e.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${_e?" active":""}`,"aria-pressed":_e,"data-testid":"draw-section",onClick:()=>{lt(!_e),qe(null)}})]}),!n&&_e&&e.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:a=>{if(a.button!==0)return;a.currentTarget.setPointerCapture(a.pointerId);const{clientX:p,clientY:b}=a;qe({sx:p,sy:b,ex:p,ey:b})},onPointerMove:a=>{const{clientX:p,clientY:b}=a;qe(v=>v&&{...v,ex:p,ey:b})},onPointerUp:()=>{const a=Se;if(qe(null),lt(!1),!a)return;const p=Le({x:a.sx,y:a.sy}),b=Math.abs(a.ex-a.sx)>6||Math.abs(a.ey-a.sy)>6;so(p,b?Le({x:a.ex,y:a.ey}):null)},children:Se&&(()=>{var v;const a=(v=Ne.current)==null?void 0:v.getBoundingClientRect(),p=(a==null?void 0:a.left)??0,b=(a==null?void 0:a.top)??0;return e.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(Se.sx,Se.ex)-p,top:Math.min(Se.sy,Se.ey)-b,width:Math.abs(Se.ex-Se.sx),height:Math.abs(Se.ey-Se.sy)}})})()}),!n&&it&&i.edgeLane(it)!=="each"&&((Zs=g.find(a=>a.id===it.source))==null?void 0:Zs.data.step.uses.app)!==i.ROUTER_APP&&e.jsx(le.Panel,{position:"top-right",children:e.jsxs("div",{className:"w6w-edge-lane",children:[e.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(a=>e.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${i.edgeLane(it)===a?" active":""}`,"aria-pressed":i.edgeLane(it)===a,title:Li,onClick:()=>Zn(a),children:a==="success"?"Success":"Error"},a)),(Nt==null?void 0:Nt.edgeId)===it.id&&e.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:Nt.message})]})}),ot&&e.jsx(le.NodeToolbar,{nodeId:ot.nodeId,position:le.Position.Bottom,isVisible:!0,children:e.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:i.loopRefusalMessage(ot.reason)})}),e.jsx(i.CanvasLayer,{canvas:J,readOnly:n,savePosition:S,onChange:Ze,onSectionDrop:no,onRequestDelete:(a,p)=>!n&&ge({kind:a,id:p})})]}),Ie&&e.jsx(i.ConfirmModal,{title:Ie.kind==="note"?"Delete note":"Delete section",message:Ie.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{oo(Ie.kind,Ie.id),ge(null)},onClose:()=>ge(null)}),Be&&e.jsx(i.StepBuilderModal,{initialTab:ye==null?void 0:ye.tab,onClose:()=>{Js(),Hs()},onDone:Hs,onAdd:a=>{const p=eo(a);return p&&Rt(p),p},onDraftChange:(a,p)=>Ns(a,{id:a,...p}),stepIds:g.map(a=>a.id),onOpenStep:a=>{oe(!1),$e(null),Ve(null),Rt(null),Ee("props"),Re(a)},workflowId:s.id,upstreamSteps:i.stepBuilderUpstreamSteps(be,g,A),loop:i.stepBuilderLoop(be,g,A,Ce)}),kt&&de&&e.jsx(Ki,{workflowId:s.id,step:kt,restoreVersion:fe,upstreamSteps:Xt.steps??[],loop:Xt.loop,readOnly:n,fanOutCount:Ts.get(de)??0,stateOutputFields:(sn=i.resolveOutputShape((Qs=Ce.actionDef)==null?void 0:Qs.call(Ce,kt.uses.app,kt.uses.action),(en=Ce.testOutputs)==null?void 0:en[de],(tn=Ce.persistedOutputs)==null?void 0:tn[de]))==null?void 0:sn.fields.map(a=>a.key),initialView:Oe,stepProblems:rt==null?void 0:rt.data.stepProblems,otherStepIds:g.filter(a=>a.id!==de).map(a=>a.id),onChange:a=>Ns(de,a),onClose:()=>Re(null),onCancel:()=>{Js(),Re(null)},onTestRun:h}),M&&e.jsxs(i.Modal,{title:`${Jt?"Run node":"Test run"}: ${M.stepId}`,onClose:()=>w(null),children:[Jt&&Ht&&e.jsx(Bi,{workflowId:s.id,step:Ht,upstreamSteps:po,loop:Qe==null?void 0:Qe.loop,continues:k?{stopAt:ls(g.map(a=>a.data.step),M.stepId)}:void 0,onCancel:()=>w(null),onRun:(a,p)=>k?ro(M.stepId,a,p):ao(M.stepId,a,p)},M.stepId),!Jt&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w6w-modal-body",children:[M.status==="running"&&e.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),M.status==="error"&&e.jsxs("div",{className:"w6w-result w6w-error",children:[M.errorCode&&e.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:e.jsx("code",{children:M.errorCode})}),M.error||"The node failed with no error message."]}),M.status==="done"&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),e.jsx(i.ResultViewer,{value:M.value,maxHeight:360}),M.meta&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),e.jsx(i.ResultViewer,{value:M.meta,maxHeight:360})]})]}),M.logs&&M.logs.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),e.jsx(we.Copyable,{value:M.logs.join(`
|
|
3
5
|
`),label:"Copy console output",children:e.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:M.logs.join(`
|
|
4
|
-
`)})})]})]}),e.jsx("div",{className:"w6w-modal-actions",children:e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>w(null),children:"Close"})})]})]}),Re!==null&&e.jsx(i.ConfirmModal,{title:Re.nodeIds.length===1?"Delete node":Re.nodeIds.length>1?`Delete ${Re.nodeIds.length} nodes`:`Delete ${Re.edgeIds.length} connections`,message:Go(Re,g,A),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{Gn(Re),Fe(null)},onClose:()=>Fe(null)}),xe&&e.jsx(go,{x:xe.x,y:xe.y,items:Do(xe.nodeIds,!!n,{replaceableTrigger:xe.nodeIds.length===1&&g.some(a=>a.id===xe.nodeIds[0]&&i.isTriggerStep(a.data.step.uses))}),onAction:fo,onClose:po})]})})})})})})})});return e.jsx(i.WorkflowConnectionsContext.Provider,{value:{nodes:g.map(a=>a.data.step),connections:O,setConnections:E,readOnly:n},children:ho})}const Mi=["code"];function Wt(t){try{const s=JSON.parse(t);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function _i(t){try{const s=JSON.parse(t);if(Array.isArray(s))return{items:s}}catch{return null}return Wt(t)}function Oi({items:t,save:s}){if(!t)return e.jsxs("output",{className:"w6w-small",style:{display:"block"},children:[e.jsx("strong",{children:"Items"})," doesn't resolve to a list yet: no step before this one has a saved test that produces it. Test an earlier step, or paste a sample list under"," ",e.jsx("strong",{children:"Override the incoming state"})," below."]});const o=t[0],n=o!==void 0?(i.inferOutputFields(o)??[]).map(r=>r.key):[];return e.jsxs("div",{className:"w6w-testout",children:[e.jsxs("div",{className:"w6w-testout-label",children:[t.length," ",t.length===1?"item":"items"]}),t.length===0?e.jsx("p",{className:"w6w-muted w6w-small",children:"The list is empty, so there is no item to sample."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w6w-testout-label",children:"First item"}),e.jsx(i.ResultViewer,{value:o,maxHeight:220})]}),s==="saved"&&e.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",n.length>0&&e.jsxs(e.Fragment,{children:[" ","Steps on ",e.jsx("strong",{children:"Each item"})," now offer ",e.jsx("strong",{children:"Current item"})," ›"," ",n.map((r,c)=>e.jsxs("span",{children:[c>0&&", ",e.jsx("code",{children:r})]},r)),"."]})]}),s==="failed"&&e.jsx("p",{className:"w6w-small",role:"alert",children:"Couldn't save the sample. Try Test again."})]})}function On(t){const[s,o]=u.useState(null),[n,r]=u.useState("0"),[c,l]=u.useState({}),[f,d]=u.useState({}),x=s??i.loopItemText(t),h=((t==null?void 0:t.outer)??[]).map(j=>({foreachId:j.foreachId,name:j.name??j.foreachId,itemText:c[j.foreachId]??i.loopItemText(j),indexText:f[j.foreachId]??"0",setItemText:y=>l(C=>({...C,[j.foreachId]:y})),setIndexText:y=>d(C=>({...C,[j.foreachId]:y}))})),m=t?i.parseLoopSeed(x,n):void 0;let k=m!=null&&m.ok?{ok:!0,value:m.value}:m;if(t&&(m!=null&&m.ok)){const j={};for(const y of h){const C=i.parseLoopSeed(y.itemText,y.indexText);if(!C.ok){k={ok:!1,error:`${y.name}: ${C.error}`};break}j[y.foreachId]=C.value}k!=null&&k.ok&&(j[t.foreachId]=m.value,k={ok:!0,value:{...m.value,loops:j}})}return{active:!!t,itemText:x,indexText:n,setItemText:o,setIndexText:r,outers:h,parsed:k}}function $n(t){var s;return(s=t.parsed)!=null&&s.ok?t.parsed.value:void 0}function bs(t){return t.parsed&&!t.parsed.ok?t.parsed.error:null}function Wn({seed:t,readOnly:s}){if(!t.active)return null;const o=bs(t);return e.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[t.outers.map(n=>e.jsxs("div",{"data-testid":`loop-seed-outer-${n.foreachId}`,children:[e.jsxs("span",{children:[n.name," item"]}),e.jsx("textarea",{rows:3,value:n.itemText,readOnly:s,spellCheck:!1,"aria-label":`${n.name} item`,onChange:r=>n.setItemText(r.target.value)}),e.jsxs("span",{children:[n.name," index"]}),e.jsx("input",{type:"text",inputMode:"numeric",value:n.indexText,readOnly:s,"aria-label":`${n.name} index`,onChange:r=>n.setIndexText(r.target.value)})]},n.foreachId)),e.jsx("span",{children:"Current item"}),e.jsx("textarea",{rows:3,value:t.itemText,readOnly:s,spellCheck:!1,"aria-label":"Current item",onChange:n=>t.setItemText(n.target.value)}),e.jsx("span",{children:"Index"}),e.jsx("input",{type:"text",inputMode:"numeric",value:t.indexText,readOnly:s,"aria-label":"Index",onChange:n=>t.setIndexText(n.target.value)}),e.jsx("span",{className:"w6w-hint",children:"This step runs once per item of the For each. Test it as one iteration — starting from the sample item, or edit it."}),o&&e.jsx("span",{className:"w6w-hint",role:"alert",children:o})]})}function ds({text:t,onChange:s,seeds:o,readOnly:n,expand:r,hint:c}){const l=Wt(t),f=l?Object.keys(l).length:0,d=f>0,[x,h]=u.useState(d);u.useEffect(()=>{(d||r)&&h(!0)},[d,r]);const m=k=>{s(JSON.stringify(k.lastRunOutput??k.input??{},null,2)),h(!0)};return e.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[e.jsx("span",{children:"Incoming state"}),o.length>0&&e.jsx("div",{className:"w6w-seed-picker",children:e.jsx("div",{className:"w6w-seed-chips",children:o.map(k=>e.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${k.label}'s saved test as the incoming state`,disabled:n,onClick:()=>m(k.test),children:[e.jsx("code",{children:k.label}),k.test.lastRunStatus?e.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",k.test.lastRunStatus]}):null]},k.stepId))})}),e.jsxs("details",{className:"w6w-state-override",open:x,onToggle:k=>h(k.currentTarget.open),children:[e.jsxs("summary",{children:["Override the incoming state",f>0?` · ${f} key${f===1?"":"s"} set`:""]}),e.jsx("textarea",{rows:3,value:t,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:k=>s(k.target.value)}),e.jsx("span",{className:"w6w-hint",children:c??e.jsxs(e.Fragment,{children:["JSON whose keys replace this step's parameters by name, for this test only — so a script's data goes under ",e.jsx("code",{children:"input"}),": ",e.jsx("code",{children:'{"input": {…}}'}),". Upstream outputs already reach ",e.jsx("code",{children:"{{ nodes.<id>.output }}"})," bindings from their saved tests. Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})})]})]})}function $i({workflowId:t,step:s,upstreamSteps:o,loop:n,onRun:r,onCancel:c,continues:l}){var J;const f=i.useW6WApi(),d=i.isTriggerStep(s.uses),x=i.isInternalApp(s.uses.app),h=u.useMemo(()=>{var H;return d?i.asFieldDefs((H=s.with)==null?void 0:H.fields):[]},[d,s.with]),m=u.useMemo(()=>d?i.fieldsToParams(h):x?i.internalNodeParams(s.uses.app,s.uses.action):null,[d,x,h,s.uses.app,s.uses.action]),[k,j]=u.useState(null),y=m??k;u.useEffect(()=>{if(m)return;if(!s.uses.app||!s.uses.action){j([]);return}let H=!1;return j(null),f.getAppActions(s.uses.app).then(q=>{var Q;H||j(((Q=q.find(fe=>fe.key===s.uses.action))==null?void 0:Q.params)??[])}).catch(()=>!H&&j([])),()=>{H=!0}},[f,m,s.uses.app,s.uses.action]);const[C,M]=u.useState(()=>{var H;return d?i.seedValues(i.asFieldDefs((H=s.with)==null?void 0:H.fields)):{}}),[w,F]=u.useState("{}"),W=i.useSeedSources(t,o,!d),O=On(n),I=(J=i.useExpressionOptions().stateShape)==null?void 0:J.written,R=i.startStateFromSeeds(W,$n(O),I),E=i.useRememberedTestInput(t,s.id),[V,K]=u.useState(!1),[S,g]=u.useState(!1);u.useEffect(()=>{if(!E.loaded)return;let H=!1;const q=(Q,fe)=>{Q&&Object.keys(Q).length>0&&(d?M(Je=>({...Je,...Q})):F(JSON.stringify(Q,null,2)),fe&&g(!0)),K(!0)};if(E.input!==void 0){q(E.input,!0);return}return f.listStepTests(t,s.id).then(Q=>{if(H)return;const fe=Q.length?Q[Q.length-1]:null;q(d?fe==null?void 0:fe.with:fe==null?void 0:fe.input,!1)}).catch(()=>{H||K(!0)}),()=>{H=!0}},[f,t,s.id,d,E.loaded]);const[P,Y]=u.useState(0),B=()=>{E.clear(),g(!1),d?M(i.seedValues(h)):F("{}"),Y(H=>H+1)},ne=H=>{M(H),A(!0),g(!1),Y(q=>q+1)},[Z,A]=u.useState(!0),X=Wt(w),D=d?Z:X!==null,z=d?C:{...s.with??{},...X??{}},U=d?null:bs(O),ie=!!y&&V&&D&&!U&&i.requiredParamsFilled(y,z);return e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsx("div",{className:"w6w-modal-body",children:e.jsxs("div",{className:"w6w-stack",children:[l&&e.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"run-from-node-hint",children:["Runs this node, then continues through every node after it",l.stopAt.length>0?e.jsxs(e.Fragment,{children:[" ","and stops before"," ",l.stopAt.length===1?"the paused node":"paused nodes"," ",l.stopAt.map((H,q)=>e.jsxs("span",{children:[q>0?", ":"",e.jsx("code",{children:H})]},H))]}):null,". Disabled nodes are skipped."]}),S&&y!==null&&V&&e.jsx(i.LastUsedNote,{onClear:B}),y===null||!V?e.jsx("p",{className:"w6w-muted w6w-small",children:y===null?"Loading parameters…":"Loading saved values…"}):d?e.jsxs(e.Fragment,{children:[e.jsx(i.PropertyEntryForm,{params:y,values:C,onChange:M,onValidityChange:A},P),s.uses.trigger===!0&&e.jsx(i.TriggerSampleButton,{app:s.uses.app,trigger:s.uses.action,onUse:ne}),y.length===0&&e.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",e.jsx("code",{children:"input"}),")."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",e.jsx("code",{children:s.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),e.jsx(Wn,{seed:O}),e.jsx(ds,{text:w,onChange:F,seeds:W})]})]})}),e.jsxs("div",{className:"w6w-modal-actions",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Cancel"}),!ie&&y!==null&&V&&e.jsx("span",{className:"w6w-muted w6w-small",children:U?`${U} Fix it to run.`:D?d?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":d?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:!ie,onClick:()=>{E.save(d?C:X??{},y??[]),r(d?C:X??{},d?void 0:R)},children:"▶ Run"})]})]})}function Wi(t){return t.uses.app===i.CONTROL_APP&&t.uses.action==="foreach"}function Bn({id:t}){const{tones:s,loopOf:o}=u.useContext(ws),n=Pn(t,o);return n.length===0?null:e.jsx("span",{className:"w6w-loop-dots",children:n.map(r=>e.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${r}`,title:`In loop · ${r}`,style:{background:ps(s.get(r)??1)}},r))})}function Vn(t){return oi(t,u.useContext(ws).tones)}function He({type:t,position:s,multiple:o,id:n,variant:r,top:c,routeLabel:l}){const f=le.useNodeId(),d=u.useContext(xs),x=!!f&&!!d&&!d.readOnly,h=()=>{x&&f&&d.onAddFromPort(f,t,n)},m=r==="error"?"a step that handles this step's failure":r==="each"?"the first step of this loop's body":t==="target"?"a step before this one":"the next step";return e.jsx(le.Handle,{type:t,position:s,id:n,className:r==="error"?"w6w-handle-error":r==="each"?"w6w-handle-each":o?"w6w-handle-multi":void 0,style:{...o?{height:22,borderRadius:3,width:8}:{},...c?{top:c}:{}},onClick:x?h:void 0,title:l?`${l} — drag or click to connect`:x?`Drag to empty canvas (or click) to add ${m} · drag to a port to connect`:r==="error"?"On error — drag to route this step's failure separately":r==="each"?"Each item — drag to the first step to repeat for every item":o?t==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function zn({id:t,step:s,runnable:o}){const n=u.useContext(xs);if(!n||n.readOnly)return null;const r=o||n.runsFromNode,c=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=tt(s),f=We(s);return e.jsxs(le.NodeToolbar,{position:le.Position.Top,className:"w6w-node-toolbar",children:[r&&e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:c,"aria-label":c,onClick:()=>n.onRun(t),children:e.jsx(we.Icon,{name:"run",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":l,title:l?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":l?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(t),children:e.jsx(we.Icon,{name:"pause",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":f,title:f?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":f?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(t),children:e.jsx(we.Icon,{name:"ban",size:15})}),e.jsx("span",{className:"w6w-node-toolbar-divider","aria-hidden":"true"}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>n.onEdit(t),children:e.jsx(we.Icon,{name:"edit",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>n.onDuplicate(t),children:e.jsx(we.Icon,{name:"copy",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>n.onDelete(t),children:e.jsx(we.Icon,{name:"trash",size:15})})]})}function Un({step:t,count:s}){if(s<2)return null;const o=t.fanOut==="parallel",n=i.fanOutLabel(s,o?"parallel":"sequential");return e.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":n,title:n,children:[e.jsx("span",{"aria-hidden":"true",children:o?"⇉":"→"})," ",s]})}function Hn({step:t}){const s=tt(t),o=We(t);return!s&&!o?null:e.jsxs("div",{children:[o&&e.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":fn,title:fn,children:[e.jsx(we.Icon,{name:"ban",size:11})," Disabled"]}),s&&e.jsxs("span",{className:"w6w-node-flag w6w-node-flag-paused","data-testid":"step-paused-badge",role:"img","aria-label":pn,title:pn,children:[e.jsx(we.Icon,{name:"pause",size:11})," Paused"]})]})}function Jn(t){return!t||t.length===0?{}:{"data-step-problem":t.map(s=>s.code).join(" "),title:t.map(i.stepProblemTooltip).join(`
|
|
5
|
-
`)}}function
|
|
6
|
-
`);return e.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":s,title:s,style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:e.jsx(we.Icon,{name:"warning",size:12})})}function Bi(t){const s=i.useW6WApi(),o=t.uses.action,[n,r]=u.useState(null),c=t.uses.trigger===!0,l=t.uses.app;return u.useEffect(()=>{if(!c||!s.getAppTriggers)return;let f=!1;return s.getAppTriggers(l).then(d=>{var x;return!f&&r(((x=d.find(h=>h.key===o))==null?void 0:x.title)??null)}).catch(()=>{}),()=>{f=!0}},[s,l,o,c]),n||o}function Vi(t){const s=i.useW6WApi(),o=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,r=t.id,c=[...Ti(t.nodes),...(t.nodes??[]).filter(y=>{var C,M;return(((C=y.uses)==null?void 0:C.app)===i.WEBHOOK_APP||((M=y.uses)==null?void 0:M.app)===i.FORM_APP)&&y.uses.trigger!==!0})],l=c.length>0,f=c.map(y=>`${y.id}:${y.uses.app}:${y.uses.action}:${i.connectionIdFor(y,t.connections)??""}`).join("|"),[d,x]=u.useState([]),h=u.useMemo(()=>Ei(d),[d]),[m,k]=u.useState(0);u.useEffect(()=>{if(!o||!l){x([]);return}let y=!1;return o.call(s,r).then(C=>!y&&x(C)).catch(()=>{}),()=>{y=!0}},[s,o,r,l,f,m]);const j=u.useMemo(()=>n?async y=>{try{await n.call(s,y)}finally{k(C=>C+1)}}:void 0,[s,n]);return u.useMemo(()=>({byNode:h,subs:d,retry:j}),[h,d,j])}function zi({nodeId:t}){const{byNode:s,retry:o}=u.useContext(_n),[n,r]=u.useState(!1),c=s.get(t),l=ki(c,o!==void 0);return!c||!l?null:e.jsxs("div",{className:"w6w-small","data-trigger-registration":c.status,"data-tone":l.tone,style:{marginTop:3,paddingLeft:2},children:[e.jsx("span",{style:l.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:l.label}),e.jsxs("span",{className:"w6w-muted",children:[" · ",l.lastFire]}),l.error&&e.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:l.error}),l.retryVisible&&o&&e.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{r(!0),o(c.id).catch(()=>{}).finally(()=>r(!1))},children:"Retry"})]})}function Ui({id:t,data:s,selected:o}){const n=s.step,c=u.useContext(gs).get(n.uses.app),l=(c==null?void 0:c.displayName)||n.uses.app||"—",f=i.isTriggerStep(n.uses),d=Bi(n),x=n.uses.trigger?`${l} · ${d}`:l,h=i.nodePortsForStep(n,u.useContext(hs)),m=Mn(s.stepStatus??"no-run",s.runStatus),k=e.jsx(Un,{step:n,count:u.useContext(ms).get(t)??0}),j=Vn(t);return e.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:j,"data-disabled":We(n)||void 0,"data-paused":tt(n)||void 0,children:[e.jsx(zn,{id:t,step:n,runnable:!0}),e.jsxs("div",{className:f?"w6w-node-trigger":void 0,"data-node-kind":f?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Jn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${m.borderWidth}px ${m.borderStyle} ${o?"var(--w6w-accent)":m.borderColor}`,opacity:We(n)?.45:o?1:m.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...f?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[e.jsx(qn,{problems:s.stepProblems}),h.in>0&&e.jsx(He,{type:"target",position:le.Position.Left,multiple:h.in>1}),e.jsx(i.AppIcon,{src:c==null?void 0:c.iconSvg,srcDark:c==null?void 0:c.iconSvgDark,brandColor:c==null?void 0:c.brandColor,name:l,size:28}),e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontWeight:600},children:x}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:n.uses.action||"—"})})]}),h.out>0&&e.jsxs(e.Fragment,{children:[e.jsx(He,{type:"source",position:le.Position.Right,multiple:h.out>1}),!f&&e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),k,e.jsx(Hn,{step:n}),f&&n.uses.trigger===!0&&e.jsx(zi,{nodeId:t}),s.loopOf&&e.jsx(Bn,{id:t}),e.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,c!=null&&c.version?` - v${c.version}`:""]}),n.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Hi({id:t,data:s,selected:o}){const n=s.step,r=i.routesForStep(n),c=n.uses.app===i.ROUTER_APP,l=i.isIfStep(n),f=r.length?i.routerPortLayout(r):l?i.ifPortLayout():void 0,d=JSON.stringify(r.map(F=>F.id)),x=le.useUpdateNodeInternals();u.useEffect(()=>{x(t)},[t,d,x]);const h=i.internalNodeLabel(n.uses.app,n.uses.action),m=i.internalNodeIcon(n.uses.app,n.uses.action),k=i.nodePortsForStep(n,u.useContext(hs)),j=i.isTriggerStep(n.uses),y=Wi(n),C=Mn(s.stepStatus??"no-run",s.runStatus),M=e.jsx(Un,{step:n,count:u.useContext(ms).get(t)??0}),w=Vn(t);return e.jsxs("div",{className:[y?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:w,"data-disabled":We(n)||void 0,"data-paused":tt(n)||void 0,children:[e.jsx(zn,{id:t,step:n,runnable:!i.isControlApp(n.uses.app)}),e.jsxs("div",{className:j?"w6w-node-trigger":c?"w6w-node-router":void 0,"data-node-kind":j?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Jn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${C.borderWidth}px ${C.borderStyle} ${o?"var(--w6w-accent)":C.borderColor}`,opacity:We(n)?.45:o?1:C.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...j?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...f!=null&&f.minHeight?{minHeight:f.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[e.jsx(qn,{problems:s.stepProblems}),k.in>0&&e.jsx(He,{type:"target",position:le.Position.Left,multiple:k.in>1}),m&&e.jsx(i.InternalIcon,{icon:m}),e.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[e.jsx("div",{style:{fontWeight:600},children:h}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:n.uses.action||"—"})})]}),y&&e.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[e.jsx("span",{children:"Each item"}),e.jsx("span",{children:"Done"})]}),l&&(f==null?void 0:f.right[0])&&e.jsx("span",{className:"w6w-if-true-label w6w-small","aria-hidden":"true",children:f.right[0].label}),!l&&!!(f!=null&&f.right.length)&&e.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${f.right.length}, 1fr)`},"aria-hidden":"true",children:f.right.map(F=>e.jsx("span",{title:F.label,children:F.label},F.id))}),k.out>0&&e.jsxs(e.Fragment,{children:[y&&e.jsx(He,{type:"source",position:le.Position.Right,multiple:!1,id:i.EACH_SOURCE_HANDLE,variant:"each"}),f?e.jsxs(e.Fragment,{children:[f.right.map(F=>e.jsx(He,{type:"source",position:le.Position.Right,multiple:!1,id:F.handleId,top:F.top,routeLabel:F.label},F.id)),f.bottom&&e.jsxs(e.Fragment,{children:[e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:f.bottom.handleId,routeLabel:f.bottom.label}),e.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:f.bottom.label})]})]}):e.jsx(He,{type:"source",position:le.Position.Right,multiple:k.out>1,id:y?i.routeHandle(i.FOREACH_DONE_ROUTE):void 0}),!j&&!c&&!l&&n.uses.app!==i.RACE_APP&&e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),M,e.jsx(Hn,{step:n}),s.loopOf&&e.jsx(Bn,{id:t}),s.legacyLoop&&e.jsx("div",{className:"w6w-loop-legacy-note w6w-small",children:"This loop was converted from an older definition. Its steps after For each now run once per item; check the order, then save."}),e.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:n.id}),n.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Ji(t,s){var l,f;if(!s)return t;const o={...(t==null?void 0:t.steps)??{}};let n=!1;for(const[d,x]of Object.entries(s)){const h=/^nodes\.([^.]+)\.output$/.exec(d);!h||((l=o[h[1]])==null?void 0:l.output)!==void 0||(o[h[1]]={...o[h[1]]??{},output:x},n=!0)}const r=s["trigger.event"],c=r!==void 0&&((f=t==null?void 0:t.trigger)==null?void 0:f.event)===void 0;return!n&&!c?t:{...t??{},...n?{steps:o}:{},...c?{trigger:{...(t==null?void 0:t.trigger)??{},event:r}}:{}}}function qi(t){return e.jsx(Gi,{...t})}function Gi({workflowId:t,step:s,restoreVersion:o,upstreamSteps:n,loop:r,onChange:c,onClose:l,onCancel:f,readOnly:d,initialView:x="props",fanOutCount:h=0,stateOutputFields:m,onTestRun:k,stepProblems:j,otherStepIds:y}){var yt,St,ot,Me;const C=i.useW6WApi(),M=u.useContext(gs),[w,F]=u.useState(s),W=i.useWorkflowConnections(),O=i.connectionIdFor(w,W==null?void 0:W.connections),I={...w,uses:{...w.uses,connection:O}},E=w.uses.connectionRef!==void 0&&!O||i.isConnectionBlocked(I,j),V=j==null?void 0:j.find(T=>T.code==="unknown_connection"&&T.connection===O),K=(j??[]).filter(T=>"fix"in T),[S,g]=u.useState(E?"setup":"configure"),[P,Y]=u.useState(x==="json"?"code":x==="settings"?"config":"props"),[B,ne]=u.useState("props"),[Z,A]=u.useState(()=>i.stepToJson(s)),[X,D]=u.useState("{}"),z=u.useRef(null),[U,ie]=u.useState(!1),J=u.useRef(o);u.useEffect(()=>{J.current!==o&&(J.current=o,F(s),A(i.stepToJson(s)))},[o,s]);const[H,q]=u.useState(!1),[Q,fe]=u.useState(null),[Je,_e]=u.useState(null),[lt,Se]=u.useState(null),[qe,Ie]=u.useState(!1),ge=i.isInternalApp(w.uses.app),ce=w.uses.trigger===!0;u.useEffect(()=>{if(ge){fe(i.internalNodeParams(w.uses.app,w.uses.action));const te=i.INTERNAL_NODES.filter(ae=>ae.app===w.uses.app&&ae.groupActions&&!ae.hidden);_e(te.length?te.map(ae=>({key:ae.action,title:ae.label,params:ae.params})):null);return}if(!w.uses.app){_e(null),fe([]);return}let T=!1;return fe(null),(ce?i.getTriggerDefs(C,w.uses.app):C.getAppActions(w.uses.app)).then(te=>{var ae;T||(_e(te),fe(w.uses.action?((ae=te.find(je=>je.key===w.uses.action))==null?void 0:ae.params)??[]:[]))}).catch(()=>!T&&fe([])),()=>{T=!0}},[C,w.uses.app,w.uses.action,ge,ce]);const ke=u.useRef(0);u.useEffect(()=>()=>{ke.current++},[]);const Be=u.useCallback(()=>{ge||!w.uses.app||C.listConnectionsForApp(w.uses.app).then(T=>{Se(T),Ie(!1)}).catch(()=>Ie(!0))},[C,w.uses.app,ge]);u.useEffect(()=>{if(ge||!w.uses.app)return;let T=!1;return Se(null),Ie(!1),C.listConnectionsForApp(w.uses.app).then(te=>{T||(Se(te),Ie(!1))}).catch(()=>!T&&Ie(!0)),()=>{T=!0}},[C,w.uses.app,ge]);const oe=u.useCallback(T=>{F(T),c(T)},[c]),bt=Ho({enabled:w.uses.app===i.SCRIPT_APP&&!d,values:w.with??{},onChange:T=>oe({...w,with:T})}),de=T=>{T==="code"&&A(i.stepToJson(w)),Y(T)},Pe=T=>{const te=i.stepNameError(T,y??[]);return te||oe({...w,id:T}),te},Oe=!!w.uses.app&&!!w.uses.action&&!i.isControlApp(w.uses.app),Ee=i.isForeachStep(w),xe=i.isTriggerStep(w.uses),Ge=S==="test"&&Oe&&!xe,ye=i.useSeedSources(t,n,Oe&&!xe||Ee),Ve=On(Oe&&!xe?r:void 0),Re=i.useExpressionOptions(),Fe=i.startStateFromSeeds(ye,$n(Ve),(yt=Re.stateShape)==null?void 0:yt.written),ct=Ji(Fe,Re.sampleValues),Ne=i.useRememberedTestInput(Oe&&!xe||Ee?t:void 0,w.id),[be,$e]=u.useState(!1);u.useEffect(()=>{if((!Oe||xe)&&!Ee||!Ne.loaded)return;if(!Ee&&Ne.input!==void 0){const te=Ne.input;if(Object.keys(te).length===0)return;const ae=JSON.stringify(te,null,2);D(je=>je.trim()==="{}"?ae:je),$e(!0);return}let T=!1;return C.listStepTests(t,w.id).then(te=>{if(T)return;const ae=te.length?te[te.length-1]:null;if(!(ae!=null&&ae.input)||Object.keys(ae.input).length===0)return;const je=JSON.stringify(ae.input,null,2);D(Ye=>Ye.trim()==="{}"?je:Ye)}).catch(()=>{}),()=>{T=!0}},[C,t,w.id,Oe,xe,Ee,Ne.loaded]);const De=Ee?_i(X):Wt(X),Le={...w.with??{},...De??{}},dt=De??{},st=!!Q&&!bs(Ve)&&i.requiredParamsFilled(Q,Le)&&(w.uses.app!==i.CALL_APP||H),ee=Ee?i.resolveLoopItemsInState(Le.items,Fe):void 0,[nt,Ke]=u.useState("idle"),jt=T=>{D(T),Ke("idle")},ut=async()=>{if(ee){Ke("saving");try{await C.saveStepTest(t,w.id,i.foreachTestFixture(ee,dt)),Ke("saved")}catch{Ke("failed")}}},ue=M.get(w.uses.app),vt=ce?(St=Je==null?void 0:Je.find(T=>T.key===w.uses.action))==null?void 0:St.webhook:void 0,pt=ge?i.internalNodeIcon(w.uses.app,w.uses.action):null,Bt=ge?pt?e.jsx(i.InternalIcon,{icon:pt}):null:e.jsx(i.AppIcon,{src:ue==null?void 0:ue.iconSvg,srcDark:ue==null?void 0:ue.iconSvgDark,brandColor:ue==null?void 0:ue.brandColor,name:ue==null?void 0:ue.displayName});return e.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:Bt,title:e.jsx(i.StepNameEditor,{value:w.id,onCommit:Pe,readOnly:d}),onClose:f??l,size:"wide",children:e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsxs("div",{className:"w6w-tabsbar",children:[e.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].filter(T=>w.uses.app!==i.RACE_APP||T!=="test").map(T=>e.jsx("button",{type:"button",className:`w6w-subtab${S===T?" active":""}`,disabled:E&&T!=="setup",onClick:()=>g(T),children:T==="setup"?"Setup":T==="configure"?"Configure":"Test"},T))}),Ge?e.jsx(i.ConfigViewToggle,{view:B,views:["props","code"],onChange:T=>ne(T)}):e.jsx(i.ConfigViewToggle,{view:P,customized:i.hasParamCustomization(w.with??{}),onChange:de,disabled:S!=="configure"})]}),E&&V&&e.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",V.connection," no longer exists — choose another to continue."]}),K.length>0&&e.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:K.map(T=>e.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("span",{children:i.stepProblemTooltip(T)}),e.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":T.code,disabled:d,onClick:()=>{const te=Ln(w,T);oe(te),A(i.stepToJson(te))},children:"fix"in T?T.fix.label:""})]},T.code))}),e.jsxs("div",{className:"w6w-stepconfig-body",children:[S==="setup"&&w.uses.app===i.CALL_APP&&e.jsx(i.CallTargetForm,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d,onValidityChange:q,setupOnly:!0}),S==="setup"&&w.uses.app!==i.CALL_APP&&e.jsx(Xi,{step:w,app:ue,actions:Je,conns:lt,connsFailed:qe,isInternal:ge,actionLabel:ce?"Trigger":"Action",readOnly:d,onChangeAction:T=>{var ae;const te=ge?i.internalNodeDefaults(w.uses.app,T):{};if(ge)for(const je of i.internalNodeParams(w.uses.app,T))je.key in(w.with??{})&&(te[je.key]=(ae=w.with)==null?void 0:ae[je.key]);oe({...w,uses:{...w.uses,action:T},with:te})},onChangeTriggerEvents:(T,te)=>oe({...w,uses:{...w.uses,action:T},with:{...w.with,actions:te}}),onChangeConnection:T=>{if(!W){const{connectionRef:ae,...je}=w.uses;oe({...w,uses:{...je,connection:T}});return}const te=i.selectNodeConnection(w,T,(W==null?void 0:W.nodes)??[w],(W==null?void 0:W.connections)??{});W==null||W.setConnections(te.connections),oe(te.step)},onChangeConnectionRef:T=>oe(i.withConnectionRef(w,T)),onConnectionCreated:Be,onChangeApp:T=>{const te=++ke.current;if(T===w.uses.app){oe(w);return}const ae={...w,uses:{app:T,action:"",...ce?{trigger:!0}:{}},with:{}};(i.isInternalApp(T)?Promise.resolve([]):C.listConnectionsForApp(T)).catch(()=>[]).then(je=>{if(te!==ke.current)return;const Ye=i.defaultConnectionFor(ae,je,(W==null?void 0:W.nodes)??[],(W==null?void 0:W.connections)??{});oe({...ae,uses:{...ae.uses,...Ye}})})}}),S==="configure"&&e.jsxs(e.Fragment,{children:[(w.uses.app===i.WEBHOOK_APP||w.uses.app===i.FORM_APP)&&C.listSubscriptionsForWorkflow&&C.createSubscription&&e.jsx(Yi,{workflowId:t,step:w,readOnly:d}),ce&&vt&&w.uses.action&&C.listSubscriptionsForWorkflow&&e.jsx(Ro,{workflowId:t,nodeId:w.id,appId:w.uses.app,triggerKey:w.uses.action,appName:(ue==null?void 0:ue.displayName)??w.uses.app,setup:vt,connectionId:O&&!O.startsWith("zerocred:")?O:null,params:w.with??{},readOnly:d}),Q===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):P==="props"?w.uses.app===i.CALL_APP?e.jsx(i.CallTargetForm,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d,onValidityChange:q}):w.uses.app===i.RACE_APP?e.jsx("p",{className:"w6w-muted w6w-small",children:i.RACE_DESCRIPTION}):w.uses.action==="wait"&&i.isControlApp(w.uses.app)?e.jsx(i.WaitEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.action==="if"&&i.isControlApp(w.uses.app)?e.jsx(i.ConditionEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app==="@w6w/stop"?e.jsx(i.StopEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app===i.ROUTER_APP?e.jsx(i.RouterEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app===i.FORM_APP?e.jsxs("div",{className:"w6w-stack",children:[e.jsx(xo,{value:(ot=w.with)==null?void 0:ot.form,readOnly:d,stepId:w.id,onChange:T=>oe({...w,with:{...w.with,form:T}})}),e.jsx(i.ParamsForm,{params:Q.filter(T=>T.key!=="form"),values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})})]}):e.jsxs(e.Fragment,{children:[w.uses.app===i.SCRIPT_APP&&e.jsx(Jo,{values:w.with??{},conversion:bt,readOnly:d}),e.jsx(i.ParamsForm,{params:Q,values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T}),dynamic:ge||!w.uses.action?void 0:{appId:w.uses.app,actionKey:w.uses.action,kind:i.isTriggerStep(w.uses)?"trigger":"action",connectionId:E?void 0:O,appName:ue==null?void 0:ue.displayName}})]}):P==="code"?e.jsx(i.JsonEditor,{value:Z,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${w.id} JSON`,copyable:!0}):P==="params-code"?e.jsx(i.ParamCustomization,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d}):e.jsxs("div",{className:"w6w-stack",children:[e.jsx(i.NodeConfigForm,{config:{retry:w.retry,onError:w.onError,notes:w.notes},onChange:T=>oe({...w,...T}),readOnly:d,failureHandling:!xe,retryControls:!i.isControlApp(w.uses.app)&&w.uses.app!==i.CALL_APP}),Ki,e.jsx(i.StepFanOutControl,{step:w,count:h,readOnly:d,onChange:oe}),i.stateWriteVisible(w)&&e.jsx(i.StepStateControl,{step:w,inLoop:r!==void 0,outputFields:m,readOnly:d,onChange:oe})]})]}),S==="test"&&e.jsx("div",{className:"w6w-stack",children:Oe?xe?e.jsx(i.TriggerFillForm,{app:w.uses.app,action:w.uses.action,fields:ce||(Me=w.with)==null?void 0:Me.fields,appTrigger:ce,persist:{workflowId:t,stepId:w.id,input:dt},listen:(w.uses.app===i.WEBHOOK_APP||w.uses.app===i.FORM_APP)&&C.listSubscriptionsForWorkflow&&C.startWebhookListen?{stepWith:w.with,readOnly:d,appId:w.uses.app}:void 0}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",e.jsx("code",{children:w.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),e.jsx(Wn,{seed:Ve,readOnly:d}),be&&!d&&e.jsx(i.LastUsedNote,{onClear:()=>{Ne.clear(),$e(!1),D("{}")}}),e.jsx(ds,{text:X,onChange:D,seeds:ye,readOnly:d}),Q===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):e.jsx(Wo,{params:Q,values:Le,testStartState:ct,view:B,literalKeys:w.uses.app===i.SCRIPT_APP?Mi:void 0}),e.jsx(i.StepTestRun,{ref:z,app:w.uses.app,action:w.uses.action,connectionId:O,values:Le,state:Fe,canRun:st,hideRunButton:!0,persist:{workflowId:t,stepId:w.id,input:dt},onBusyChange:ie})]}):Ee?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Resolves ",e.jsx("strong",{children:"Items"})," against the incoming state — nothing inside the loop runs. ",e.jsx("strong",{children:"Test"})," saves the first item as this loop's sample, so the steps on its ",e.jsx("strong",{children:"Each item"})," output can pick its keys. To run the loop's work, test a step on ",e.jsx("strong",{children:"Each item"}),": it runs once, on one item."]}),e.jsx(ds,{text:X,onChange:jt,seeds:ye,readOnly:d,expand:!ee,hint:e.jsxs(e.Fragment,{children:["Paste a sample list — ",e.jsx("code",{children:'[{"id": 1, "name": "…"}]'})," — or"," ",e.jsx("code",{children:'{"items": […]}'}),". It replaces what ",e.jsx("strong",{children:"Items"})," ","resolves to, for this test only."]})}),e.jsx(Oi,{items:ee,save:nt})]}):e.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),e.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[f&&!d&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:f,children:"Cancel"}),w.uses.app===i.RACE_APP&&S==="configure"?e.jsx("button",{type:"button",className:"w6w-btn",onClick:l,children:"Done"}):S!=="test"?e.jsxs(e.Fragment,{children:[f&&!d&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:E,onClick:()=>g(S==="setup"?"configure":"test"),children:"Next →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),Oe&&!xe&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:d||!st||U,onClick:()=>{var T;k==null||k(),(T=z.current)==null||T.run()},children:U?"Testing…":"Test"}),Ee&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:d||!(ee!=null&&ee.length)||nt==="saving",onClick:()=>void ut(),children:nt==="saving"?"Testing…":"Test"})]})]})]})})}const Ki=!1;function Yi({workflowId:t,step:s,readOnly:o}){const n=i.useW6WApi(),r=s.uses.app===i.FORM_APP,[c,l]=u.useState(void 0),[f,d]=u.useState(null),[x,h]=u.useState(!1),m=(c==null?void 0:c.webhookUrl)??(c==null?void 0:c.formUrl);u.useEffect(()=>{const j=n.listSubscriptionsForWorkflow;if(!j)return;let y=!1;return j(t).then(C=>{y||l(r?i.pickFormSubscription(C,s.id):i.pickWebhookSubscription(C,s.id))}).catch(C=>!y&&d(C.message)),()=>{y=!0}},[n,t,s.id,r]);const k=()=>{const j=n.createSubscription;j&&(d(null),h(!0),j(r?i.FORM_APP:i.WEBHOOK_APP,s.uses.action,{workflowId:t,connectionId:null,params:r?{node:s.id}:s.with??{}}).then(y=>{h(!1),l(y)}).catch(y=>{h(!1),d(y instanceof Error?y.message:String(y))}))};return e.jsxs("div",{className:"w6w-stack w6w-url-panel",children:[e.jsx("p",{className:"w6w-muted w6w-small",children:r?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Form URL"})," — share it, or embed it in an iframe. Each submission starts the workflow once it is published."]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]})}),f&&e.jsx("div",{className:"w6w-result w6w-error",children:f}),m?e.jsxs("div",{className:"w6w-listen-url",children:[e.jsx(we.Copyable,{value:m,readOnly:!0,children:e.jsx("input",{type:"text",readOnly:!0,value:m,"aria-label":r?"Form URL":"Webhook URL"})}),r&&e.jsx("a",{className:"w6w-btn w6w-btn-ghost w6w-btn-sm",href:m,target:"_blank",rel:"noreferrer",children:"Open form"})]}):c===void 0?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!o&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:x,onClick:k,children:x?"Creating…":r?"Create form URL":"Create webhook URL"})]})}function Xi({step:t,app:s,actions:o,conns:n,connsFailed:r,isInternal:c,actionLabel:l="Action",readOnly:f,onChangeAction:d,onChangeTriggerEvents:x,onChangeConnection:h,onChangeConnectionRef:m,onChangeApp:k,onConnectionCreated:j}){const y=t.uses.trigger?i.eventbriteTriggerChoices(t.uses.app,o,t.uses.action,t.with??{}):null,[C,M]=u.useState(null),w=u.useRef(null),F=i.useWorkflowConnections(),W=i.connectionIdFor(t,F==null?void 0:F.connections);return e.jsxs("div",{className:"w6w-stack",children:[t.uses.connectionRef&&!W&&e.jsx("p",{role:"alert",className:"w6w-field-error",children:"The shared connection is missing or unbound. Choose an account."}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"App"}),e.jsxs("div",{className:"w6w-app-conn-row",ref:w,children:[e.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":C==="app",disabled:f,onClick:()=>M(O=>O==="app"?null:"app"),children:[!c&&s&&e.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),e.jsx("span",{className:"w6w-conn-label-name",children:c?t.uses.app:(s==null?void 0:s.displayName)??t.uses.app})]}),!c&&e.jsx(i.WorkflowConnectionPicker,{step:t,conns:n,failed:r,readOnly:f,open:C==="conn",onOpenChange:O=>M(O?"conn":null),anchorRef:w,onChangeConnection:h,onChangeConnectionRef:m,onConnectionCreated:j})]}),C==="app"&&e.jsx(i.AnchoredFlyout,{anchorRef:w,onClose:()=>M(null),children:e.jsx(i.AppPicker,{onSelectApp:O=>{const I=O.id===t.uses.app;k(O.id),M(I?"conn":null)}})})]}),c&&!(o!=null&&o.length)?e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Action"}),e.jsx("div",{className:"w6w-muted w6w-small",children:e.jsx("code",{children:t.uses.action})})]}):y?e.jsx(i.EventbriteTriggerPicker,{choices:y,readOnly:f,onChange:O=>x(y.triggerKey,O)}):e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:l}),e.jsx(i.Combobox,{value:t.uses.action,disabled:f||o===null,onChange:d,options:o===null?[{value:t.uses.action,label:t.uses.action}]:o.map(O=>({value:O.key,label:O.title??O.key}))})]})]})}function Sn({trigger:t}){return e.jsx("span",{className:"w6w-connection-node-kind",role:"img","aria-label":t?"Trigger":"Node",children:e.jsx("svg",{"aria-hidden":"true",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t?e.jsx("path",{d:"M13 2 4 14h7l-1 8 10-12h-7l1-8Z"}):e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"}),e.jsx("path",{d:"M2 12h3m14 0h3"})]})})})}function Zi({resources:t}){const s=i.useW6WApi(),o=t.highlightNode;u.useEffect(()=>()=>o==null?void 0:o(null),[o]);const[n,r]=u.useState([]),[c,l]=u.useState(!0),[f,d]=u.useState(),[x,h]=u.useState(),[m,k]=u.useState(null),[j,y]=u.useState(!1),[C,M]=u.useState(!1),w=u.useRef(0),F=u.useCallback(async()=>{const D=++w.current;l(!0),d(void 0);try{const z=await s.listConnections();return D!==w.current?void 0:(r(z),z)}catch(z){D===w.current&&d(z.message)}finally{D===w.current&&l(!1)}},[s]);u.useEffect(()=>(F(),()=>{w.current++}),[F]);const[W,O]=u.useState(new Map),I=JSON.stringify([...new Set([...Object.values(t.connections).map(D=>D.app),...n.map(D=>D.appId)])].filter(D=>{var z;return!((z=t.apps)!=null&&z.has(D))&&!n.some(U=>U.appId===D&&U.app!==void 0)}).sort());u.useEffect(()=>{var J,H;let D=!1;const z=JSON.parse(I);if(c||!z.length)return;const U=(J=s.listAppsByIds)==null?void 0:J.bind(s),ie=U?Promise.all(Array.from({length:Math.ceil(z.length/50)},(q,Q)=>U(z.slice(Q*50,(Q+1)*50)))).then(q=>q.flat()):(H=s.listApps)==null?void 0:H.call(s);return ie==null||ie.then(q=>{D||O(new Map(q.map(Q=>[Q.id,Q])))}).catch(()=>{}),()=>{D=!0}},[s,I,c]);const R=D=>{var J;const z=n.find(H=>H.appId===D&&H.app)??n.find(H=>H.appId===D&&H.app!==void 0),U=z?i.resolveConnectionAppMeta(z,W):W.get(D),ie=(J=t.apps)==null?void 0:J.get(D);return ie?{...U,...ie}:U},E=D=>{var z;return((z=R(D))==null?void 0:z.displayName)||D},V=D=>{if(t.readOnly)return!1;try{return t.edit(D),h(void 0),!0}catch(z){return h(z.message),!1}},K=D=>i.nextWorkflowConnectionName(D.appId,t.connections),S=()=>{k(null),h(void 0),y(!1)},g=m!=null&&m.ref?t.connections[m.ref]:void 0,P=n.find(D=>D.id===(m==null?void 0:m.connection)),Y=(g==null?void 0:g.app)??(P==null?void 0:P.appId),B=t.nodes.filter(D=>D.uses.app===Y),ne=t.nodes.filter(D=>(m==null?void 0:m.ref)!==void 0&&D.uses.connectionRef===m.ref),Z=n.filter(D=>!g||D.appId===g.app).map(D=>({value:D.id,label:g?D.displayName||D.id:`${E(D.appId)} · ${D.displayName||D.id}`}));m!=null&&m.connection&&!Z.some(D=>D.value===m.connection)&&Z.unshift({value:m.connection,label:m.connection.startsWith("zerocred:")?"Built-in":m.connection});const A=(D,z=28)=>{const U=R(D);return e.jsx(i.AppIcon,{src:U==null?void 0:U.iconSvg,srcDark:U==null?void 0:U.iconSvgDark,brandColor:U==null?void 0:U.brandColor,name:E(D),size:z})},X=()=>{if(!m||!m.name.trim()||!m.connection||!Y)return;const D=m.ref!==void 0?{type:"update",ref:m.ref,name:m.name,connection:m.connection,nodeIds:m.allNodes?B.map(z=>z.id):void 0}:{type:"add",name:m.name,app:Y,connection:m.connection};V(D)&&S()};return e.jsxs("div",{className:"w6w-stack","data-testid":"workflow-connections-panel",children:[e.jsxs("div",{className:"w6w-workflow-connections-heading",children:[e.jsx("h3",{children:"Connections"}),e.jsx(i.IconButton,{label:"Add connection",disabled:t.readOnly,onClick:()=>{h(void 0),k({name:"",connection:"",allNodes:!1})},children:e.jsx("svg",{"aria-hidden":"true",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),f&&e.jsxs("div",{role:"alert",className:"w6w-stack",children:[e.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",f]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void F(),children:"Retry"})]}),Object.entries(t.connections).map(([D,z])=>{var H;const U=t.nodes.filter(q=>q.uses.connectionRef===D),ie=n.find(q=>q.id===z.connection),J=(ie==null?void 0:ie.displayName)||((H=z.connection)!=null&&H.startsWith("zerocred:")?"Built-in":z.connection)||"No credentials selected";return e.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":D,children:[e.jsxs("div",{className:"w6w-connection-app-heading",children:[A(z.app),e.jsxs("div",{className:"w6w-connection-summary",children:[e.jsx("strong",{children:E(z.app)}),e.jsx("span",{className:"w6w-small",children:J}),e.jsxs("span",{className:"w6w-muted w6w-small",children:[D,ie!=null&&ie.state?` · ${ie.state}`:""]})]}),e.jsx(i.IconButton,{icon:"edit",label:`Edit connection ${D}`,disabled:t.readOnly,onClick:()=>{h(void 0),k({ref:D,name:D,connection:z.connection??"",allNodes:!1})}})]}),U.length>0?e.jsxs("details",{className:"w6w-connection-consumers",onToggle:q=>{q.currentTarget.open||o==null||o(null)},children:[e.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",U.length," ",U.length===1?"node":"nodes"]}),e.jsx("ul",{className:"w6w-connection-node-list",children:U.map(q=>e.jsx("li",{children:t.focusNode?e.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${q.id} on canvas`,onClick:()=>{var Q;return(Q=t.focusNode)==null?void 0:Q.call(t,q.id)},onMouseEnter:()=>o==null?void 0:o(q.id),onMouseLeave:()=>o==null?void 0:o(null),onFocus:()=>o==null?void 0:o(q.id),onBlur:()=>o==null?void 0:o(null),children:[e.jsx(Sn,{trigger:i.isTriggerStep(q.uses)}),e.jsxs("span",{className:"w6w-connection-node-label",children:[e.jsx("strong",{children:q.uses.action}),e.jsx("span",{className:"w6w-muted w6w-small",children:q.id})]})]}):e.jsxs("span",{className:"w6w-connection-app-heading",children:[e.jsx(Sn,{trigger:i.isTriggerStep(q.uses)}),e.jsxs("span",{className:"w6w-connection-node-label",children:[e.jsx("strong",{children:q.uses.action}),e.jsx("span",{className:"w6w-muted w6w-small",children:q.id})]})]})},q.id))})]}):e.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},D)}),!Object.keys(t.connections).length&&e.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),m&&!C&&!j&&e.jsxs(i.Modal,{title:m.ref!==void 0?"Edit connection":"Add connection",titleIcon:Y?A(Y):void 0,subtitle:Y?E(Y):void 0,onClose:S,children:[e.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[x&&e.jsx("p",{role:"alert",className:"w6w-field-error",children:x}),f&&e.jsxs("div",{role:"alert",className:"w6w-stack",children:[e.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",f]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void F(),children:"Retry"})]}),m.ref!==void 0&&!g&&e.jsx("p",{role:"alert",children:"This workflow connection no longer exists."}),e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:"Workflow connection name"}),e.jsx("input",{className:"w6w-input","aria-label":"Workflow connection name",value:m.name,disabled:t.readOnly,onChange:D=>k({...m,name:D.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:g?"Credentials":"Existing connection"}),e.jsx(i.Combobox,{"aria-label":g?"Credentials":"Connection to add",options:Z,value:m.connection,placeholder:c?"Loading connections…":"Choose a connection…",disabled:t.readOnly||c||!!f,onChange:D=>{const z=n.find(U=>U.id===D);k({...m,connection:D,name:!m.name&&z?K(z):m.name})}})]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:t.readOnly,onClick:()=>M(!0),children:"Create new credentials"}),g&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"w6w-muted w6w-small",children:m.allNodes?`Saving applies these credentials to all ${B.length} ${E(g.app)} nodes.`:`Saving updates credentials for ${ne.length} linked ${ne.length===1?"node":"nodes"}.`}),B.length>0&&e.jsxs("label",{className:"w6w-connection-scope",children:[e.jsx("input",{type:"checkbox",checked:m.allNodes||B.every(D=>D.uses.connectionRef===m.ref),disabled:t.readOnly||B.every(D=>D.uses.connectionRef===m.ref),onChange:D=>k({...m,allNodes:D.target.checked})}),"Use for all ",B.length," ",E(g.app)," ",B.length===1?"node":"nodes"," in this workflow"]}),e.jsxs("div",{className:"w6w-connection-remove",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:t.readOnly||ne.length>0,onClick:()=>y(!0),children:"Remove from workflow"}),ne.length>0&&e.jsx("p",{className:"w6w-muted w6w-small",children:"Assign another connection to the linked nodes before removing this one."})]})]})]}),e.jsxs("div",{className:"w6w-modal-actions",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:S,children:"Cancel"}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:t.readOnly||c||!!f||!m.name.trim()||!m.connection||!Y||m.ref!==void 0&&!g,onClick:X,children:m.ref!==void 0?"Save changes":"Add to workflow"})]})]}),m&&j&&e.jsx(i.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${m.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>y(!1),onConfirm:()=>{m.ref&&V({type:"remove",ref:m.ref})?S():y(!1)}}),m&&C&&e.jsx(i.AddConnectionModal,{initialAppId:g==null?void 0:g.app,onClose:()=>M(!1),onCreated:({connectionId:D})=>{M(!1),F().then(z=>{const U=z==null?void 0:z.find(ie=>ie.id===D);U&&k(ie=>ie?{...ie,connection:U.id,name:ie.name||K(U)}:null)})}})]})}exports.CALL_APP=i.CALL_APP;exports.CONTROL_APP=i.CONTROL_APP;exports.CanvasLayer=i.CanvasLayer;exports.DATA_APP=i.DATA_APP;exports.ExpressionOptionsProvider=i.ExpressionOptionsProvider;exports.INTERNAL_NODES=i.INTERNAL_NODES;exports.Markdown=i.Markdown;exports.RACE_APP=i.RACE_APP;exports.SCHEDULER_APP=i.SCHEDULER_APP;exports.SCRIPT_APP=i.SCRIPT_APP;exports.TRIGGER_APP=i.TRIGGER_APP;exports.WEBHOOK_APP=i.WEBHOOK_APP;exports.asFieldDefs=i.asFieldDefs;exports.centralizeConnections=i.centralizeConnections;exports.coerceDefault=i.coerceDefault;exports.connectionIdFor=i.connectionIdFor;exports.fieldWidget=i.fieldWidget;exports.fieldsToParams=i.fieldsToParams;exports.flowToWorkflow=i.flowToWorkflow;exports.internalNodeDefaults=i.internalNodeDefaults;exports.internalNodeIcon=i.internalNodeIcon;exports.internalNodeLabel=i.internalNodeLabel;exports.internalNodeParams=i.internalNodeParams;exports.isControlApp=i.isControlApp;exports.isInternalApp=i.isInternalApp;exports.isTriggerApp=i.isTriggerApp;exports.isTriggerStep=i.isTriggerStep;exports.seedValues=i.seedValues;exports.workflowToFlow=i.workflowToFlow;exports.MAX_NOTES=Nn;exports.MAX_NOTE_BYTES=kn;exports.MAX_SECTIONS=Cn;exports.WorkflowConnectionsPanel=Zi;exports.WorkflowFlowEditor=Di;exports.applyStepProblemFix=Ln;exports.assignMembership=is;exports.clampCanvas=rs;exports.findLoopProblems=ci;exports.findStateWriteProblems=pi;exports.isDisabledStep=We;exports.isPausedStep=tt;exports.pausedStopAt=ls;exports.pruneSectionMembers=us;exports.renameSectionMember=os;exports.roundGeometry=ns;exports.sectionsContaining=Tn;exports.withCanvasGeometry=En;exports.withDisabled=Fn;exports.withPaused=Rn;
|
|
6
|
+
`)})})]})]}),e.jsx("div",{className:"w6w-modal-actions",children:e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>w(null),children:"Close"})})]})]}),Pe!==null&&e.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:Yo(Pe,g,A),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{Yn(Pe),Fe(null)},onClose:()=>Fe(null)}),xe&&e.jsx(bo,{x:xe.x,y:xe.y,items:Mo(xe.nodeIds,!!n,{replaceableTrigger:xe.nodeIds.length===1&&g.some(a=>a.id===xe.nodeIds[0]&&i.isTriggerStep(a.data.step.uses))}),onAction:mo,onClose:ho})]})})})})})})})});return e.jsx(i.WorkflowConnectionsContext.Provider,{value:{nodes:g.map(a=>a.data.step),connections:O,setConnections:E,readOnly:n},children:wo})}const Oi=["code"];function Wt(t){try{const s=JSON.parse(t);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function $i(t){try{const s=JSON.parse(t);if(Array.isArray(s))return{items:s}}catch{return null}return Wt(t)}function Wi({items:t,save:s}){if(!t)return e.jsxs("output",{className:"w6w-small",style:{display:"block"},children:[e.jsx("strong",{children:"Items"})," doesn't resolve to a list yet: no step before this one has a saved test that produces it. Test an earlier step, or paste a sample list under"," ",e.jsx("strong",{children:"Override the incoming state"})," below."]});const o=t[0],n=o!==void 0?(i.inferOutputFields(o)??[]).map(r=>r.key):[];return e.jsxs("div",{className:"w6w-testout",children:[e.jsxs("div",{className:"w6w-testout-label",children:[t.length," ",t.length===1?"item":"items"]}),t.length===0?e.jsx("p",{className:"w6w-muted w6w-small",children:"The list is empty, so there is no item to sample."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w6w-testout-label",children:"First item"}),e.jsx(i.ResultViewer,{value:o,maxHeight:220})]}),s==="saved"&&e.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",n.length>0&&e.jsxs(e.Fragment,{children:[" ","Steps on ",e.jsx("strong",{children:"Each item"})," now offer ",e.jsx("strong",{children:"Current item"})," ›"," ",n.map((r,c)=>e.jsxs("span",{children:[c>0&&", ",e.jsx("code",{children:r})]},r)),"."]})]}),s==="failed"&&e.jsx("p",{className:"w6w-small",role:"alert",children:"Couldn't save the sample. Try Test again."})]})}function Wn(t){const[s,o]=u.useState(null),[n,r]=u.useState("0"),[c,l]=u.useState({}),[f,d]=u.useState({}),x=s??i.loopItemText(t),h=((t==null?void 0:t.outer)??[]).map(j=>({foreachId:j.foreachId,name:j.name??j.foreachId,itemText:c[j.foreachId]??i.loopItemText(j),indexText:f[j.foreachId]??"0",setItemText:y=>l(C=>({...C,[j.foreachId]:y})),setIndexText:y=>d(C=>({...C,[j.foreachId]:y}))})),m=t?i.parseLoopSeed(x,n):void 0;let k=m!=null&&m.ok?{ok:!0,value:m.value}:m;if(t&&(m!=null&&m.ok)){const j={};for(const y of h){const C=i.parseLoopSeed(y.itemText,y.indexText);if(!C.ok){k={ok:!1,error:`${y.name}: ${C.error}`};break}j[y.foreachId]=C.value}k!=null&&k.ok&&(j[t.foreachId]=m.value,k={ok:!0,value:{...m.value,loops:j}})}return{active:!!t,itemText:x,indexText:n,setItemText:o,setIndexText:r,outers:h,parsed:k}}function Bn(t){var s;return(s=t.parsed)!=null&&s.ok?t.parsed.value:void 0}function bs(t){return t.parsed&&!t.parsed.ok?t.parsed.error:null}function Vn({seed:t,readOnly:s}){if(!t.active)return null;const o=bs(t);return e.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[t.outers.map(n=>e.jsxs("div",{"data-testid":`loop-seed-outer-${n.foreachId}`,children:[e.jsxs("span",{children:[n.name," item"]}),e.jsx("textarea",{rows:3,value:n.itemText,readOnly:s,spellCheck:!1,"aria-label":`${n.name} item`,onChange:r=>n.setItemText(r.target.value)}),e.jsxs("span",{children:[n.name," index"]}),e.jsx("input",{type:"text",inputMode:"numeric",value:n.indexText,readOnly:s,"aria-label":`${n.name} index`,onChange:r=>n.setIndexText(r.target.value)})]},n.foreachId)),e.jsx("span",{children:"Current item"}),e.jsx("textarea",{rows:3,value:t.itemText,readOnly:s,spellCheck:!1,"aria-label":"Current item",onChange:n=>t.setItemText(n.target.value)}),e.jsx("span",{children:"Index"}),e.jsx("input",{type:"text",inputMode:"numeric",value:t.indexText,readOnly:s,"aria-label":"Index",onChange:n=>t.setIndexText(n.target.value)}),e.jsx("span",{className:"w6w-hint",children:"This step runs once per item of the For each. Test it as one iteration — starting from the sample item, or edit it."}),o&&e.jsx("span",{className:"w6w-hint",role:"alert",children:o})]})}function ds({text:t,onChange:s,seeds:o,readOnly:n,expand:r,hint:c}){const l=Wt(t),f=l?Object.keys(l).length:0,d=f>0,[x,h]=u.useState(d);u.useEffect(()=>{(d||r)&&h(!0)},[d,r]);const m=k=>{s(JSON.stringify(k.lastRunOutput??k.input??{},null,2)),h(!0)};return e.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[e.jsx("span",{children:"Incoming state"}),o.length>0&&e.jsx("div",{className:"w6w-seed-picker",children:e.jsx("div",{className:"w6w-seed-chips",children:o.map(k=>e.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${k.label}'s saved test as the incoming state`,disabled:n,onClick:()=>m(k.test),children:[e.jsx("code",{children:k.label}),k.test.lastRunStatus?e.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",k.test.lastRunStatus]}):null]},k.stepId))})}),e.jsxs("details",{className:"w6w-state-override",open:x,onToggle:k=>h(k.currentTarget.open),children:[e.jsxs("summary",{children:["Override the incoming state",f>0?` · ${f} key${f===1?"":"s"} set`:""]}),e.jsx("textarea",{rows:3,value:t,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:k=>s(k.target.value)}),e.jsx("span",{className:"w6w-hint",children:c??e.jsxs(e.Fragment,{children:["JSON whose keys replace this step's parameters by name, for this test only — so a script's data goes under ",e.jsx("code",{children:"input"}),": ",e.jsx("code",{children:'{"input": {…}}'}),". Upstream outputs already reach ",e.jsx("code",{children:"{{ nodes.<id>.output }}"})," bindings from their saved tests. Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})})]})]})}function Bi({workflowId:t,step:s,upstreamSteps:o,loop:n,onRun:r,onCancel:c,continues:l}){var J;const f=i.useW6WApi(),d=i.isTriggerStep(s.uses),x=i.isInternalApp(s.uses.app),h=u.useMemo(()=>{var H;return d?i.asFieldDefs((H=s.with)==null?void 0:H.fields):[]},[d,s.with]),m=u.useMemo(()=>d?i.fieldsToParams(h):x?i.internalNodeParams(s.uses.app,s.uses.action):null,[d,x,h,s.uses.app,s.uses.action]),[k,j]=u.useState(null),y=m??k;u.useEffect(()=>{if(m)return;if(!s.uses.app||!s.uses.action){j([]);return}let H=!1;return j(null),f.getAppActions(s.uses.app).then(q=>{var Q;H||j(((Q=q.find(fe=>fe.key===s.uses.action))==null?void 0:Q.params)??[])}).catch(()=>!H&&j([])),()=>{H=!0}},[f,m,s.uses.app,s.uses.action]);const[C,M]=u.useState(()=>{var H;return d?i.seedValues(i.asFieldDefs((H=s.with)==null?void 0:H.fields)):{}}),[w,F]=u.useState("{}"),W=i.useSeedSources(t,o,!d),O=Wn(n),I=(J=i.useExpressionOptions().stateShape)==null?void 0:J.written,P=i.startStateFromSeeds(W,Bn(O),I),E=i.useRememberedTestInput(t,s.id),[V,K]=u.useState(!1),[S,g]=u.useState(!1);u.useEffect(()=>{if(!E.loaded)return;let H=!1;const q=(Q,fe)=>{Q&&Object.keys(Q).length>0&&(d?M(Je=>({...Je,...Q})):F(JSON.stringify(Q,null,2)),fe&&g(!0)),K(!0)};if(E.input!==void 0){q(E.input,!0);return}return f.listStepTests(t,s.id).then(Q=>{if(H)return;const fe=Q.length?Q[Q.length-1]:null;q(d?fe==null?void 0:fe.with:fe==null?void 0:fe.input,!1)}).catch(()=>{H||K(!0)}),()=>{H=!0}},[f,t,s.id,d,E.loaded]);const[R,Y]=u.useState(0),B=()=>{E.clear(),g(!1),d?M(i.seedValues(h)):F("{}"),Y(H=>H+1)},ne=H=>{M(H),A(!0),g(!1),Y(q=>q+1)},[Z,A]=u.useState(!0),X=Wt(w),L=d?Z:X!==null,z=d?C:{...s.with??{},...X??{}},U=d?null:bs(O),ie=!!y&&V&&L&&!U&&i.requiredParamsFilled(y,z);return e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsx("div",{className:"w6w-modal-body",children:e.jsxs("div",{className:"w6w-stack",children:[l&&e.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"run-from-node-hint",children:["Runs this node, then continues through every node after it",l.stopAt.length>0?e.jsxs(e.Fragment,{children:[" ","and stops before"," ",l.stopAt.length===1?"the paused node":"paused nodes"," ",l.stopAt.map((H,q)=>e.jsxs("span",{children:[q>0?", ":"",e.jsx("code",{children:H})]},H))]}):null,". Disabled nodes are skipped."]}),S&&y!==null&&V&&e.jsx(i.LastUsedNote,{onClear:B}),y===null||!V?e.jsx("p",{className:"w6w-muted w6w-small",children:y===null?"Loading parameters…":"Loading saved values…"}):d?e.jsxs(e.Fragment,{children:[e.jsx(i.PropertyEntryForm,{params:y,values:C,onChange:M,onValidityChange:A},R),s.uses.trigger===!0&&e.jsx(i.TriggerSampleButton,{app:s.uses.app,trigger:s.uses.action,onUse:ne}),y.length===0&&e.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",e.jsx("code",{children:"input"}),")."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",e.jsx("code",{children:s.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),e.jsx(Vn,{seed:O}),e.jsx(ds,{text:w,onChange:F,seeds:W})]})]})}),e.jsxs("div",{className:"w6w-modal-actions",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Cancel"}),!ie&&y!==null&&V&&e.jsx("span",{className:"w6w-muted w6w-small",children:U?`${U} Fix it to run.`:L?d?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":d?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:!ie,onClick:()=>{E.save(d?C:X??{},y??[]),r(d?C:X??{},d?void 0:P)},children:"▶ Run"})]})]})}function Vi(t){return t.uses.app===i.CONTROL_APP&&t.uses.action==="foreach"}function zn({id:t}){const{tones:s,loopOf:o}=u.useContext(ws),n=Fn(t,o);return n.length===0?null:e.jsx("span",{className:"w6w-loop-dots",children:n.map(r=>e.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${r}`,title:`In loop · ${r}`,style:{background:ps(s.get(r)??1)}},r))})}function Un(t){return ri(t,u.useContext(ws).tones)}function He({type:t,position:s,multiple:o,id:n,variant:r,top:c,routeLabel:l}){const f=le.useNodeId(),d=u.useContext(xs),x=!!f&&!!d&&!d.readOnly,h=()=>{x&&f&&d.onAddFromPort(f,t,n)},m=r==="error"?"a step that handles this step's failure":r==="each"?"the first step of this loop's body":t==="target"?"a step before this one":"the next step";return e.jsx(le.Handle,{type:t,position:s,id:n,className:r==="error"?"w6w-handle-error":r==="each"?"w6w-handle-each":o?"w6w-handle-multi":void 0,style:{...o?{height:22,borderRadius:3,width:8}:{},...c?{top:c}:{}},onClick:x?h:void 0,title:l?`${l} — drag or click to connect`:x?`Drag to empty canvas (or click) to add ${m} · drag to a port to connect`:r==="error"?"On error — drag to route this step's failure separately":r==="each"?"Each item — drag to the first step to repeat for every item":o?t==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Hn({id:t,step:s,runnable:o}){const n=u.useContext(xs);if(!n||n.readOnly)return null;const r=o||n.runsFromNode,c=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=tt(s),f=We(s);return e.jsxs(le.NodeToolbar,{position:le.Position.Top,className:"w6w-node-toolbar",children:[r&&e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:c,"aria-label":c,onClick:()=>n.onRun(t),children:e.jsx(we.Icon,{name:"run",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":l,title:l?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":l?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(t),children:e.jsx(we.Icon,{name:"pause",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":f,title:f?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":f?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(t),children:e.jsx(we.Icon,{name:"ban",size:15})}),e.jsx("span",{className:"w6w-node-toolbar-divider","aria-hidden":"true"}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>n.onEdit(t),children:e.jsx(we.Icon,{name:"edit",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>n.onDuplicate(t),children:e.jsx(we.Icon,{name:"copy",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>n.onDelete(t),children:e.jsx(we.Icon,{name:"trash",size:15})})]})}function Jn({step:t,count:s}){if(s<2)return null;const o=t.fanOut==="parallel",n=i.fanOutLabel(s,o?"parallel":"sequential");return e.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":n,title:n,children:[e.jsx("span",{"aria-hidden":"true",children:o?"⇉":"→"})," ",s]})}function qn({step:t}){const s=tt(t),o=We(t);return!s&&!o?null:e.jsxs("div",{children:[o&&e.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":mn,title:mn,children:[e.jsx(we.Icon,{name:"ban",size:11})," Disabled"]}),s&&e.jsxs("span",{className:"w6w-node-flag w6w-node-flag-paused","data-testid":"step-paused-badge",role:"img","aria-label":hn,title:hn,children:[e.jsx(we.Icon,{name:"pause",size:11})," Paused"]})]})}function Gn(t){return!t||t.length===0?{}:{"data-step-problem":t.map(s=>s.code).join(" "),title:t.map(i.stepProblemTooltip).join(`
|
|
7
|
+
`)}}function Kn({problems:t}){if(!t||t.length===0)return null;const s=t.map(i.stepProblemTooltip).join(`
|
|
8
|
+
`);return e.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":s,title:s,style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:e.jsx(we.Icon,{name:"warning",size:12})})}function zi(t){const s=i.useW6WApi(),o=t.uses.action,[n,r]=u.useState(null),c=t.uses.trigger===!0,l=t.uses.app;return u.useEffect(()=>{if(!c||!s.getAppTriggers)return;let f=!1;return s.getAppTriggers(l).then(d=>{var x;return!f&&r(((x=d.find(h=>h.key===o))==null?void 0:x.title)??null)}).catch(()=>{}),()=>{f=!0}},[s,l,o,c]),n||o}function Ui(t){const s=i.useW6WApi(),o=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,r=t.id,c=[...Ii(t.nodes),...(t.nodes??[]).filter(y=>{var C,M;return(((C=y.uses)==null?void 0:C.app)===i.WEBHOOK_APP||((M=y.uses)==null?void 0:M.app)===i.FORM_APP)&&y.uses.trigger!==!0})],l=c.length>0,f=c.map(y=>`${y.id}:${y.uses.app}:${y.uses.action}:${i.connectionIdFor(y,t.connections)??""}`).join("|"),[d,x]=u.useState([]),h=u.useMemo(()=>Ai(d),[d]),[m,k]=u.useState(0);u.useEffect(()=>{if(!o||!l){x([]);return}let y=!1;return o.call(s,r).then(C=>!y&&x(C)).catch(()=>{}),()=>{y=!0}},[s,o,r,l,f,m]);const j=u.useMemo(()=>n?async y=>{try{await n.call(s,y)}finally{k(C=>C+1)}}:void 0,[s,n]);return u.useMemo(()=>({byNode:h,subs:d,retry:j}),[h,d,j])}function Hi({nodeId:t}){const{byNode:s,retry:o}=u.useContext($n),[n,r]=u.useState(!1),c=s.get(t),l=Ti(c,o!==void 0);return!c||!l?null:e.jsxs("div",{className:"w6w-small","data-trigger-registration":c.status,"data-tone":l.tone,style:{marginTop:3,paddingLeft:2},children:[e.jsx("span",{style:l.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:l.label}),e.jsxs("span",{className:"w6w-muted",children:[" · ",l.lastFire]}),l.error&&e.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:l.error}),l.retryVisible&&o&&e.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{r(!0),o(c.id).catch(()=>{}).finally(()=>r(!1))},children:"Retry"})]})}function Ji({id:t,data:s,selected:o}){const n=s.step,c=u.useContext(gs).get(n.uses.app),l=(c==null?void 0:c.displayName)||n.uses.app||"—",f=i.isTriggerStep(n.uses),d=zi(n),x=n.uses.trigger?`${l} · ${d}`:l,h=i.nodePortsForStep(n,u.useContext(hs)),m=On(s.stepStatus??"no-run",s.runStatus),k=e.jsx(Jn,{step:n,count:u.useContext(ms).get(t)??0}),j=Un(t);return e.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:j,"data-disabled":We(n)||void 0,"data-paused":tt(n)||void 0,children:[e.jsx(Hn,{id:t,step:n,runnable:!0}),e.jsxs("div",{className:f?"w6w-node-trigger":void 0,"data-node-kind":f?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Gn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${m.borderWidth}px ${m.borderStyle} ${o?"var(--w6w-accent)":m.borderColor}`,opacity:We(n)?.45:o?1:m.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...f?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[e.jsx(Kn,{problems:s.stepProblems}),h.in>0&&e.jsx(He,{type:"target",position:le.Position.Left,multiple:h.in>1}),e.jsx(i.AppIcon,{src:c==null?void 0:c.iconSvg,srcDark:c==null?void 0:c.iconSvgDark,brandColor:c==null?void 0:c.brandColor,name:l,size:28}),e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontWeight:600},children:x}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:n.uses.action||"—"})})]}),h.out>0&&e.jsxs(e.Fragment,{children:[e.jsx(He,{type:"source",position:le.Position.Right,multiple:h.out>1}),!f&&e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),k,e.jsx(qn,{step:n}),f&&n.uses.trigger===!0&&e.jsx(Hi,{nodeId:t}),s.loopOf&&e.jsx(zn,{id:t}),e.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,c!=null&&c.version?` - v${c.version}`:""]}),n.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function qi({id:t,data:s,selected:o}){const n=s.step,r=i.routesForStep(n),c=n.uses.app===i.ROUTER_APP,l=i.isIfStep(n),f=r.length?i.routerPortLayout(r):l?i.ifPortLayout():void 0,d=JSON.stringify(r.map(F=>F.id)),x=le.useUpdateNodeInternals();u.useEffect(()=>{x(t)},[t,d,x]);const h=i.internalNodeLabel(n.uses.app,n.uses.action),m=i.internalNodeIcon(n.uses.app,n.uses.action),k=i.nodePortsForStep(n,u.useContext(hs)),j=i.isTriggerStep(n.uses),y=Vi(n),C=On(s.stepStatus??"no-run",s.runStatus),M=e.jsx(Jn,{step:n,count:u.useContext(ms).get(t)??0}),w=Un(t);return e.jsxs("div",{className:[y?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:w,"data-disabled":We(n)||void 0,"data-paused":tt(n)||void 0,children:[e.jsx(Hn,{id:t,step:n,runnable:!i.isControlApp(n.uses.app)}),e.jsxs("div",{className:j?"w6w-node-trigger":c?"w6w-node-router":void 0,"data-node-kind":j?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Gn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${C.borderWidth}px ${C.borderStyle} ${o?"var(--w6w-accent)":C.borderColor}`,opacity:We(n)?.45:o?1:C.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...j?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...f!=null&&f.minHeight?{minHeight:f.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[e.jsx(Kn,{problems:s.stepProblems}),k.in>0&&e.jsx(He,{type:"target",position:le.Position.Left,multiple:k.in>1}),m&&e.jsx(i.InternalIcon,{icon:m}),e.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[e.jsx("div",{style:{fontWeight:600},children:h}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:n.uses.action||"—"})})]}),y&&e.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[e.jsx("span",{children:"Each item"}),e.jsx("span",{children:"Done"})]}),l&&(f==null?void 0:f.right[0])&&e.jsx("span",{className:"w6w-if-true-label w6w-small","aria-hidden":"true",children:f.right[0].label}),!l&&!!(f!=null&&f.right.length)&&e.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${f.right.length}, 1fr)`},"aria-hidden":"true",children:f.right.map(F=>e.jsx("span",{title:F.label,children:F.label},F.id))}),k.out>0&&e.jsxs(e.Fragment,{children:[y&&e.jsx(He,{type:"source",position:le.Position.Right,multiple:!1,id:i.EACH_SOURCE_HANDLE,variant:"each"}),f?e.jsxs(e.Fragment,{children:[f.right.map(F=>e.jsx(He,{type:"source",position:le.Position.Right,multiple:!1,id:F.handleId,top:F.top,routeLabel:F.label},F.id)),f.bottom&&e.jsxs(e.Fragment,{children:[e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:f.bottom.handleId,routeLabel:f.bottom.label}),e.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:f.bottom.label})]})]}):e.jsx(He,{type:"source",position:le.Position.Right,multiple:k.out>1,id:y?i.routeHandle(i.FOREACH_DONE_ROUTE):void 0}),!j&&!c&&!l&&n.uses.app!==i.RACE_APP&&e.jsx(He,{type:"source",position:le.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),M,e.jsx(qn,{step:n}),s.loopOf&&e.jsx(zn,{id:t}),s.legacyLoop&&e.jsx("div",{className:"w6w-loop-legacy-note w6w-small",children:"This loop was converted from an older definition. Its steps after For each now run once per item; check the order, then save."}),e.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:n.id}),n.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Gi(t,s){var l,f;if(!s)return t;const o={...(t==null?void 0:t.steps)??{}};let n=!1;for(const[d,x]of Object.entries(s)){const h=/^nodes\.([^.]+)\.output$/.exec(d);!h||((l=o[h[1]])==null?void 0:l.output)!==void 0||(o[h[1]]={...o[h[1]]??{},output:x},n=!0)}const r=s["trigger.event"],c=r!==void 0&&((f=t==null?void 0:t.trigger)==null?void 0:f.event)===void 0;return!n&&!c?t:{...t??{},...n?{steps:o}:{},...c?{trigger:{...(t==null?void 0:t.trigger)??{},event:r}}:{}}}function Ki(t){return e.jsx(Yi,{...t})}function Yi({workflowId:t,step:s,restoreVersion:o,upstreamSteps:n,loop:r,onChange:c,onClose:l,onCancel:f,readOnly:d,initialView:x="props",fanOutCount:h=0,stateOutputFields:m,onTestRun:k,stepProblems:j,otherStepIds:y}){var yt,St,ot,Me;const C=i.useW6WApi(),M=u.useContext(gs),[w,F]=u.useState(s),W=i.useWorkflowConnections(),O=i.connectionIdFor(w,W==null?void 0:W.connections),I={...w,uses:{...w.uses,connection:O}},E=w.uses.connectionRef!==void 0&&!O||i.isConnectionBlocked(I,j),V=j==null?void 0:j.find(T=>T.code==="unknown_connection"&&T.connection===O),K=(j??[]).filter(T=>"fix"in T),[S,g]=u.useState(E?"setup":"configure"),[R,Y]=u.useState(x==="json"?"code":x==="settings"?"config":"props"),[B,ne]=u.useState("props"),[Z,A]=u.useState(()=>i.stepToJson(s)),[X,L]=u.useState("{}"),z=u.useRef(null),[U,ie]=u.useState(!1),J=u.useRef(o);u.useEffect(()=>{J.current!==o&&(J.current=o,F(s),A(i.stepToJson(s)))},[o,s]);const[H,q]=u.useState(!1),[Q,fe]=u.useState(null),[Je,_e]=u.useState(null),[lt,Se]=u.useState(null),[qe,Ie]=u.useState(!1),ge=i.isInternalApp(w.uses.app),ce=w.uses.trigger===!0;u.useEffect(()=>{if(ge){fe(i.internalNodeParams(w.uses.app,w.uses.action));const te=i.INTERNAL_NODES.filter(ae=>ae.app===w.uses.app&&ae.groupActions&&!ae.hidden);_e(te.length?te.map(ae=>({key:ae.action,title:ae.label,params:ae.params})):null);return}if(!w.uses.app){_e(null),fe([]);return}let T=!1;return fe(null),(ce?i.getTriggerDefs(C,w.uses.app):C.getAppActions(w.uses.app)).then(te=>{var ae;T||(_e(te),fe(w.uses.action?((ae=te.find(je=>je.key===w.uses.action))==null?void 0:ae.params)??[]:[]))}).catch(()=>!T&&fe([])),()=>{T=!0}},[C,w.uses.app,w.uses.action,ge,ce]);const ke=u.useRef(0);u.useEffect(()=>()=>{ke.current++},[]);const Be=u.useCallback(()=>{ge||!w.uses.app||C.listConnectionsForApp(w.uses.app).then(T=>{Se(T),Ie(!1)}).catch(()=>Ie(!0))},[C,w.uses.app,ge]);u.useEffect(()=>{if(ge||!w.uses.app)return;let T=!1;return Se(null),Ie(!1),C.listConnectionsForApp(w.uses.app).then(te=>{T||(Se(te),Ie(!1))}).catch(()=>!T&&Ie(!0)),()=>{T=!0}},[C,w.uses.app,ge]);const oe=u.useCallback(T=>{F(T),c(T)},[c]),bt=qo({enabled:w.uses.app===i.SCRIPT_APP&&!d,values:w.with??{},onChange:T=>oe({...w,with:T})}),de=T=>{T==="code"&&A(i.stepToJson(w)),Y(T)},Re=T=>{const te=i.stepNameError(T,y??[]);return te||oe({...w,id:T}),te},Oe=!!w.uses.app&&!!w.uses.action&&!i.isControlApp(w.uses.app),Ee=i.isForeachStep(w),xe=i.isTriggerStep(w.uses),Ge=S==="test"&&Oe&&!xe,ye=i.useSeedSources(t,n,Oe&&!xe||Ee),Ve=Wn(Oe&&!xe?r:void 0),Pe=i.useExpressionOptions(),Fe=i.startStateFromSeeds(ye,Bn(Ve),(yt=Pe.stateShape)==null?void 0:yt.written),ct=Gi(Fe,Pe.sampleValues),Ne=i.useRememberedTestInput(Oe&&!xe||Ee?t:void 0,w.id),[be,$e]=u.useState(!1);u.useEffect(()=>{if((!Oe||xe)&&!Ee||!Ne.loaded)return;if(!Ee&&Ne.input!==void 0){const te=Ne.input;if(Object.keys(te).length===0)return;const ae=JSON.stringify(te,null,2);L(je=>je.trim()==="{}"?ae:je),$e(!0);return}let T=!1;return C.listStepTests(t,w.id).then(te=>{if(T)return;const ae=te.length?te[te.length-1]:null;if(!(ae!=null&&ae.input)||Object.keys(ae.input).length===0)return;const je=JSON.stringify(ae.input,null,2);L(Ye=>Ye.trim()==="{}"?je:Ye)}).catch(()=>{}),()=>{T=!0}},[C,t,w.id,Oe,xe,Ee,Ne.loaded]);const Le=Ee?$i(X):Wt(X),De={...w.with??{},...Le??{}},dt=Le??{},st=!!Q&&!bs(Ve)&&i.requiredParamsFilled(Q,De)&&(w.uses.app!==i.CALL_APP||H),ee=Ee?i.resolveLoopItemsInState(De.items,Fe):void 0,[nt,Ke]=u.useState("idle"),jt=T=>{L(T),Ke("idle")},ut=async()=>{if(ee){Ke("saving");try{await C.saveStepTest(t,w.id,i.foreachTestFixture(ee,dt)),Ke("saved")}catch{Ke("failed")}}},ue=M.get(w.uses.app),vt=ce?(St=Je==null?void 0:Je.find(T=>T.key===w.uses.action))==null?void 0:St.webhook:void 0,pt=ge?i.internalNodeIcon(w.uses.app,w.uses.action):null,Bt=ge?pt?e.jsx(i.InternalIcon,{icon:pt}):null:e.jsx(i.AppIcon,{src:ue==null?void 0:ue.iconSvg,srcDark:ue==null?void 0:ue.iconSvgDark,brandColor:ue==null?void 0:ue.brandColor,name:ue==null?void 0:ue.displayName});return e.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:Bt,title:e.jsx(i.StepNameEditor,{value:w.id,onCommit:Re,readOnly:d}),onClose:f??l,size:"wide",children:e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsxs("div",{className:"w6w-tabsbar",children:[e.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].filter(T=>w.uses.app!==i.RACE_APP||T!=="test").map(T=>e.jsx("button",{type:"button",className:`w6w-subtab${S===T?" active":""}`,disabled:E&&T!=="setup",onClick:()=>g(T),children:T==="setup"?"Setup":T==="configure"?"Configure":"Test"},T))}),Ge?e.jsx(i.ConfigViewToggle,{view:B,views:["props","code"],onChange:T=>ne(T)}):e.jsx(i.ConfigViewToggle,{view:R,customized:i.hasParamCustomization(w.with??{}),onChange:de,disabled:S!=="configure"})]}),E&&V&&e.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",V.connection," no longer exists — choose another to continue."]}),K.length>0&&e.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:K.map(T=>e.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("span",{children:i.stepProblemTooltip(T)}),e.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":T.code,disabled:d,onClick:()=>{const te=_n(w,T);oe(te),A(i.stepToJson(te))},children:"fix"in T?T.fix.label:""})]},T.code))}),e.jsxs("div",{className:"w6w-stepconfig-body",children:[S==="setup"&&w.uses.app===i.CALL_APP&&e.jsx(i.CallTargetForm,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d,onValidityChange:q,setupOnly:!0}),S==="setup"&&w.uses.app!==i.CALL_APP&&e.jsx(Qi,{step:w,app:ue,actions:Je,conns:lt,connsFailed:qe,isInternal:ge,actionLabel:ce?"Trigger":"Action",readOnly:d,onChangeAction:T=>{var ae;const te=ge?i.internalNodeDefaults(w.uses.app,T):{};if(ge)for(const je of i.internalNodeParams(w.uses.app,T))je.key in(w.with??{})&&(te[je.key]=(ae=w.with)==null?void 0:ae[je.key]);oe({...w,uses:{...w.uses,action:T},with:te})},onChangeTriggerEvents:(T,te)=>oe({...w,uses:{...w.uses,action:T},with:{...w.with,actions:te}}),onChangeConnection:T=>{if(!W){const{connectionRef:ae,...je}=w.uses;oe({...w,uses:{...je,connection:T}});return}const te=i.selectNodeConnection(w,T,(W==null?void 0:W.nodes)??[w],(W==null?void 0:W.connections)??{});W==null||W.setConnections(te.connections),oe(te.step)},onChangeConnectionRef:T=>oe(i.withConnectionRef(w,T)),onConnectionCreated:Be,onChangeApp:T=>{const te=++ke.current;if(T===w.uses.app){oe(w);return}const ae={...w,uses:{app:T,action:"",...ce?{trigger:!0}:{}},with:{}};(i.isInternalApp(T)?Promise.resolve([]):C.listConnectionsForApp(T)).catch(()=>[]).then(je=>{if(te!==ke.current)return;const Ye=i.defaultConnectionFor(ae,je,(W==null?void 0:W.nodes)??[],(W==null?void 0:W.connections)??{});oe({...ae,uses:{...ae.uses,...Ye}})})}}),S==="configure"&&e.jsxs(e.Fragment,{children:[(w.uses.app===i.WEBHOOK_APP||w.uses.app===i.FORM_APP)&&C.listSubscriptionsForWorkflow&&C.createSubscription&&e.jsx(Zi,{workflowId:t,step:w,readOnly:d}),ce&&vt&&w.uses.action&&C.listSubscriptionsForWorkflow&&e.jsx(Lo,{workflowId:t,nodeId:w.id,appId:w.uses.app,triggerKey:w.uses.action,appName:(ue==null?void 0:ue.displayName)??w.uses.app,setup:vt,connectionId:O&&!O.startsWith("zerocred:")?O:null,params:w.with??{},readOnly:d}),Q===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):R==="props"?w.uses.app===i.CALL_APP?e.jsx(i.CallTargetForm,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d,onValidityChange:q}):w.uses.app===i.RACE_APP?e.jsx("p",{className:"w6w-muted w6w-small",children:i.RACE_DESCRIPTION}):w.uses.action==="wait"&&i.isControlApp(w.uses.app)?e.jsx(i.WaitEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.action==="if"&&i.isControlApp(w.uses.app)?e.jsx(i.ConditionEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app==="@w6w/stop"?e.jsx(i.StopEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app===i.ROUTER_APP?e.jsx(i.RouterEditor,{values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})}):w.uses.app===i.FORM_APP?e.jsxs("div",{className:"w6w-stack",children:[e.jsx(jo,{value:(ot=w.with)==null?void 0:ot.form,readOnly:d,stepId:w.id,onChange:T=>oe({...w,with:{...w.with,form:T}})}),e.jsx(i.ParamsForm,{params:Q.filter(T=>T.key!=="form"),values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T})})]}):e.jsxs(e.Fragment,{children:[w.uses.app===i.SCRIPT_APP&&e.jsx(Go,{values:w.with??{},conversion:bt,readOnly:d}),e.jsx(i.ParamsForm,{params:Q,values:w.with??{},readOnly:d,onChange:T=>oe({...w,with:T}),dynamic:ge||!w.uses.action?void 0:{appId:w.uses.app,actionKey:w.uses.action,kind:i.isTriggerStep(w.uses)?"trigger":"action",connectionId:E?void 0:O,appName:ue==null?void 0:ue.displayName}})]}):R==="code"?e.jsx(i.JsonEditor,{value:Z,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${w.id} JSON`,copyable:!0}):R==="params-code"?e.jsx(i.ParamCustomization,{values:w.with??{},onChange:T=>oe({...w,with:T}),readOnly:d}):e.jsxs("div",{className:"w6w-stack",children:[e.jsx(i.NodeConfigForm,{config:{retry:w.retry,onError:w.onError,notes:w.notes,timeoutMs:w.timeoutMs},onChange:T=>oe({...w,...T}),readOnly:d,failureHandling:!xe,retryControls:!i.isControlApp(w.uses.app)&&w.uses.app!==i.CALL_APP}),Xi,e.jsx(i.StepFanOutControl,{step:w,count:h,readOnly:d,onChange:oe}),i.stateWriteVisible(w)&&e.jsx(i.StepStateControl,{step:w,inLoop:r!==void 0,outputFields:m,readOnly:d,onChange:oe})]})]}),S==="test"&&e.jsx("div",{className:"w6w-stack",children:Oe?xe?e.jsx(i.TriggerFillForm,{app:w.uses.app,action:w.uses.action,fields:ce||(Me=w.with)==null?void 0:Me.fields,appTrigger:ce,persist:{workflowId:t,stepId:w.id,input:dt},listen:(w.uses.app===i.WEBHOOK_APP||w.uses.app===i.FORM_APP)&&C.listSubscriptionsForWorkflow&&C.startWebhookListen?{stepWith:w.with,readOnly:d,appId:w.uses.app}:void 0}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",e.jsx("code",{children:w.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),e.jsx(Vn,{seed:Ve,readOnly:d}),be&&!d&&e.jsx(i.LastUsedNote,{onClear:()=>{Ne.clear(),$e(!1),L("{}")}}),e.jsx(ds,{text:X,onChange:L,seeds:ye,readOnly:d}),Q===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):e.jsx(Vo,{params:Q,values:De,testStartState:ct,view:B,literalKeys:w.uses.app===i.SCRIPT_APP?Oi:void 0}),e.jsx(i.StepTestRun,{ref:z,app:w.uses.app,action:w.uses.action,connectionId:O,values:De,timeoutMs:w.timeoutMs,state:Fe,canRun:st,hideRunButton:!0,persist:{workflowId:t,stepId:w.id,input:dt},onBusyChange:ie})]}):Ee?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Resolves ",e.jsx("strong",{children:"Items"})," against the incoming state — nothing inside the loop runs. ",e.jsx("strong",{children:"Test"})," saves the first item as this loop's sample, so the steps on its ",e.jsx("strong",{children:"Each item"})," output can pick its keys. To run the loop's work, test a step on ",e.jsx("strong",{children:"Each item"}),": it runs once, on one item."]}),e.jsx(ds,{text:X,onChange:jt,seeds:ye,readOnly:d,expand:!ee,hint:e.jsxs(e.Fragment,{children:["Paste a sample list — ",e.jsx("code",{children:'[{"id": 1, "name": "…"}]'})," — or"," ",e.jsx("code",{children:'{"items": […]}'}),". It replaces what ",e.jsx("strong",{children:"Items"})," ","resolves to, for this test only."]})}),e.jsx(Wi,{items:ee,save:nt})]}):e.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),e.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[f&&!d&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:f,children:"Cancel"}),w.uses.app===i.RACE_APP&&S==="configure"?e.jsx("button",{type:"button",className:"w6w-btn",onClick:l,children:"Done"}):S!=="test"?e.jsxs(e.Fragment,{children:[f&&!d&&e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:E,onClick:()=>g(S==="setup"?"configure":"test"),children:"Next →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),Oe&&!xe&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:d||!st||U,onClick:()=>{var T;k==null||k(),(T=z.current)==null||T.run()},children:U?"Testing…":"Test"}),Ee&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:d||!(ee!=null&&ee.length)||nt==="saving",onClick:()=>void ut(),children:nt==="saving"?"Testing…":"Test"})]})]})]})})}const Xi=!1;function Zi({workflowId:t,step:s,readOnly:o}){const n=i.useW6WApi(),r=s.uses.app===i.FORM_APP,[c,l]=u.useState(void 0),[f,d]=u.useState(null),[x,h]=u.useState(!1),m=(c==null?void 0:c.webhookUrl)??(c==null?void 0:c.formUrl);u.useEffect(()=>{const j=n.listSubscriptionsForWorkflow;if(!j)return;let y=!1;return j(t).then(C=>{y||l(r?i.pickFormSubscription(C,s.id):i.pickWebhookSubscription(C,s.id))}).catch(C=>!y&&d(C.message)),()=>{y=!0}},[n,t,s.id,r]);const k=()=>{const j=n.createSubscription;j&&(d(null),h(!0),j(r?i.FORM_APP:i.WEBHOOK_APP,s.uses.action,{workflowId:t,connectionId:null,params:r?{node:s.id}:s.with??{}}).then(y=>{h(!1),l(y)}).catch(y=>{h(!1),d(y instanceof Error?y.message:String(y))}))};return e.jsxs("div",{className:"w6w-stack w6w-url-panel",children:[e.jsx("p",{className:"w6w-muted w6w-small",children:r?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Form URL"})," — share it, or embed it in an iframe. Each submission starts the workflow once it is published."]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]})}),f&&e.jsx("div",{className:"w6w-result w6w-error",children:f}),m?e.jsxs("div",{className:"w6w-listen-url",children:[e.jsx(we.Copyable,{value:m,readOnly:!0,children:e.jsx("input",{type:"text",readOnly:!0,value:m,"aria-label":r?"Form URL":"Webhook URL"})}),r&&e.jsx("a",{className:"w6w-btn w6w-btn-ghost w6w-btn-sm",href:m,target:"_blank",rel:"noreferrer",children:"Open form"})]}):c===void 0?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!o&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:x,onClick:k,children:x?"Creating…":r?"Create form URL":"Create webhook URL"})]})}function Qi({step:t,app:s,actions:o,conns:n,connsFailed:r,isInternal:c,actionLabel:l="Action",readOnly:f,onChangeAction:d,onChangeTriggerEvents:x,onChangeConnection:h,onChangeConnectionRef:m,onChangeApp:k,onConnectionCreated:j}){const y=t.uses.trigger?i.eventbriteTriggerChoices(t.uses.app,o,t.uses.action,t.with??{}):null,[C,M]=u.useState(null),w=u.useRef(null),F=i.useWorkflowConnections(),W=i.connectionIdFor(t,F==null?void 0:F.connections);return e.jsxs("div",{className:"w6w-stack",children:[t.uses.connectionRef&&!W&&e.jsx("p",{role:"alert",className:"w6w-field-error",children:"The shared connection is missing or unbound. Choose an account."}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"App"}),e.jsxs("div",{className:"w6w-app-conn-row",ref:w,children:[e.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":C==="app",disabled:f,onClick:()=>M(O=>O==="app"?null:"app"),children:[!c&&s&&e.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),e.jsx("span",{className:"w6w-conn-label-name",children:c?t.uses.app:(s==null?void 0:s.displayName)??t.uses.app})]}),!c&&e.jsx(i.WorkflowConnectionPicker,{step:t,conns:n,failed:r,readOnly:f,open:C==="conn",onOpenChange:O=>M(O?"conn":null),anchorRef:w,onChangeConnection:h,onChangeConnectionRef:m,onConnectionCreated:j})]}),C==="app"&&e.jsx(i.AnchoredFlyout,{anchorRef:w,onClose:()=>M(null),children:e.jsx(i.AppPicker,{onSelectApp:O=>{const I=O.id===t.uses.app;k(O.id),M(I?"conn":null)}})})]}),c&&!(o!=null&&o.length)?e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Action"}),e.jsx("div",{className:"w6w-muted w6w-small",children:e.jsx("code",{children:t.uses.action})})]}):y?e.jsx(i.EventbriteTriggerPicker,{choices:y,readOnly:f,onChange:O=>x(y.triggerKey,O)}):e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:l}),e.jsx(i.Combobox,{value:t.uses.action,disabled:f||o===null,onChange:d,options:o===null?[{value:t.uses.action,label:t.uses.action}]:o.map(O=>({value:O.key,label:O.title??O.key}))})]})]})}function Cn({trigger:t}){return e.jsx("span",{className:"w6w-connection-node-kind",role:"img","aria-label":t?"Trigger":"Node",children:e.jsx("svg",{"aria-hidden":"true",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t?e.jsx("path",{d:"M13 2 4 14h7l-1 8 10-12h-7l1-8Z"}):e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"}),e.jsx("path",{d:"M2 12h3m14 0h3"})]})})})}function er({resources:t}){const s=i.useW6WApi(),o=t.highlightNode;u.useEffect(()=>()=>o==null?void 0:o(null),[o]);const[n,r]=u.useState([]),[c,l]=u.useState(!0),[f,d]=u.useState(),[x,h]=u.useState(),[m,k]=u.useState(null),[j,y]=u.useState(!1),[C,M]=u.useState(!1),w=u.useRef(0),F=u.useCallback(async()=>{const L=++w.current;l(!0),d(void 0);try{const z=await s.listConnections();return L!==w.current?void 0:(r(z),z)}catch(z){L===w.current&&d(z.message)}finally{L===w.current&&l(!1)}},[s]);u.useEffect(()=>(F(),()=>{w.current++}),[F]);const[W,O]=u.useState(new Map),I=JSON.stringify([...new Set([...Object.values(t.connections).map(L=>L.app),...n.map(L=>L.appId)])].filter(L=>{var z;return!((z=t.apps)!=null&&z.has(L))&&!n.some(U=>U.appId===L&&U.app!==void 0)}).sort());u.useEffect(()=>{var J,H;let L=!1;const z=JSON.parse(I);if(c||!z.length)return;const U=(J=s.listAppsByIds)==null?void 0:J.bind(s),ie=U?Promise.all(Array.from({length:Math.ceil(z.length/50)},(q,Q)=>U(z.slice(Q*50,(Q+1)*50)))).then(q=>q.flat()):(H=s.listApps)==null?void 0:H.call(s);return ie==null||ie.then(q=>{L||O(new Map(q.map(Q=>[Q.id,Q])))}).catch(()=>{}),()=>{L=!0}},[s,I,c]);const P=L=>{var J;const z=n.find(H=>H.appId===L&&H.app)??n.find(H=>H.appId===L&&H.app!==void 0),U=z?i.resolveConnectionAppMeta(z,W):W.get(L),ie=(J=t.apps)==null?void 0:J.get(L);return ie?{...U,...ie}:U},E=L=>{var z;return((z=P(L))==null?void 0:z.displayName)||L},V=L=>{if(t.readOnly)return!1;try{return t.edit(L),h(void 0),!0}catch(z){return h(z.message),!1}},K=L=>i.nextWorkflowConnectionName(L.appId,t.connections),S=()=>{k(null),h(void 0),y(!1)},g=m!=null&&m.ref?t.connections[m.ref]:void 0,R=n.find(L=>L.id===(m==null?void 0:m.connection)),Y=(g==null?void 0:g.app)??(R==null?void 0:R.appId),B=t.nodes.filter(L=>L.uses.app===Y),ne=t.nodes.filter(L=>(m==null?void 0:m.ref)!==void 0&&L.uses.connectionRef===m.ref),Z=n.filter(L=>!g||L.appId===g.app).map(L=>({value:L.id,label:g?L.displayName||L.id:`${E(L.appId)} · ${L.displayName||L.id}`}));m!=null&&m.connection&&!Z.some(L=>L.value===m.connection)&&Z.unshift({value:m.connection,label:m.connection.startsWith("zerocred:")?"Built-in":m.connection});const A=(L,z=28)=>{const U=P(L);return e.jsx(i.AppIcon,{src:U==null?void 0:U.iconSvg,srcDark:U==null?void 0:U.iconSvgDark,brandColor:U==null?void 0:U.brandColor,name:E(L),size:z})},X=()=>{if(!m||!m.name.trim()||!m.connection||!Y)return;const L=m.ref!==void 0?{type:"update",ref:m.ref,name:m.name,connection:m.connection,nodeIds:m.allNodes?B.map(z=>z.id):void 0}:{type:"add",name:m.name,app:Y,connection:m.connection};V(L)&&S()};return e.jsxs("div",{className:"w6w-stack","data-testid":"workflow-connections-panel",children:[e.jsxs("div",{className:"w6w-workflow-connections-heading",children:[e.jsx("h3",{children:"Connections"}),e.jsx(i.IconButton,{label:"Add connection",disabled:t.readOnly,onClick:()=>{h(void 0),k({name:"",connection:"",allNodes:!1})},children:e.jsx("svg",{"aria-hidden":"true",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),f&&e.jsxs("div",{role:"alert",className:"w6w-stack",children:[e.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",f]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void F(),children:"Retry"})]}),Object.entries(t.connections).map(([L,z])=>{var H;const U=t.nodes.filter(q=>q.uses.connectionRef===L),ie=n.find(q=>q.id===z.connection),J=(ie==null?void 0:ie.displayName)||((H=z.connection)!=null&&H.startsWith("zerocred:")?"Built-in":z.connection)||"No credentials selected";return e.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":L,children:[e.jsxs("div",{className:"w6w-connection-app-heading",children:[A(z.app),e.jsxs("div",{className:"w6w-connection-summary",children:[e.jsx("strong",{children:E(z.app)}),e.jsx("span",{className:"w6w-small",children:J}),e.jsxs("span",{className:"w6w-muted w6w-small",children:[L,ie!=null&&ie.state?` · ${ie.state}`:""]})]}),e.jsx(i.IconButton,{icon:"edit",label:`Edit connection ${L}`,disabled:t.readOnly,onClick:()=>{h(void 0),k({ref:L,name:L,connection:z.connection??"",allNodes:!1})}})]}),U.length>0?e.jsxs("details",{className:"w6w-connection-consumers",onToggle:q=>{q.currentTarget.open||o==null||o(null)},children:[e.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",U.length," ",U.length===1?"node":"nodes"]}),e.jsx("ul",{className:"w6w-connection-node-list",children:U.map(q=>e.jsx("li",{children:t.focusNode?e.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${q.id} on canvas`,onClick:()=>{var Q;return(Q=t.focusNode)==null?void 0:Q.call(t,q.id)},onMouseEnter:()=>o==null?void 0:o(q.id),onMouseLeave:()=>o==null?void 0:o(null),onFocus:()=>o==null?void 0:o(q.id),onBlur:()=>o==null?void 0:o(null),children:[e.jsx(Cn,{trigger:i.isTriggerStep(q.uses)}),e.jsxs("span",{className:"w6w-connection-node-label",children:[e.jsx("strong",{children:q.uses.action}),e.jsx("span",{className:"w6w-muted w6w-small",children:q.id})]})]}):e.jsxs("span",{className:"w6w-connection-app-heading",children:[e.jsx(Cn,{trigger:i.isTriggerStep(q.uses)}),e.jsxs("span",{className:"w6w-connection-node-label",children:[e.jsx("strong",{children:q.uses.action}),e.jsx("span",{className:"w6w-muted w6w-small",children:q.id})]})]})},q.id))})]}):e.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},L)}),!Object.keys(t.connections).length&&e.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),m&&!C&&!j&&e.jsxs(i.Modal,{title:m.ref!==void 0?"Edit connection":"Add connection",titleIcon:Y?A(Y):void 0,subtitle:Y?E(Y):void 0,onClose:S,children:[e.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[x&&e.jsx("p",{role:"alert",className:"w6w-field-error",children:x}),f&&e.jsxs("div",{role:"alert",className:"w6w-stack",children:[e.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",f]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void F(),children:"Retry"})]}),m.ref!==void 0&&!g&&e.jsx("p",{role:"alert",children:"This workflow connection no longer exists."}),e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:"Workflow connection name"}),e.jsx("input",{className:"w6w-input","aria-label":"Workflow connection name",value:m.name,disabled:t.readOnly,onChange:L=>k({...m,name:L.target.value})})]}),e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:g?"Credentials":"Existing connection"}),e.jsx(i.Combobox,{"aria-label":g?"Credentials":"Connection to add",options:Z,value:m.connection,placeholder:c?"Loading connections…":"Choose a connection…",disabled:t.readOnly||c||!!f,onChange:L=>{const z=n.find(U=>U.id===L);k({...m,connection:L,name:!m.name&&z?K(z):m.name})}})]}),e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:t.readOnly,onClick:()=>M(!0),children:"Create new credentials"}),g&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"w6w-muted w6w-small",children:m.allNodes?`Saving applies these credentials to all ${B.length} ${E(g.app)} nodes.`:`Saving updates credentials for ${ne.length} linked ${ne.length===1?"node":"nodes"}.`}),B.length>0&&e.jsxs("label",{className:"w6w-connection-scope",children:[e.jsx("input",{type:"checkbox",checked:m.allNodes||B.every(L=>L.uses.connectionRef===m.ref),disabled:t.readOnly||B.every(L=>L.uses.connectionRef===m.ref),onChange:L=>k({...m,allNodes:L.target.checked})}),"Use for all ",B.length," ",E(g.app)," ",B.length===1?"node":"nodes"," in this workflow"]}),e.jsxs("div",{className:"w6w-connection-remove",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:t.readOnly||ne.length>0,onClick:()=>y(!0),children:"Remove from workflow"}),ne.length>0&&e.jsx("p",{className:"w6w-muted w6w-small",children:"Assign another connection to the linked nodes before removing this one."})]})]})]}),e.jsxs("div",{className:"w6w-modal-actions",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:S,children:"Cancel"}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:t.readOnly||c||!!f||!m.name.trim()||!m.connection||!Y||m.ref!==void 0&&!g,onClick:X,children:m.ref!==void 0?"Save changes":"Add to workflow"})]})]}),m&&j&&e.jsx(i.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${m.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>y(!1),onConfirm:()=>{m.ref&&V({type:"remove",ref:m.ref})?S():y(!1)}}),m&&C&&e.jsx(i.AddConnectionModal,{initialAppId:g==null?void 0:g.app,onClose:()=>M(!1),onCreated:({connectionId:L})=>{M(!1),F().then(z=>{const U=z==null?void 0:z.find(ie=>ie.id===L);U&&k(ie=>ie?{...ie,connection:U.id,name:ie.name||K(U)}:null)})}})]})}exports.CALL_APP=i.CALL_APP;exports.CONTROL_APP=i.CONTROL_APP;exports.CanvasLayer=i.CanvasLayer;exports.DATA_APP=i.DATA_APP;exports.ExpressionOptionsProvider=i.ExpressionOptionsProvider;exports.INTERNAL_NODES=i.INTERNAL_NODES;exports.Markdown=i.Markdown;exports.RACE_APP=i.RACE_APP;exports.SCHEDULER_APP=i.SCHEDULER_APP;exports.SCRIPT_APP=i.SCRIPT_APP;exports.TRIGGER_APP=i.TRIGGER_APP;exports.WEBHOOK_APP=i.WEBHOOK_APP;exports.asFieldDefs=i.asFieldDefs;exports.centralizeConnections=i.centralizeConnections;exports.coerceDefault=i.coerceDefault;exports.connectionIdFor=i.connectionIdFor;exports.fieldWidget=i.fieldWidget;exports.fieldsToParams=i.fieldsToParams;exports.flowToWorkflow=i.flowToWorkflow;exports.internalNodeDefaults=i.internalNodeDefaults;exports.internalNodeIcon=i.internalNodeIcon;exports.internalNodeLabel=i.internalNodeLabel;exports.internalNodeParams=i.internalNodeParams;exports.isControlApp=i.isControlApp;exports.isInternalApp=i.isInternalApp;exports.isTriggerApp=i.isTriggerApp;exports.isTriggerStep=i.isTriggerStep;exports.seedValues=i.seedValues;exports.workflowToFlow=i.workflowToFlow;exports.MAX_NOTES=kn;exports.MAX_NOTE_BYTES=Tn;exports.MAX_SECTIONS=En;exports.WorkflowConnectionsPanel=er;exports.WorkflowFlowEditor=Mi;exports.applyStepProblemFix=_n;exports.assignMembership=is;exports.clampCanvas=rs;exports.findLoopProblems=ui;exports.findStateWriteProblems=hi;exports.isDisabledStep=We;exports.isPausedStep=tt;exports.pausedStopAt=ls;exports.pruneSectionMembers=us;exports.renameSectionMember=os;exports.roundGeometry=ns;exports.sectionsContaining=In;exports.withCanvasGeometry=An;exports.withDisabled=Dn;exports.withPaused=Ln;
|
|
7
9
|
//# sourceMappingURL=flow.cjs.map
|