easy_flow 0.52.0 → 0.54.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d7c7fe6e156649f27feced89f3bcead9bdac9fe6f39ebe8a9956e11716eefcd
4
- data.tar.gz: c7635a07ec44d41af799c51f17542b3346d8143a267630696527593d899a6091
3
+ metadata.gz: 0ac513b344a1d8840cfe5fee24ae751eda1e9f2e24a6b4d1fcd7199091a621d9
4
+ data.tar.gz: 9cf5f9b0edff6739beda59b1e5aa23064121ab6211344dcc1792eb407dd67f62
5
5
  SHA512:
6
- metadata.gz: 8abdee407d6ce1ffc63a98484d70ea89e1a0781a797c355886c39a08f95fad0a4a2a7966272825be60f01f9f9a0758763efbea2d126c35778adc8751aca6ca17
7
- data.tar.gz: 957d60c9212f3fee557badd513bfeab88c5854df885f4cbd74042bb664bd3944cc3ac64253796da67bf14968aa554870588fbe4fc447270b44a2b3a05a8e5c4a
6
+ metadata.gz: 58ca418648f6f5d8bd2febb3ea4204aa8e296928094c147cba63dd2319ccb772ba8373950410ad0235157902311194147b8c1ebebaf00d51d26045106a43016a
7
+ data.tar.gz: 797dec1241a9d2a38d395c75cc4bd4754045d7ad13040981bd7758c738db620ecc7853c200098761532b0d179179785fc533e747f4929808a48f972dcb912327
data/README.md CHANGED
@@ -1,2 +1,22 @@
1
1
  # easy_flow
2
2
  Guided, versioned, branching flows for Rails apps
3
+
4
+ ## For each
5
+
6
+ A For each step (`:for_each`) is drawn on the canvas as a dashed box. It runs the steps inside the box once for each item of a list an earlier step recorded, one item after another, in list order. It runs only in a flow that saves its runs, and a flow that keeps nothing tells the visitor so.
7
+
8
+ Its settings:
9
+
10
+ - `list` names the list as `<step>.<output>`, such as `outline.variants`, or as the step id alone when that step recorded the array as its whole value.
11
+ - `concurrency` is how many items may run at the same time. Items still run one at a time.
12
+ - `on_item_failure` is `continue` or `stop`. A failed item still lets the next item start.
13
+
14
+ Each visit of a held step is recorded under its item number, counting from 1, such as `write@item2`, and a further visit inside the same item adds the visit number, such as `write@item2@2`. A held step's input can tick `The current item` to receive that item's value from the list. An input naming another held step receives that step's output for the same item. An item ends when its steps leave the box, or when a held step routes to `failed`.
15
+
16
+ Once every item has ended, the For each step records these outputs under its own id:
17
+
18
+ - `result` is `passed` when no item failed, and `failed` otherwise.
19
+ - `items` holds one entry per item, mapping each held step the item reached to its latest value.
20
+ - `passed` and `failed` count the items.
21
+
22
+ A step after the box reads them through an input that names the For each step and one of those outputs. An empty list runs no items, records `items` as an empty list, and the run goes on to the step after the box.
@@ -1 +1 @@
1
- (()=>{var Ye=globalThis.ReactDOM;var{createPortal:xs,createRoot:At,flushSync:ys,hydrateRoot:bs,preconnect:vs,prefetchDNS:ws,preinit:ks,preinitModule:Ss,preload:Cs,preloadModule:Ns,requestFormReset:Es,unstable_batchedUpdates:_s,useFormState:As,useFormStatus:zs,version:Ts}=Ye;var zt=globalThis.React,e=zt,{Children:Os,Component:Bs,Fragment:Ds,PureComponent:Ls,StrictMode:Ps,Suspense:Is,cloneElement:$s,createContext:Hs,createElement:Ws,createRef:js,forwardRef:Gs,isValidElement:Vs,lazy:Fs,memo:Us,startTransition:Xs,useCallback:Ys,useContext:qs,useDebugValue:Js,useDeferredValue:Ks,useEffect:L,useId:Zs,useImperativeHandle:Qs,useLayoutEffect:R,useMemo:P,useReducer:Rs,useRef:Y,useState:E,useSyncExternalStore:tn,useTransition:en}=zt;var Tt=new Map,tt=new Map,ft=(t,o)=>Tt.set(t,o),Mt=()=>{tt.forEach(t=>t.unmount()),tt.clear()},Ot=(t,o)=>t.querySelectorAll("[data-react-ui]").forEach(s=>{if(tt.has(s))return;let r=Tt.get(s.dataset.reactUi),n=o(s);tt.set(s,n),n.render(e.createElement(r,JSON.parse(s.dataset.props)))});var Bt=(t,o)=>{let s=()=>Ot(t,o);t.addEventListener("turbo:load",s),t.addEventListener("turbo:frame-load",s),t.addEventListener("turbo:before-cache",Mt),t.readyState==="loading"?t.addEventListener("DOMContentLoaded",s):s()};var A=(...t)=>t.filter(Boolean).join(" ");var qe={primary:"ks-button-primary",secondary:"ks-button-secondary",danger:"ks-button-danger"},Je={sm:"ks-button-sm",md:"ks-button-md",lg:"ks-button-lg"},Ke=({variant:t="primary",size:o="md",className:s,children:r,...n})=>{let a=n.href?"a":"button";return e.createElement(a,{...n,className:A("ks-button",qe[t],Je[o],s)},r)},w=Ke;var Ze="border border-amber-500 bg-white text-amber-700 dark:bg-zinc-900 dark:text-amber-400",Qe="border border-gray-300 bg-white text-gray-500 dark:border-zinc-600 dark:bg-zinc-900 dark:text-gray-400",Re="border border-accent-600 bg-accent-600 text-white",to=({name:t,connected:o,armed:s,onArm:r,connecting:n})=>e.createElement("button",{onClick:a=>{n||(a.stopPropagation(),r(a))},title:s?"Now choose a step to connect to":"Connect this branch",className:s?Re:o?Qe:Ze,style:{padding:"1px 8px",marginRight:4,borderRadius:999,fontSize:11,cursor:"pointer"}},t||"next"),Dt=to;var eo={width:240,boxSizing:"border-box",borderRadius:8},oo={minWidth:120,boxSizing:"border-box",borderRadius:6},ro={padding:"8px 14px",textAlign:"center",fontWeight:600},so={fontWeight:600,lineHeight:1.3},no={fontSize:12,fontWeight:500,lineHeight:1.3},ao=(t,o,s)=>{let r=s?"ring-4 ring-accent-600/15":"shadow-sm";return t||s&&!o?`border-accent-600 ${r}`:o?`border-red-600 ${r}`:"border-gray-300 shadow-sm dark:border-zinc-700"},io=(t,o)=>o&&t.label===t.id&&t.type_name||t.label,lo=(t,o,s)=>s?o===t.type_name?null:t.type_name:t.type,co=({node:t,selected:o,armed:s,connecting:r,onSelect:n,onOpen:a,onArm:p,onDragEnd:c,onDragStart:l,hideStepTypeCodes:m,compact:u=!1,typeAbove:x=u})=>{let h=t.begins_here||t.ends_here,d=t.begins_here,f=t.ends_here?[]:t.ports,_=r&&!d,v=io(t,m),C=lo(t,v,m);return e.createElement("div",{ref:t.ref,"data-step":t.id,draggable:!d,onDragStart:k=>{k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/plain",t.id),l()},onDragEnd:c,onClick:t.opens&&!r?()=>a(t.opens):n,className:`bg-white ${u&&!o?"border":"border-2"} dark:bg-zinc-900 ${ao(_,t.violations.length>0,o)}`,style:{...u?oo:eo,padding:h?0:u?"8px 10px":"12px 14px",cursor:d?"default":r?"crosshair":"grab"}},!h&&x&&C&&e.createElement("div",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},C),h&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:ro},v),!h&&e.createElement("div",{style:u?no:so},v),t.violations.length>0&&e.createElement("div",{"data-error-count":!0,className:"text-red-600 dark:text-red-400",style:{fontSize:10}},`${t.violations.length} error${t.violations.length===1?"":"s"}`),!h&&t.summary&&t.violations.length===0&&e.createElement("div",{className:o?"text-accent-600 dark:text-accent-400":"text-gray-500 dark:text-gray-400",style:{fontSize:10}},t.summary),!h&&!x&&C&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginTop:2}},C),t.picture_url&&e.createElement("div",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:11,marginTop:2}},"Has a picture"),t.starts_a_flow&&e.createElement("div",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:11,marginTop:2}},"Runs a flow"),t.opens&&e.createElement(w,{variant:"secondary",size:"sm",className:"mt-2",onClick:k=>{k.stopPropagation(),n()}},"Settings"),f.length>0&&e.createElement("div",{style:{padding:t.begins_here?"0 14px 8px":"10px 0 0"}},f.map(k=>e.createElement(Dt,{key:k,name:k,connected:t.connected.includes(k),connecting:r,armed:s===k,onArm:N=>p(k,N)}))))},gt=co;var Lt={position:"relative",zIndex:2,width:240,fontSize:11,whiteSpace:"nowrap",cursor:"pointer"},po={...Lt,width:"auto",whiteSpace:"normal",overflowWrap:"anywhere"},mo=({node:t,header:o,onSelect:s,compact:r=!1})=>e.createElement("div",{ref:t.ref,"data-group-header":t.id,onClick:s,className:"font-mono text-gray-500 dark:text-gray-400",style:{...r?po:Lt,...s?{}:{cursor:"default"}}},o),et=mo;var uo=({id:t,bounds:o,onDrop:s})=>e.createElement("div",{"data-group-box":t,onDragOver:r=>{r.preventDefault(),r.dataTransfer.dropEffect="move"},onDrop:r=>{r.preventDefault(),s()},className:"border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60",style:{position:"absolute",zIndex:1,borderRadius:8,boxSizing:"border-box",...o}}),Pt=uo;var fo=t=>t!=null&&t!==""&&typeof t!="object",go=["integer","float"],ho=(t,o,s)=>s&&o.labels?.[t]||t,ot=(t,o,s)=>{let r=Object.keys(o?.fields||{}).filter(n=>fo(t.config[n])).map(n=>`${ho(n,o,s)}${go.includes(o.fields[n])?"":":"} ${t.config[n]}`);return[s&&t.type_name||t.type,...r].join(" \xB7 ")};var It=(t,o,s)=>{let r=Math.min(...t.map(c=>c.left))-o.left+s.scrollLeft-12,n=Math.min(...t.map(c=>c.top))-o.top+s.scrollTop-10,a=Math.max(...t.map(c=>c.left+c.width))-o.left+s.scrollLeft+12,p=Math.max(...t.map(c=>c.top+c.height))-o.top+s.scrollTop+10;return{left:r,top:n,width:a-r,height:p-n}},xo=({left:t,top:o,width:s,height:r},n)=>n.x>=t&&n.x<=t+s&&n.y>=o&&n.y<=o+r,$t=(t,o)=>t.find(s=>xo(s.bounds,o))?.id||null,Ht=(t,o)=>t.filter(s=>!o.some(r=>r.id===s.source&&r.holds?.includes(s.target))),Wt=(t,o)=>o.some(s=>s.holds?.includes(t.id)&&!s.loose&&s.row===t.row-1);var ht=(t,o)=>t.includes(o)?t.filter(s=>s!==o):[...t,o],jt=(t,o)=>({...o?.choices||{},...t?.choices||{}});var yo=({as:t="input",disabled:o,className:s,...r})=>e.createElement(t,{...r,disabled:o,className:A("ks-input",o&&"ks-input-disabled",s)}),I=yo;var bo=t=>e.createElement(I,{...t,as:"select"}),Gt=bo;var vo=({className:t,...o})=>e.createElement("input",{type:"checkbox",...o,className:A("ks-checkbox",t)}),rt=vo;var wo=({name:t,value:o,label:s,hint:r,className:n,...a})=>e.createElement("label",{className:"inline-block cursor-pointer relative"},e.createElement("input",{type:"radio",name:t,value:o,...a,className:A("peer sr-only",n)}),e.createElement("span",{className:"ks-radio-card inline-flex flex-col cursor-pointer transition ks-radio-card-highlight"},e.createElement("span",{className:"ks-radio-card-header flex items-start justify-between"},e.createElement("span",{className:"ks-radio-card-label block"},s)),r!=null&&e.createElement("span",{className:"ks-radio-card-hint block text-sm"},r))),Vt=wo;var ko=({name:t,options:o,value:s,onChange:r,className:n})=>e.createElement("div",{className:A("flex flex-wrap ks-grid-gap-sm",n)},o.map(a=>e.createElement(Vt,{key:a.value,name:t,...a,checked:a.value===s,onChange:()=>r(a.value)}))),Ft=ko;var Ut=t=>(t||[]).map(o=>typeof o=="object"?o:{value:o,label:o}),So=({name:t,type:o,value:s,choices:r,onChange:n,onSettle:a,onPick:p,pictureUrl:c})=>{if(o==="picture")return e.createElement("div",{className:"mb-3"},s&&c&&e.createElement("img",{src:c,alt:"The step's picture",style:{maxWidth:"100%"}}),s&&e.createElement(w,{type:"button",variant:"secondary",size:"sm","data-remove-picture":!0,onClick:()=>a("")},"Remove picture"),e.createElement("input",{type:"file",accept:"image/*",onChange:l=>l.target.files[0]&&p(l.target.files[0])}));if(o==="boolean")return e.createElement(rt,{checked:!!s,onChange:l=>a(l.target.checked)});if(o==="select"||o==="previous_step"||o==="from_step"||o==="flow")return e.createElement(Gt,{className:"mb-3",value:s??"",onChange:l=>a(l.target.value)},e.createElement("option",{value:""}),Ut(r).map(l=>e.createElement("option",{key:l.value,value:l.value},l.label)));if(o==="radio_cards")return e.createElement("div",{"data-radio-cards":!0,className:"mb-3 [&_label]:flex-[1_1_7rem] [&_.ks-radio-card]:flex [&_.ks-radio-card]:h-full"},e.createElement(Ft,{name:t,value:s,options:r||[],onChange:a}));if(o==="multi_select"){let l=Array.isArray(s)?s:[],m=u=>a(ht(l,u));return e.createElement("div",{style:{display:"flex",flexWrap:"wrap",gap:8}},(r||[]).map(u=>e.createElement("label",{key:u,style:{display:"inline-flex",alignItems:"center",gap:4}},e.createElement(rt,{checked:l.includes(u),onChange:()=>m(u)}),e.createElement("span",null,u))))}if(o==="flows"){let l=Array.isArray(s)?s:[];return e.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4},className:"mb-3"},Ut(r).map(m=>e.createElement("label",{key:m.value,style:{display:"inline-flex",alignItems:"center",gap:4}},e.createElement(rt,{checked:l.includes(m.value),onChange:()=>a(ht(l,m.value))}),e.createElement("span",null,m.label))))}return o==="integer"||o==="float"?e.createElement(I,{className:"mb-3",type:"number",step:o==="integer"?"1":"any",value:s??"",onChange:l=>n(l.target.value),onBlur:l=>a(l.target.value)}):e.createElement(I,{className:"mb-3",type:"text",value:s??"",onChange:l=>n(l.target.value),onBlur:l=>a(l.target.value)})},st=So;var Xt=(t,o,s,r)=>t.map((n,a)=>a===o?{...n,[s]:r}:n);var Co=({text:t})=>e.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{display:"block",fontSize:11,lineHeight:1.4,marginBottom:12},"data-setting-explanation":!0},t),nt=Co;var No=(t,o,s,r)=>{let n=(t||{})[s],a=(o||{})[s];return a?(n||{})[r[a]]:n},Eo=({holds:t,labels:o,explanations:s,rows:r,choices:n,outputsOf:a,onChange:p,onSettle:c})=>{let l=Array.isArray(r)?r:[],m=(u,x,h,d)=>{let f=Xt(l,u,x,h);d?c(f):p(f)};return e.createElement("div",{style:{marginBottom:12}},l.map((u,x)=>e.createElement("div",{key:x,className:"rounded-md border border-gray-200 dark:border-zinc-700",style:{padding:"8px 8px 2px",marginBottom:6}},Object.entries(t).map(([h,d])=>e.createElement("label",{key:h,style:{display:"block"}},e.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{display:"block",marginBottom:2,fontSize:11}},(o||{})[h]||h),e.createElement(st,{type:d,value:u[h],choices:No(n,a,h,u),onChange:f=>m(x,h,f,!1),onSettle:f=>m(x,h,f,!0)}),(s||{})[h]&&e.createElement(nt,{text:s[h]}))),e.createElement(w,{variant:"secondary",size:"sm",className:"mb-1.5",onClick:()=>c(l.filter((h,d)=>d!==x))},"Remove"))),e.createElement(w,{variant:"secondary",size:"sm",className:"w-full",onClick:()=>c([...l,{}])},"Add"))},Yt=Eo;var _o={start:null,end:"ks-value-list-end"},Ao="grid grid-cols-1 sm:grid-cols-2 ks-grid-gap-sm",zo="flex flex-col min-w-0",To="ks-value-list-label basis-auto text-xs",Mo=()=>e.createElement("svg",{"aria-label":"Right",role:"img",className:"ks-tone-success inline size-5 align-text-bottom",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor"},e.createElement("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z",clipRule:"evenodd"})),Oo=({value:t,fallback:o})=>String(t??"")===""?o:t,Bo=({rows:t,align:o="start",columns:s=!1,className:r})=>e.createElement("dl",{className:A("ks-value-list",_o[o],s&&Ao,r)},t.map((n,a)=>e.createElement("div",{key:a,className:A(s?zo:"ks-value-list-row",n.total&&"ks-value-list-total")},e.createElement("dt",{className:s?To:"ks-value-list-label"},n.label,n.note!=null&&e.createElement(e.Fragment,null," ",e.createElement("span",{className:"ks-value-list-note"},n.note))),e.createElement("dd",{className:"ks-value-list-value"},Oo(n),n.right&&e.createElement(e.Fragment,null," ",e.createElement(Mo,null)))))),qt=Bo;var Do=()=>e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2"},e.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})),Lo=({summary:t,open:o=!1,className:s,children:r})=>e.createElement("details",{className:A("ks-disclosure group",s),open:o},e.createElement("summary",{className:"ks-disclosure-summary flex cursor-pointer list-none items-center justify-between [&::-webkit-details-marker]:hidden"},e.createElement("span",null,t),e.createElement("span",{className:"ks-disclosure-icon h-4 w-4 shrink-0 transition-transform group-open:rotate-180"},e.createElement(Do,null))),e.createElement("div",{className:"ks-disclosure-body text-sm"},r)),Jt=Lo;var Po=({language:t,caption:o,className:s,children:r})=>e.createElement("div",{className:A("ks-code overflow-hidden",s)},o!=null&&e.createElement("div",{className:"ks-code-caption font-mono text-xs"},o),e.createElement("pre",{className:"ks-code-block overflow-x-auto font-mono text-sm leading-relaxed"},e.createElement("code",{className:t==null?"":`language-${t}`},r))),Kt=Po;var xt="flex flex-col gap-1 mb-3",Zt="[&_dd]:font-mono",Io="[&_.ks-value-list]:grid-cols-2 [&_.ks-value-list]:gap-2",$o="[&_.ks-value-list]:font-mono [&_.ks-value-list]:flex [&_.ks-value-list]:flex-col [&_.ks-value-list]:gap-1 [&_.ks-value-list-row]:gap-2 [&_.ks-value-list-row]:py-0 [&_.ks-value-list-row]:border-0 [&_.ks-value-list-label]:basis-[90px]",Ho="border-t border-gray-200 pt-2.5 dark:border-zinc-700 [&_.ks-disclosure]:border-0 [&_.ks-disclosure-summary]:flex-row-reverse [&_.ks-disclosure-summary]:justify-end [&_.ks-disclosure-summary]:gap-1 [&_.ks-disclosure-summary]:p-0 [&_.ks-disclosure-summary]:font-normal [&_.ks-disclosure-body]:p-0 [&_.ks-disclosure-body]:pt-1.5 [&_.ks-code-block]:p-2 [&_.ks-code-block]:text-[11px]",Wo=t=>t.values?t.columns?`${xt} ${Zt} ${Io}`:`${xt} ${Zt} ${$o}`:`${xt} ${Ho}`,jo=({details:t})=>e.createElement(e.Fragment,null,t.map((o,s)=>e.createElement("section",{key:s,className:Wo(o)},o.heading&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400"},o.heading),o.values&&e.createElement(qt,{rows:o.values,columns:o.columns}),o.code&&o.code.map(r=>e.createElement(Jt,{key:r.summary,summary:r.summary},e.createElement(Kt,null,r.code)))))),Qt=jo;var Go=({as:t="div",className:o,children:s,...r})=>e.createElement(t,{...r,className:A("ks-panel",o)},s),D=Go;var at=(t,o)=>({className:s,children:r,...n})=>e.createElement(t,{...n,className:A(o,s)},r),q=at("label","ks-label"),Na=at("p","ks-hint"),Ea=at("p","ks-error"),_a=at("span","ks-required");var Vo={width:320,padding:"14px 16px",overflowY:"auto",display:"flex",flexDirection:"column",fontSize:12},Fo={marginTop:"auto",paddingTop:12,display:"flex",flexDirection:"column",gap:8},Uo=({node:t,fields:o,holds:s,labels:r,explanations:n,recordLabels:a,recordExplanations:p,recordChoices:c,recordOutputsOf:l,choices:m,onSave:u,onDelete:x,onClose:h,onPickPicture:d,refusal:f,notice:_})=>{let[v,C]=E(t.config),[k,N]=E(t.picture_url);L(()=>N(t.picture_url),[t.id,t.picture_url]),L(()=>C(t.config),[t.id,t.config]);let O=b=>{C(b),JSON.stringify(b)!==JSON.stringify(t.config)&&u(b)};return e.createElement(D,{as:"aside",style:Vo,className:"max-sm:absolute max-sm:inset-0 max-sm:z-30 max-sm:!w-auto","data-inspector":!0},e.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8,marginBottom:12}},e.createElement("div",null,e.createElement("p",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},t.id," \xB7 ",t.type),e.createElement("h2",{style:{fontSize:15,fontWeight:600}},t.label)),e.createElement("button",{title:"Close",onClick:h,className:"text-gray-500 dark:text-gray-400",style:{border:"none",background:"none",cursor:"pointer",fontSize:18,lineHeight:1}},"\xD7")),f&&e.createElement("p",{className:"text-red-800 dark:text-red-400",style:{fontWeight:600,marginBottom:12},"data-refusal":!0},f),_&&!f&&e.createElement("p",{className:"text-emerald-800 dark:text-emerald-400",style:{fontWeight:600,marginBottom:12},"data-notice":!0},_),Object.entries(o).map(([b,B])=>e.createElement(q,{key:b},e.createElement("span",{style:{display:"block",marginBottom:3}},r[b]||b),B==="list"?e.createElement(Yt,{holds:s[b]||{},labels:a[b]||{},explanations:(p||{})[b],rows:v[b],choices:{...(c||{})[b],...(t.record_choices||{})[b]},outputsOf:(l||{})[b],onChange:T=>C({...v,[b]:T}),onSettle:T=>O({...v,[b]:T})}):e.createElement(st,{name:b,type:B,value:v[b],choices:m[b],pictureUrl:k,onChange:T=>C({...v,[b]:T}),onSettle:T=>O({...v,[b]:T}),onPick:async T=>{let H=await d(T);H&&(N(H.url),O({...v,[b]:H.reference}))}}),(n||{})[b]&&e.createElement(nt,{text:n[b]}))),e.createElement(Qt,{details:t.details||[]}),e.createElement("div",{style:Fo},(t.links||[]).length>0&&e.createElement("div",{style:{display:"flex",gap:8}},t.links.map(b=>e.createElement(w,{key:b.address,variant:"secondary",size:"sm",className:"flex-1",href:b.address},b.label))),e.createElement(w,{variant:"danger",size:"sm",className:"w-full",onClick:x},"Delete step")))},Rt=Uo;var Xo={width:240,boxSizing:"border-box",padding:"10px 14px",borderRadius:8,textAlign:"center",fontSize:12,cursor:"pointer"},Yo={minWidth:120,boxSizing:"border-box",padding:"8px 10px",borderRadius:6,textAlign:"center",fontSize:12,cursor:"pointer"},qo="border-2 border-dashed border-amber-500 bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300",Jo="border-2 border-dashed border-accent-600 bg-accent-50 text-accent-800 dark:bg-accent-950 dark:text-accent-200",Ko=({node:t,dragging:o,onFill:s,onDrop:r,compact:n=!1})=>e.createElement("div",{ref:t.ref,"data-placeholder":t.id,title:`Choose the step \u201C${t.label}\u201D should lead to`,onClick:s,onDragOver:a=>{o&&(a.preventDefault(),a.dataTransfer.dropEffect="move")},onDrop:a=>{a.preventDefault(),r()},className:o?Jo:qo,style:n?Yo:Xo},e.createElement("div",{style:{fontWeight:600}},t.label),e.createElement("div",{style:{fontSize:11}},o?"drop a step here":"leads nowhere yet \u2014 click to choose")),te=Ko;var Zo=({entries:t,at:o,onPick:s,onConnect:r,onDismiss:n,hideStepTypeCodes:a})=>e.createElement(D,{className:"shadow-lg",style:{position:"absolute",zIndex:9,top:o.y,left:o.x,width:210,padding:8,borderRadius:8}},e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{margin:"0 0 6px",fontSize:11}},"Add a step"),t.map(p=>e.createElement(w,{key:p.type,variant:"secondary",size:"sm",className:"w-full mb-1.5 flex-col",onClick:()=>s(p)},p.label,!a&&e.createElement("span",{className:"opacity-75",style:{display:"block",fontSize:11}},p.type))),r&&e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:r},"Connect to a step already here"),e.createElement(w,{variant:"secondary",size:"sm",className:"w-full",onClick:n},"Cancel")),ee=Zo;var Qo=t=>o=>o.label.toLowerCase().includes(t.trim().toLowerCase()),Ro=(t,o,s="")=>{let r=Object.values(o).flat(),n=Object.entries(o).map(([a,p])=>({heading:a,entries:p.map(c=>t.find(l=>l.type===c)).filter(Boolean)}));return[{heading:null,entries:t.filter(a=>!r.includes(a.type))},...n].map(a=>({...a,entries:a.entries.filter(Qo(s))})).filter(a=>a.entries.length>0)},tr={width:200,flex:"none",boxSizing:"border-box",padding:"14px 12px",gap:6,fontSize:12,overflowY:"auto",borderWidth:"0 1px 0 0"},er={fontSize:11,textTransform:"uppercase",letterSpacing:".04em",padding:"8px 4px 2px"},or={textAlign:"left",padding:"7px 9px",borderRadius:6,fontSize:12,cursor:"grab"},rr=({entries:t,groups:o,onPick:s,onCarry:r,onDrop:n})=>{let[a,p]=E("");return e.createElement(D,{as:"aside","aria-label":"Steps","data-step-list":!0,className:"hidden flex-col sm:flex",style:tr},e.createElement(I,{type:"search","aria-label":"Search steps",placeholder:"Search steps",value:a,onChange:c=>p(c.target.value),style:{marginBottom:6,fontSize:12}}),Ro(t,o,a).map(c=>e.createElement(e.Fragment,{key:c.heading||""},c.heading&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:er},c.heading),c.entries.map(l=>e.createElement(D,{as:"button",type:"button",key:l.type,"data-step-type":l.type,className:"bg-surface-50 dark:bg-surface-950",style:or,draggable:!0,onClick:()=>s(l),onDragStart:m=>{m.dataTransfer.effectAllowed="copyMove",m.dataTransfer.setData("text/plain",l.type),r(l)},onDragEnd:n},l.label)))))},oe=rr;var sr={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},re=({label:t,title:o,idle:s,enabled:r,onUse:n})=>e.createElement(w,{variant:"secondary",size:"sm",title:r?o:s,disabled:!r,onClick:n,style:{opacity:r?1:.4,cursor:r?"pointer":"default"}},t),nr=({undoable:t,redoable:o,onAdd:s,onUndo:r,onRedo:n})=>e.createElement("div",{style:{position:"absolute",top:16,left:16,zIndex:5,display:"flex",gap:8}},e.createElement(w,{variant:"secondary",className:"rounded-full",style:sr,title:"Add a step",onClick:s},"+"),e.createElement(re,{label:"\u21B6 Undo",title:"Undo the last change",idle:"Nothing to undo",enabled:t,onUse:r}),e.createElement(re,{label:"\u21B7 Redo",title:"Redo the change you undid",idle:"Nothing to redo",enabled:o,onUse:n})),se=nr;var ar=({type:t="info",title:o,message:s,onDismiss:r,className:n})=>e.createElement("div",{className:A("ks-alert",`ks-alert-${t}`,n),role:"alert"},e.createElement("div",{className:"ks-alert-body"},e.createElement("div",{className:"ks-alert-content"},o&&e.createElement("p",{className:"ks-alert-title"},o),e.createElement("p",{className:o?"ks-alert-message-titled":"ks-alert-message"},s)),r&&e.createElement("button",{type:"button",className:"ks-alert-dismiss","aria-label":"Dismiss",onClick:r},"\xD7"))),ne=ar;var ae=t=>{let o=t.map(s=>`\u201C${s.name}\u201D`).join(", ");return t.length===1?`${o} is not connected to the flow and will be removed. Remove it to go on, or cancel and connect it first.`:`${o} are not connected to the flow and will be removed. Remove them to go on, or cancel and connect them first.`};var ie=({version:t,published:o})=>t?o?o===t?`Version ${t} \xB7 live`:`Version ${t} \xB7 visitors still on ${o}`:`Version ${t} \xB7 never published`:"No version yet";var ir={width:280,padding:20,overflowY:"auto"},le={fontWeight:600,marginBottom:6,marginTop:14},yt={fontSize:12,marginBottom:4,lineHeight:1.4},de={display:"block",marginBottom:3},ce=(t,o,s)=>r=>{r.target.value!==(t[o]??"")&&s({[o]:r.target.value})},lr=({flow:t,changes:o,refusal:s,notice:r,publishNote:n,warning:a,onCreate:p,onPublish:c,onAccept:l,onDecline:m,onSaveDetails:u,onClose:x})=>e.createElement(D,{as:"aside",style:ir,"data-builder-panel":!0},e.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8}},e.createElement("h2",{style:{fontWeight:600},"data-flow-name":!0},t.title||t.slug),e.createElement("button",{title:"Close",onClick:x,className:"text-gray-500 dark:text-gray-400",style:{border:"none",background:"none",cursor:"pointer",fontSize:18,lineHeight:1}},"\xD7")),e.createElement("a",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:12,display:"block"},href:t.history_url,"data-history":!0},ie(t)),a?e.createElement("div",{style:{marginTop:14},"data-unconnected-warning":!0},e.createElement(ne,{type:"warning",className:"mb-1.5",message:ae(a.steps)}),e.createElement(w,{size:"sm",className:"w-full mb-1.5",onClick:l,"data-accept-removal":!0},a.path==="/publish"?"Remove and publish":"Remove and create version"),e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:m,"data-decline-removal":!0},"Cancel")):e.createElement("div",{style:{marginTop:14}},e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:p,"data-create-version":!0},"Create version"),e.createElement(w,{size:"sm",className:"w-full mb-1.5",onClick:c,"data-publish":!0},"Publish"),n&&e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12,lineHeight:1.4},"data-publish-note":!0},n)),s&&e.createElement("p",{className:"text-red-800 dark:text-red-400",style:{...yt,fontWeight:600,marginTop:8},"data-refusal":!0},s),r&&!s&&e.createElement("p",{className:"text-emerald-800 dark:text-emerald-400",style:{...yt,fontWeight:600,marginTop:8},"data-notice":!0},r),e.createElement("h2",{style:le},"Changes since the last version"),o.length===0?e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12}},"Nothing has changed."):o.map((h,d)=>e.createElement("p",{key:d,style:yt,"data-change":!0},h)),e.createElement("h2",{style:le},"Details"),e.createElement(q,null,e.createElement("span",{style:de},"Title"),e.createElement(I,{className:"mb-3",defaultValue:t.title??"",onBlur:ce(t,"title",u),"data-flow-title":!0})),e.createElement(q,null,e.createElement("span",{style:de},"Start label"),e.createElement(I,{className:"mb-3",defaultValue:t.start_label??"",onBlur:ce(t,"start_label",u),"data-flow-start-label":!0})),e.createElement("div",{style:{marginTop:16}},e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.definition_url,"data-definition":!0},"Definition"),e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.details_url,"data-details":!0},"Edit details"))),pe=lr;var dr=({variant:t="neutral",className:o,children:s,...r})=>e.createElement("span",{...r,className:A("ks-badge",`ks-badge-${t}`,o)},s),me=dr;var cr={center:"ks-tab-bar flex flex-wrap justify-center max-sm:flex-nowrap max-sm:overflow-x-auto max-sm:justify-start",start:"ks-tab-bar flex flex-wrap justify-start max-sm:flex-nowrap max-sm:overflow-x-auto"},pr={pills:"ks-tab-bar-pills",underline:"ks-tab-bar-underline"},mr="ks-tab text-sm transition max-sm:shrink-0 max-sm:whitespace-nowrap ks-tab-active",ur="ks-tab transition max-sm:shrink-0 max-sm:whitespace-nowrap ks-tab-active",fr=({shape:t,count:o})=>t?e.createElement("span",{className:"ks-tab-count"},o):e.createElement(me,{variant:"info"},o),gr=t=>typeof t=="string"?t!=="":t>0,hr=({tabs:t,value:o,onChange:s,align:r="center",shape:n,className:a})=>e.createElement("div",{className:a},e.createElement("div",{className:A(cr[r],pr[n])},t.map(p=>e.createElement("button",{key:p.value,type:"button",className:n?ur:mr,"data-active":p.value===o?"":void 0,onClick:()=>s(p.value)},p.label,gr(p.count)&&e.createElement(e.Fragment,null," ",e.createElement(fr,{shape:n,count:p.count}))))),t.find(p=>p.value===o)?.content),ue=hr;var xr={error:"text-red-800 dark:text-red-400",ok:"text-emerald-800 dark:text-emerald-400"},fe="mx-6 mb-6 flex max-h-[45%] flex-none flex-col overflow-y-auto rounded-lg max-sm:m-0 max-sm:max-h-none max-sm:rounded-none [&_.ks-tab-bar]:mb-0 [&_.ks-tab-bar]:px-2",yr="max-sm:absolute max-sm:inset-0 max-sm:z-20",xe={padding:"10px 14px",fontSize:12,display:"flex",flexDirection:"column",gap:6},ge={display:"flex",gap:8,textAlign:"left"},he={flexShrink:0,whiteSpace:"nowrap"},br=({check:t,onSelect:o})=>{let s=e.createElement(e.Fragment,null,e.createElement("span",{className:xr[t.level],style:{...he,fontWeight:500}},t.level),t.node&&e.createElement("span",{className:"font-mono",style:he},t.node),e.createElement("span",null,t.sentence));return t.node?e.createElement("button",{type:"button","data-check-row":!0,"data-step-id":t.node,style:{...ge,border:"none",background:"none",padding:0,cursor:"pointer",font:"inherit",color:"inherit"},onClick:()=>o(t.node)},s):e.createElement("div",{"data-check-row":!0,style:ge},s)},vr=({checks:t,onSelect:o})=>e.createElement("div",{style:xe},t.map((s,r)=>e.createElement(br,{key:r,check:s,onSelect:o}))),wr=()=>typeof window<"u"&&!!window.matchMedia?.("(max-width: 639px)").matches,kr=({checks:t,tabs:o,onSelect:s,opened:r=wr()?null:"validation"})=>{let[n,a]=E(r);return e.createElement(D,{as:"section","aria-label":"Validation and tests","data-drawer":!0,className:n?`${fe} ${yr}`:fe},e.createElement(ue,{align:"start",shape:"underline",value:n,onChange:p=>a(p===n?null:p),tabs:[{value:"validation",label:"Validation",count:t.filter(p=>p.level==="error").length,content:e.createElement(vr,{checks:t,onSelect:s})},...o.map(p=>({value:p.label,label:p.label,count:p.count??"",content:e.createElement("div",{"data-drawer-content":!0,style:xe,dangerouslySetInnerHTML:{__html:p.content}})}))]}))},ye=kr;var be={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},ve=t=>({opacity:t?1:0,transition:"opacity .12s"}),Sr=({link:t,onInsert:o,onRemove:s,onDrop:r,dragging:n,alwaysShowInsertButtons:a})=>{let[p,c]=E(!1),l=p||n;return e.createElement("div",{"data-connector":`${t.source}-${t.target}`,style:{position:"absolute",left:t.midX-34,top:t.midY-20,width:68,height:40,zIndex:4},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onDragEnter:()=>c(!0),onDragLeave:()=>c(!1),onDragOver:m=>{m.preventDefault(),m.dataTransfer.dropEffect="move"},onDrop:m=>{m.preventDefault(),c(!1),r()}},e.createElement("div",{style:{display:"flex",gap:4,justifyContent:"center",alignItems:"center",height:"100%"}},e.createElement(w,{variant:"secondary",title:n?"Move the step here":"Insert a step here",onClick:o,className:"rounded-full data-[over=true]:ring-2 data-[over=true]:ring-accent-600","data-over":!!(n&&p),style:{...be,...ve(l||a)}},"+"),!n&&e.createElement(w,{variant:"danger",title:"Remove this connection",onClick:s,className:"rounded-full",style:{...be,...ve(l)}},"\xD7")))},we=Sr;var Cr=({links:t,extent:o,dragging:s,onInsert:r,onRemove:n,onDrop:a,alwaysShowInsertButtons:p})=>e.createElement(e.Fragment,null,e.createElement("svg",{width:o.width,height:o.height,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:1}},e.createElement("defs",null,e.createElement("marker",{id:"easy_flow-arrow",viewBox:"0 0 10 10",refX:"8",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto"},e.createElement("path",{d:"M 0 0 L 10 5 L 0 10 z",className:"fill-gray-400 dark:fill-zinc-500"}))),t.map(c=>e.createElement("path",{key:c.id,"data-link":c.id,className:"stroke-gray-400 dark:stroke-zinc-500",fill:"none",strokeWidth:"1.5",markerEnd:"url(#easy_flow-arrow)",d:c.path}))),t.filter(c=>c.label).map(c=>e.createElement("div",{key:`${c.id}-label`,"data-link-label":c.id,className:"bg-surface-50 text-gray-500 dark:bg-surface-950 dark:text-gray-400",style:{position:"absolute",left:c.midX+(p?2:-10),top:c.midY-18,zIndex:3,fontSize:11,padding:"0 3px"}},c.label)),t.filter(c=>!c.placeholder).map(c=>e.createElement(we,{key:c.id,link:c,dragging:!!s,alwaysShowInsertButtons:p,onInsert:()=>r(c),onRemove:()=>n(c),onDrop:()=>a(c)}))),ke=Cr;var bt={width:22,height:22,padding:0,fontSize:14,lineHeight:"14px"},Se="opacity-0 transition-opacity group-data-[over=true]:opacity-100",Nr={display:"flex",alignItems:"center",justifyContent:"flex-end",gap:2,height:"100%"},Er=({link:t,onInsert:o,onRemove:s,onDrop:r,alwaysShowInsertButtons:n,dragging:a,shown:p=!1,className:c="",style:l,children:m})=>e.createElement("div",{"data-joint":t?.id,className:`group ${c}`.trim(),style:l,onMouseEnter:u=>{u.currentTarget.dataset.over="true"},onMouseLeave:u=>{delete u.currentTarget.dataset.over},onDragOver:u=>{t&&r&&(u.preventDefault(),u.dataTransfer.dropEffect="move")},onDrop:u=>{t&&(u.preventDefault(),r(t))}},m,t&&o&&e.createElement("div",{style:Nr},e.createElement(w,{variant:"secondary",title:"Insert a step here",onClick:u=>o(t,u),className:`rounded-full ${n?"opacity-100":Se}`,style:a?{...bt,opacity:1}:bt},"+"),e.createElement(w,{variant:"danger",title:"Remove this connection",onClick:()=>s(t),className:`rounded-full ${p?"opacity-100":Se}`,style:bt},"\xD7"))),it=Er;var _r=(t,o)=>{let s=new Map(t.map(p=>[p,0])),r=new Map(t.map(p=>[p,[]])),n=new Map(t.map(p=>[p,0]));o.forEach(p=>{r.get(p.source).push(p.target),n.set(p.target,n.get(p.target)+1)});let a=t.filter(p=>n.get(p)===0);for(let p=0;p<a.length;p++){let c=a[p];r.get(c).forEach(l=>{s.set(l,Math.max(s.get(l),s.get(c)+1)),n.set(l,n.get(l)-1),n.get(l)===0&&a.push(l)})}return s},wt=(t,o)=>{let s=new Map(t.map(r=>[r,[]]));return o.forEach(r=>s.get(r.source).push(r)),s},Ar=(t,o)=>{let s=wt(t,o),r=new Set(o.map(c=>c.target)),n=new Map,a=new Set,p=c=>{let l=[[c,0]];for(n.set(c,"open");l.length>0;){let m=l[l.length-1],u=s.get(m[0])[m[1]++];u?n.get(u.target)==="open"?a.add(u):n.has(u.target)||(n.set(u.target,"open"),l.push([u.target,0])):(n.set(m[0],"done"),l.pop())}};return t.filter(c=>!r.has(c)).forEach(p),t.forEach(c=>{n.has(c)||p(c)}),a},zr=(t,o,s)=>{let r=[];t.forEach(l=>{var m;return(r[m=s.get(l)]||(r[m]=[])).push(l)});let n=wt(t,o),a=new Map;n.forEach(l=>l.forEach((m,u)=>a.set(m,(u+1)/(l.length+1))));let p=new Map(t.map(l=>[l,[]]));o.forEach(l=>p.get(l.target).push(l));let c=new Map;return r.forEach(l=>{let m=new Map(l.map(u=>{let x=p.get(u),h=x.reduce((d,f)=>d+c.get(f.source)+a.get(f),0);return[u,x.length>0?h/x.length:1/0]}));l.sort((u,x)=>m.get(u)===m.get(x)?0:m.get(u)<m.get(x)?-1:1),l.forEach((u,x)=>c.set(u,x))}),c};var vt=(t,o,s)=>{let r=[];return t.forEach((n,a)=>{r[a]=a===0?s:r[a-1]+t[a-1]+o}),r},Tr=(t,o)=>t.length>0?t[t.length-1]+o[o.length-1]:0,Mr=t=>{let o=[t];for(let s=1;s*2<=t.length;s*=2){let r=o[o.length-1];o.push(r.slice(0,t.length-s*2+1).map((n,a)=>Math.max(n,r[a+s])))}return(s,r)=>{let n=Math.floor(Math.log2(r-s+1));return Math.max(o[n][s],o[n][r-(1<<n)+1])}},Ce=(t,o,s,r)=>{let n=Ar(t,o),a=o.filter(g=>!n.has(g)),p=_r(t,a),c=zr(t,a,p),l=[],m=[];t.forEach(g=>{var S;l[p.get(g)]=Math.max(l[p.get(g)]||0,s(g).width),(m[S=p.get(g)]||(m[S]=[]))[c.get(g)]=g});let u=g=>p.get(g.target)>p.get(g.source)+1,x=g=>{let S=new Map;return g.forEach(M=>{S.has(M.target)||S.set(M.target,S.size)}),S},h=x(o.filter(g=>n.has(g))),d=x(a.filter(u)),f=vt(l,64,r.left),_=r.top+h.size*14,v=new Map,C=m.map(g=>{let S=g.map(M=>s(M).height);return vt(S,24,_).forEach((M,W)=>v.set(g[W],M)),Tr(vt(S,24,_),S)}),k=Mr(C),N=Object.fromEntries(t.map(g=>[g,{column:p.get(g),row:c.get(g),x:f[p.get(g)],y:v.get(g),width:s(g).width,height:s(g).height}])),O=new Map;a.filter(u).forEach(g=>O.set(g.target,Math.max(O.get(g.target)||0,k(p.get(g.source)+1,p.get(g.target)-1))));let b=g=>n.has(g)?r.top+(h.size-1-h.get(g.target))*14:u(g)?O.get(g.target)+(d.get(g.target)+1)*14:null,B=g=>N[g].y+(s(g).arrives??N[g].height/2),T=g=>b(g)??B(g.target),H=new Map;wt(t,o).forEach(g=>[...g].sort((S,M)=>T(S)-T(M)).forEach((S,M)=>H.set(S,(M+1)/(g.length+1))));let pt=g=>{let S=N[g.source],M=N[g.target],W=S.y+S.height*H.get(g),U=B(g.target),X=f[S.column]+l[S.column]+40,V=b(g),Q=[[S.x+S.width,W],[X,W]],F=[[M.x-64+40,U],[M.x,U]];return{...g.drawn,points:V===null?[...Q,[X,U],F[1]]:[...Q,[X,V],[F[0][0],V],...F]}},K=o.map(pt),Z=[...Object.values(N).map(g=>[g.x+g.width,g.y+g.height]),...K.flatMap(g=>g.points)].reduce(([g,S],[M,W])=>[Math.max(g,M),Math.max(S,W)],[0,0]);return{places:N,links:K,width:Z[0]+r.right,height:Z[1]+r.bottom}},J="\0entry";var Or={left:44,top:40,right:20,bottom:40},Br={left:0,top:8,right:16,bottom:12},lt=(t,o,{heights:s={}}={})=>{let r=new Set(t.map(d=>d.id)),n=new Map(t.flatMap(d=>(d.holds||[]).filter(f=>r.has(f)).map(f=>[f,d.id]))),a=new Map([[null,{ids:[],edges:[]}]]);t.filter(d=>d.holds).forEach(d=>a.set(d.id,{ids:[J],edges:[]})),t.forEach(d=>a.get(n.get(d.id)??null).ids.push(d.id)),o.filter(d=>r.has(d.source)&&r.has(d.target)).forEach(d=>{let f=n.get(d.target);f&&f===d.source?a.get(f).edges.push({source:J,target:d.target,drawn:d}):f&&f===n.get(d.source)?a.get(f).edges.push({source:d.source,target:d.target,drawn:d}):a.get(null).edges.push({source:n.get(d.source)??d.source,target:f??d.target,drawn:d})});let p=d=>({width:184,height:s[d]||64}),c=new Map([...a].filter(([d])=>d).map(([d,f])=>[d,Ce(f.ids,f.edges,_=>_===J?{width:0,height:64}:p(_),Br)])),l=d=>s[d]||24,m=d=>{let f=c.get(d);return f?{width:f.width,height:l(d)+f.height,arrives:l(d)+f.places[J].y+64/2}:p(d)},u=Ce(a.get(null).ids,a.get(null).edges,m,Or),x={...u.places},h=[...u.links];return c.forEach((d,f)=>{let _=u.places[f],[v,C]=[_.x,_.y+l(f)];Object.entries(d.places).filter(([k])=>k!==J).forEach(([k,N])=>{x[k]={...N,x:N.x+v,y:N.y+C}}),d.links.forEach(k=>h.push({...k,points:k.points.map(([N,O])=>[N+v,O+C])}))}),{places:x,links:h,width:u.width,height:u.height}};var Dr={display:"flex",flexDirection:"column",gap:14,padding:"64px 16px 24px"},Lr={display:"flex",flexDirection:"column",gap:10,padding:"8px 10px",borderRadius:8},Pr={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,minHeight:26,paddingLeft:12,fontSize:11},Ir=t=>(o,s)=>t[o.id].column-t[s.id].column||t[o.id].row-t[s.id].row,$r=t=>t?.placeholder?"nowhere yet":t?.label,Hr=({node:t,leaving:o,named:s,draw:r,joints:n})=>e.createElement("div",{"data-step-row":t.id},r(t),o.map(a=>e.createElement(it,{key:a.id,link:a,...n,alwaysShowInsertButtons:!0,shown:!0,className:"border-l border-gray-300 text-gray-500 dark:border-zinc-600 dark:text-gray-400",style:Pr},e.createElement("span",null,[a.label,"\u2192",s.get(a.target)].filter(Boolean).join(" "))))),Wr=({nodes:t,edges:o,draw:s,joints:r,children:n,style:a})=>{let{places:p}=lt(t,o),c=new Map(t.map(d=>[d.id,$r(d)])),l=new Map(t.map(d=>[d.id,[]]));o.forEach(d=>{l.has(d.source)&&c.has(d.target)&&l.get(d.source).push(d)});let m=new Map(t.flatMap(d=>(d.holds||[]).map(f=>[f,d.id]))),u=[...t].sort(Ir(p)),x=new Map;u.filter(d=>m.has(d.id)).forEach(d=>{x.has(m.get(d.id))||x.set(m.get(d.id),[]),x.get(m.get(d.id)).push(d)});let h=d=>e.createElement(Hr,{key:d.id,node:d,leaving:l.get(d.id),named:c,draw:s,joints:r});return e.createElement("div",{"data-flow-rows":!0,style:{...Dr,...a}},n,u.filter(d=>!m.has(d.id)).map(d=>d.holds?e.createElement("div",{key:d.id,"data-group-box":d.id,className:"border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60",style:Lr},h(d),(x.get(d.id)||[]).map(h)):h(d)))},Ne=Wr;var jr={display:"flex",flexDirection:"column",alignItems:"flex-start",gap:14,padding:"64px 0 0"},Gr={position:"absolute",zIndex:3,maxWidth:56,fontSize:10,lineHeight:"13px",pointerEvents:"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Vr=t=>t.map(([o,s],r)=>`${r===0?"M":"L"} ${o} ${s}`).join(" "),Fr=t=>Object.fromEntries(Object.entries(t).filter(([,o])=>o?.firstElementChild).map(([o,s])=>[o,s.firstElementChild.offsetHeight])),Ur=(t,o)=>Object.keys(o).some(s=>t[s]!==o[s]),Xr=({nodes:t,edges:o,draw:s,joints:r})=>{let[n,a]=E({}),p=Y({}),c=P(()=>lt(t,o,{heights:n}),[t,o,n]);R(()=>{let m=Fr(p.current);Ur(n,m)&&a({...n,...m})});let l=m=>u=>{p.current[m]=u};return e.createElement("div",{"data-flow-graph":!0,style:{position:"relative",flex:"none",width:c.width,height:c.height}},e.createElement("svg",{width:c.width,height:c.height,style:{position:"absolute",top:0,left:0,pointerEvents:"none"}},e.createElement("defs",null,e.createElement("marker",{id:"easy_flow-graph-arrow",viewBox:"0 0 10 10",refX:"8",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto"},e.createElement("path",{d:"M 0 0 L 10 5 L 0 10 z",className:"fill-gray-400 dark:fill-zinc-500"}))),c.links.map(m=>e.createElement("path",{key:m.id,"data-link":m.id,d:Vr(m.points),fill:"none",strokeWidth:"1.5",className:"stroke-gray-400 dark:stroke-zinc-500",markerEnd:"url(#easy_flow-graph-arrow)"}))),t.map(m=>{let u=c.places[m.id];return m.holds?e.createElement("div",{key:m.id,ref:l(m.id),"data-group-box":m.id,className:"border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60",style:{position:"absolute",left:u.x,top:u.y,width:u.width,height:u.height,boxSizing:"border-box",borderRadius:8}},e.createElement("div",{style:{padding:"4px 10px"}},s(m))):e.createElement("div",{key:m.id,ref:l(m.id),style:{position:"absolute",left:u.x,top:u.y,width:u.width,zIndex:2}},s(m))}),c.links.filter(m=>m.label).map(m=>e.createElement("div",{key:`${m.id}-label`,"data-link-label":m.id,title:m.label,className:"text-gray-500 dark:text-gray-400",style:{...Gr,left:m.points[0][0]+6,top:m.points[0][1]-14}},m.label)),r.onInsert&&c.links.filter(m=>!m.placeholder).map(m=>e.createElement(it,{key:m.id,link:m,...r,style:{position:"absolute",left:m.points[0][0],top:m.points[0][1]-12,width:62,height:24,zIndex:3}})))},_e="(min-width: 640px)",Yr=()=>typeof window>"u"||!window.matchMedia||window.matchMedia(_e).matches,qr=()=>{let[t,o]=E(Yr);return L(()=>{if(!window.matchMedia)return;let s=window.matchMedia(_e),r=()=>o(s.matches);return s.addEventListener("change",r),()=>s.removeEventListener("change",r)},[]),t},Jr=({nodes:t,edges:o,draw:s,joints:r,children:n,style:a})=>qr()?e.createElement("div",{"data-flow-rows":!0,style:{...jr,...a}},n,e.createElement(Xr,{nodes:t,edges:o,draw:s,joints:r})):e.createElement(Ne,{nodes:t,edges:o,draw:s,joints:r,style:a},n),dt=Jr;var ze="Your change was not saved because the server could not be reached.",Kr="Your change was saved, but the canvas could not be refreshed. Reload the page to see it.",Ae=async({base:t,fetch:o,onFlow:s,onError:r})=>{let n=await o(t+".json",{headers:{Accept:"application/json"}}).catch(()=>null),a=n?.ok?await n.json().catch(()=>null):null;return a?s(a):r(Kr)},Te=({base:t,token:o,fetch:s,onFlow:r,onError:n,onNotice:a,onWarning:p=()=>{}})=>async(c,l,m)=>{let u={base:t,fetch:s,onFlow:r,onError:n},x=await s(t+c,{method:l,headers:{"Content-Type":"application/json","X-CSRF-Token":o},body:m&&JSON.stringify(m)}).catch(()=>null);if(!x)return a(null),n(ze);let h=await x.json().catch(()=>({}));return h.unconnected?(a(null),n(null),p({path:c,steps:h.unconnected}),Ae(u)):(p(null),x.ok?(n(null),a(h.notice||null),Ae(u)):(a(null),n(h.error||"That change was refused")))},Me=({base:t,token:o,fetch:s,onError:r})=>async n=>{let a=new FormData;a.append("picture",n);let p=await s(t+"/pictures",{method:"POST",headers:{"X-CSRF-Token":o},body:a}).catch(()=>null);if(!p)return r(ze),null;let c=await p.json().catch(()=>({}));return p.ok?(r(null),c):(r(c.error||"That picture was refused"),null)};var Zr=(t,o,s)=>{let[r,n]=E(s),[a,p]=E(null),[c,l]=E(null),[m,u]=E(null),x=P(()=>Te({base:t,token:o,fetch:(...d)=>window.fetch(...d),onFlow:n,onError:p,onNotice:l,onWarning:u}),[t,o]),h=P(()=>Me({base:t,token:o,fetch:(...d)=>window.fetch(...d),onError:p}),[t,o]);return{flow:r,error:a,notice:c,warning:m,setWarning:u,send:x,pickPicture:h}},Oe=Zr;var ct=(t,o,s,r)=>{let n=t.left-s.left+r.scrollLeft,a=t.top-s.top+r.scrollTop;return o==="left"?{x:n,y:a+t.height/2}:o==="right"?{x:n+t.width,y:a+t.height/2}:o==="top"?{x:n+t.width/2,y:a}:{x:n+t.width/2,y:a+t.height}},Qr=(t,o,s)=>s&&o==="top"?{x:t.x,y:s.top}:t,Rr=(t,o)=>o==="top"?{x:t.x,y:t.y-3}:o==="left"?{x:t.x-3,y:t.y}:o==="right"?{x:t.x+3,y:t.y}:{x:t.x,y:t.y+3},ts=(t,o,s,r,n)=>{let a={straight:`M ${o.x} ${o.y} L ${s.x} ${s.y}`,turn:`M ${o.x} ${o.y} H ${s.x} V ${s.y}`,lane:`M ${o.x} ${o.y} V ${r} H ${s.x} V ${s.y}`,detour:`M ${o.x} ${o.y} H ${n} V ${s.y} H ${s.x}`}[t.route];return{...t,path:a,midX:t.route==="detour"?n:(o.x+s.x)/2,midY:t.route==="lane"?r:(o.y+s.y)/2}},es=(t,o,s,r)=>{let[n,a]=E([]),[p,c]=E({width:"100%",height:"100%"}),[l,m]=E([]);return R(()=>{let u=()=>{let h=o.current?.getBoundingClientRect();if(!h)return;c({width:o.current.scrollWidth,height:o.current.scrollHeight});let d=t.nodes.filter(f=>f.holds&&!f.loose&&s.current[f.id]).map(f=>{let _=s.current[f.id],v=_.getBoundingClientRect(),C=f.holds.flatMap(N=>s.current[N]?[s.current[N].getBoundingClientRect()]:[]),k=[{left:v.left,top:v.top,width:Math.max(v.width,_.scrollWidth),height:v.height},...C];return{id:f.id,bounds:It(k,h,o.current)}});m(d),a(t.edges.flatMap(f=>{let _=s.current[f.source]?.getBoundingClientRect(),v=s.current[f.target]?.getBoundingClientRect();if(!_||!v)return[];let C=ct(_,f.leaves,h,o.current),k=d.find(B=>B.id===f.target)?.bounds,N=Rr(Qr(ct(v,f.enters,h,o.current),f.enters,k),f.enters),O=(ct(_,"bottom",h,o.current).y+ct(v,"top",h,o.current).y)/2,b=f.leaves==="left"?Math.min(C.x,N.x)-28:Math.max(C.x,N.x)+28;return[ts(f,C,N,O,b)]}))};u(),window.addEventListener("resize",u);let x=new ResizeObserver(u);return o.current&&x.observe(o.current),()=>{window.removeEventListener("resize",u),x.disconnect()}},r),{links:n,extent:p,boxes:l}},Be=es;var De=(t,o)=>{let s=new Set(o),r=t,n=2;for(;s.has(r);)r=`${t}_${n++}`;return r};var Le=({send:t,onPress:o})=>s=>{let r=s.target.closest?.("[data-bar-action]");r&&(r.closest("details")?.removeAttribute("open"),o(),r.dataset.barPath&&t(r.dataset.barPath,"POST"))};var rs=8,ss={display:"flex",height:"100%",minHeight:0,fontSize:13,position:"relative"},ns={flex:1,minWidth:0,display:"flex",flexDirection:"column",position:"relative"},as={flex:1,minHeight:0,overflow:"auto",position:"relative"},Ie={position:"absolute",top:56,left:16,zIndex:5,width:264,padding:12,borderRadius:8},is={...Ie,position:"static",alignSelf:"flex-start"},ls={display:"grid",rowGap:64,columnGap:0,padding:40,justifyContent:"center",position:"relative"},$e={position:"sticky",zIndex:8,top:8,margin:"8px auto 0",width:"fit-content",padding:"6px 12px",borderRadius:6,fontSize:12},ds=({port:t,onCancel:o})=>e.createElement("div",{className:"bg-accent-100 text-accent-800 dark:bg-accent-900 dark:text-accent-100",style:$e},"Choose the step \u201C",t||"next","\u201D should lead to \u2014 ",e.createElement("button",{onClick:o,className:"text-accent-800 underline dark:text-accent-100",style:{border:"none",background:"none",cursor:"pointer",fontSize:12,padding:0}},"cancel")),cs=({message:t})=>e.createElement("p",{"data-canvas-error":!0,className:"bg-red-50 text-red-800 dark:bg-red-950 dark:text-red-200",style:$e},t),ps=({base:t,token:o,initial:s})=>{let{flow:r,error:n,notice:a,warning:p,setWarning:c,send:l,pickPicture:m}=Oe(t,o,s),[u,x]=E(null),[h,d]=E(null),[f,_]=E(null),[v,C]=E(null),[k,N]=E(null),[O,b]=E(!1),B=Y({}),T=Y(null);L(()=>{let i=Le({send:l,onPress:()=>{x(null),b(!0)}});return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[l]),L(()=>{if(!O){c(null);return}let i=y=>{y.target.isConnected&&!y.target.closest("[data-builder-panel], [data-open-panel], [data-bar-action]")&&b(!1)};return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[O]),L(()=>{document.dispatchEvent(new CustomEvent("easy_flow:flow-named",{detail:r.flow?.title||r.flow?.slug}))},[r.flow?.title,r.flow?.slug]),L(()=>{document.dispatchEvent(new CustomEvent("easy_flow:flow-status",{detail:{status:r.flow?.status,publishes:r.flow?.publishes}}))},[r.flow?.status,r.flow?.publishes]);let H=P(()=>Object.fromEntries(r.nodes.map(i=>[i.id,i])),[r.nodes]),{links:pt,extent:K,boxes:mt}=Be(r,T,B,[r,u,H]),Z=P(()=>{let i={};return r.violations.forEach(y=>{var z;return(i[z=y.node]||(i[z]=[])).push(y)}),i},[r.violations]),g=r.direction==="left_to_right",S=P(()=>r.nodes.filter(i=>!i.loose),[r.nodes]),M=r.nodes.filter(i=>i.loose),W=P(()=>{let i={};return r.edges.forEach(y=>{var z;return(i[z=y.source]||(i[z]=[])).push(y.label||null)}),i},[r.edges]),U=Math.max(0,...S.map(i=>i.row))+1,X=Math.max(0,...S.map(i=>i.column))+1,V=i=>{if(!f)return;let[y,z]=f;_(null),y!==i&&l("/edges","POST",{from:y,to:i,on:z||null})},Q=i=>{if(i.isDefaultPrevented()||!v)return;i.preventDefault();let y=v;C(null);let z=T.current.getBoundingClientRect(),_t=$t(mt,{x:i.clientX-z.left+T.current.scrollLeft,y:i.clientY-z.top+T.current.scrollTop}),Ue=r.nodes.find(Xe=>Xe.holds?.includes(y))?.id||null;_t!==Ue&&l(`/steps/${y}/group`,"PATCH",{group:_t})},F=i=>[...r.palette,...r.unoffered||[]].find(y=>y.type===i?.type),j=r.nodes.find(i=>i.id===u),$=F(j),ut=(i,y={})=>l("/steps","POST",{id:De(i.type,r.nodes.map(z=>z.id)),type:i.type,from:y.from,to:y.to,on:y.on}),kt=i=>{let[y,z]=[k,v];N(null),C(null),y?ut(y,{from:i.source,to:i.target}):z&&l("/steps/"+z+"/move","PATCH",{from:i.source,to:i.target})},St=i=>{let y=T.current.getBoundingClientRect();return{x:i.clientX-y.left+T.current.scrollLeft+8,y:i.clientY-y.top+T.current.scrollTop+8}},Ct=(i,y)=>({node:{...i,ref:z=>{B.current[i.id]=z},violations:Z[i.id]||[],connected:y},selected:i.id===u,armed:f&&f[0]===i.id?f[1]:null,connecting:!!f&&f[0]!==i.id,onSelect:()=>f?V(i.id):x(i.id),onOpen:z=>window.location.assign(z),onDragStart:()=>C(i.id),onDragEnd:()=>C(null),hideStepTypeCodes:r.hide_step_type_codes,compact:g}),Nt=i=>e.createElement(e.Fragment,null,i.placeholder&&e.createElement(te,{node:{...i,ref:y=>{B.current[i.id]=y}},dragging:!!v,compact:g,onFill:()=>d({from:i.from,on:i.on,at:{x:16,y:52}}),onDrop:()=>{let y=v;C(null),y&&l("/edges","POST",{from:i.from,to:y,on:i.on})}}),i.holds&&e.createElement(et,{node:{...i,ref:y=>{B.current[i.id]=y}},header:ot(i,F(i),r.hide_step_type_codes),compact:g,onSelect:()=>f?V(i.id):x(i.id)}),!i.placeholder&&!i.holds&&e.createElement(gt,{...Ct(i,W[i.id]||[]),onArm:(y,z)=>d({from:i.id,on:y,at:St(z)})})),Et=M.length>0&&e.createElement("div",{"data-loose":!0,className:"border border-dashed border-gray-300 bg-gray-50 dark:border-zinc-700 dark:bg-zinc-900",style:g?is:Ie},e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginBottom:6}},"Not in the flow yet \u2014 drag one onto a connection"),M.map(i=>e.createElement("div",{key:i.id,style:{marginBottom:8}},e.createElement(gt,{...Ct(i,[]),onArm:(y,z)=>{z.stopPropagation(),_([i.id,y])}}))));return e.createElement("div",{className:"text-gray-900 dark:text-gray-100",style:ss,onMouseUp:()=>C(null),onKeyDown:i=>{i.key==="Escape"&&(x(null),_(null),d(null))},tabIndex:-1},e.createElement(oe,{entries:r.palette,groups:r.step_groups||{},onPick:i=>ut(i),onCarry:N,onDrop:()=>N(null)}),e.createElement("div",{className:"bg-surface-50 dark:bg-surface-950",style:ns},e.createElement("div",{ref:T,style:as,onClick:i=>{i.target===T.current&&(x(null),_(null),b(!1))},onDragOver:i=>{v&&i.preventDefault()},onDrop:Q},f&&e.createElement(ds,{port:f[1],onCancel:()=>_(null)}),n&&!O&&!j&&e.createElement(cs,{message:n}),e.createElement(se,{undoable:r.undoable,redoable:r.redoable,onAdd:()=>d({at:{x:16,y:52}}),onUndo:()=>{x(null),l("/undo","POST")},onRedo:()=>{x(null),l("/redo","POST")}}),!g&&mt.map(i=>e.createElement(Pt,{key:i.id,id:i.id,bounds:i.bounds,onDrop:()=>{let y=v;C(null),y&&l(`/steps/${y}/group`,"PATCH",{group:i.id})}})),!g&&e.createElement(ke,{links:Ht(pt,r.nodes),extent:K,dragging:v||k,alwaysShowInsertButtons:r.always_show_insert_buttons,onInsert:i=>d({from:i.source,to:i.target,at:{x:i.midX+30,y:i.midY}}),onRemove:i=>{x(null),l("/edges","DELETE",{from:i.source,to:i.target})},onDrop:kt}),!g&&Et,g&&e.createElement(dt,{nodes:S,edges:r.edges,draw:Nt,joints:{alwaysShowInsertButtons:r.always_show_insert_buttons,dragging:!!(v||k),onInsert:(i,y)=>d({from:i.source,to:i.target,at:St(y)}),onRemove:i=>{x(null),l("/edges","DELETE",{from:i.source,to:i.target})},onDrop:kt}},Et),!g&&e.createElement("div",{style:{...ls,gridTemplateColumns:`repeat(${X+1}, ${280/2}px)`,gridTemplateRows:`repeat(${U}, auto)`}},S.map(i=>e.createElement("div",{key:i.id,style:{gridRow:i.row+1,gridColumn:`${i.column+1} / span 2`,zIndex:2,marginTop:Wt(i,r.nodes)?rs-64:0}},Nt(i)))),h&&e.createElement(ee,{entries:r.palette,at:h.at,onDismiss:()=>d(null),hideStepTypeCodes:r.hide_step_type_codes,onConnect:h.on!==void 0?()=>{_([h.from,h.on]),d(null)}:null,onPick:i=>{let y=h;d(null),ut(i,y)}})),e.createElement(ye,{checks:r.checks||[],tabs:r.drawer_tabs||[],onSelect:x})),O&&!j&&e.createElement(pe,{flow:r.flow||{},changes:r.changes||[],refusal:n,notice:a,publishNote:r.publish_note,warning:p,onClose:()=>b(!1),onCreate:()=>l("/versions","POST"),onPublish:()=>l("/publish","POST"),onAccept:()=>l(p.path,"POST",{remove_unconnected:p.steps.map(i=>i.id)}),onDecline:()=>c(null),onSaveDetails:i=>l("/details","PATCH",{flow:i})}),j&&e.createElement(Rt,{node:j,fields:$?.fields||{},holds:$?.records||{},labels:$?.labels||{},explanations:$?.explanations||{},recordLabels:$?.record_labels||{},recordExplanations:$?.record_explanations||{},recordChoices:$?.record_choices||{},recordOutputsOf:$?.record_outputs_of||{},choices:jt(j,$),onClose:()=>x(null),onSave:i=>l(`/steps/${j.id}`,"PATCH",{config:i}),onPickPicture:m,refusal:n,notice:a,onDelete:()=>{x(null),l(`/steps/${j.id}`,"DELETE")}}))},He=ps;var ms={display:"block",minWidth:118,boxSizing:"border-box",borderRadius:6,padding:"8px 10px",textDecoration:"none"},We={fontSize:12,fontWeight:500,lineHeight:1.3},je={done:"border-green-600 bg-green-50 dark:border-green-500 dark:bg-green-950",paused:"border-amber-500 bg-amber-50 dark:border-amber-400 dark:bg-amber-950",pending:"border-gray-300 bg-white text-gray-500 dark:border-zinc-700 dark:bg-zinc-900 dark:text-gray-400",failed:"border-red-600 bg-red-50 dark:border-red-500 dark:bg-red-950"},Ge={done:"text-green-700 dark:text-green-400",paused:"text-amber-800 dark:text-amber-300",pending:"text-gray-500 dark:text-gray-400",failed:"text-red-700 dark:text-red-400"},us="ring-2 ring-accent-600 ring-offset-2 dark:ring-offset-zinc-950",fs=({node:t,selected:o=!1})=>{let s=t.address?"a":"div",r=t.begins_here||t.ends_here;return e.createElement(s,{"data-step":t.id,href:t.address||void 0,className:`${t.state==="paused"?"border-2":"border"} ${je[t.state]||je.pending}${o?` ${us}`:""}`,style:ms},!r&&e.createElement("div",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},t.type),e.createElement("div",{style:r?{...We,textAlign:"center"}:We},t.label,t.version&&e.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{fontWeight:400,marginLeft:4}},t.version)),t.status&&e.createElement("div",{className:Ge[t.state]||Ge.pending,style:{fontSize:11}},t.status))},Ve=fs;var gs={gap:12,padding:0,maxWidth:"100%",overflowX:"auto"},hs=({nodes:t,edges:o,selected:s})=>e.createElement(dt,{nodes:t,edges:o,joints:{},style:gs,draw:r=>r.holds?e.createElement(et,{node:r,header:ot(r,r,!1),compact:!0}):e.createElement(Ve,{node:r,selected:r.id===s})}),Fe=hs;ft("easy_flow/flow-editor",He);ft("easy_flow/run-view",Fe);document.addEventListener("easy_flow:flow-named",t=>{let o=document.querySelector("[data-flow-heading]");o&&(o.textContent=t.detail)});document.addEventListener("easy_flow:flow-status",({detail:t})=>{t.status&&document.querySelectorAll("[data-version-status]").forEach(o=>{o.textContent=t.status}),t.publishes&&document.querySelectorAll("[data-bar-action=publish]").forEach(o=>{o.textContent=`Publish v${t.publishes}`})});Bt(document,At);})();
1
+ (()=>{var Ye=globalThis.ReactDOM;var{createPortal:vs,createRoot:At,flushSync:ws,hydrateRoot:ks,preconnect:Ss,prefetchDNS:Cs,preinit:Ns,preinitModule:Es,preload:_s,preloadModule:As,requestFormReset:zs,unstable_batchedUpdates:Os,useFormState:Ts,useFormStatus:Ms,version:Bs}=Ye;var zt=globalThis.React,e=zt,{Children:Ls,Component:Ps,Fragment:Is,PureComponent:$s,StrictMode:Hs,Suspense:Ws,cloneElement:js,createContext:Gs,createElement:Vs,createRef:Fs,forwardRef:Us,isValidElement:Xs,lazy:Ys,memo:qs,startTransition:Js,useCallback:Ks,useContext:Zs,useDebugValue:Qs,useDeferredValue:Rs,useEffect:L,useId:tn,useImperativeHandle:en,useLayoutEffect:R,useMemo:P,useReducer:on,useRef:Y,useState:E,useSyncExternalStore:rn,useTransition:sn}=zt;var Ot=new Map,tt=new Map,ft=(t,o)=>Ot.set(t,o),Tt=()=>{tt.forEach(t=>t.unmount()),tt.clear()},Mt=(t,o)=>t.querySelectorAll("[data-react-ui]").forEach(s=>{if(tt.has(s))return;let r=Ot.get(s.dataset.reactUi),n=o(s);tt.set(s,n),n.render(e.createElement(r,JSON.parse(s.dataset.props)))});var Bt=(t,o)=>{let s=()=>Mt(t,o);t.addEventListener("turbo:load",s),t.addEventListener("turbo:frame-load",s),t.addEventListener("turbo:before-cache",Tt),t.readyState==="loading"?t.addEventListener("DOMContentLoaded",s):s()};var A=(...t)=>t.filter(Boolean).join(" ");var qe={primary:"ks-button-primary",secondary:"ks-button-secondary",danger:"ks-button-danger"},Je={sm:"ks-button-sm",md:"ks-button-md",lg:"ks-button-lg"},Ke=({variant:t="primary",size:o="md",className:s,children:r,...n})=>{let a=n.href?"a":"button";return e.createElement(a,{...n,className:A("ks-button",qe[t],Je[o],s)},r)},w=Ke;var Ze="border border-amber-500 bg-white text-amber-700 dark:bg-zinc-900 dark:text-amber-400",Qe="border border-gray-300 bg-white text-gray-500 dark:border-zinc-600 dark:bg-zinc-900 dark:text-gray-400",Re="border border-accent-600 bg-accent-600 text-white",to=({name:t,connected:o,armed:s,onArm:r,connecting:n})=>e.createElement("button",{onClick:a=>{n||(a.stopPropagation(),r(a))},title:s?"Now choose a step to connect to":"Connect this branch",className:s?Re:o?Qe:Ze,style:{padding:"1px 8px",marginRight:4,borderRadius:999,fontSize:11,cursor:"pointer"}},t||"next"),Dt=to;var eo={width:240,boxSizing:"border-box",borderRadius:8},oo={minWidth:120,boxSizing:"border-box",borderRadius:6},ro={padding:"8px 14px",textAlign:"center",fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},so={fontWeight:600,lineHeight:1.3},no={fontSize:12,fontWeight:500,lineHeight:1.3},ao=(t,o,s)=>{let r=s?"ring-4 ring-accent-600/15":"shadow-sm";return t||s&&!o?`border-accent-600 ${r}`:o?`border-red-600 ${r}`:"border-gray-300 shadow-sm dark:border-zinc-700"},io=(t,o)=>o&&t.label===t.id&&t.type_name||t.label,lo=(t,o)=>[o,t.ends_here&&t.mark].filter(Boolean).join(" \xB7 "),co=(t,o,s)=>s?o===t.type_name?null:t.type_name:t.type,po=({node:t,selected:o,armed:s,connecting:r,onSelect:n,onOpen:a,onArm:p,onDragEnd:c,onDragStart:l,hideStepTypeCodes:m,compact:u=!1,typeAbove:x=u})=>{let h=t.begins_here||t.ends_here,d=t.begins_here,f=t.ends_here?[]:t.ports,_=r&&!d,v=io(t,m),C=co(t,v,m);return e.createElement("div",{ref:t.ref,"data-step":t.id,draggable:!d,onDragStart:k=>{k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/plain",t.id),l()},onDragEnd:c,onClick:t.opens&&!r?()=>a(t.opens):n,className:`bg-white ${u&&!o?"border":"border-2"} dark:bg-zinc-900 ${ao(_,t.violations.length>0,o)}`,style:{...u?oo:eo,padding:h?0:u?"8px 10px":"12px 14px",cursor:d?"default":r?"crosshair":"grab"}},!h&&x&&C&&e.createElement("div",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},C),h&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:ro},lo(t,v)),!h&&e.createElement("div",{style:u?no:so},v),t.violations.length>0&&e.createElement("div",{"data-error-count":!0,className:"text-red-600 dark:text-red-400",style:{fontSize:10}},`${t.violations.length} error${t.violations.length===1?"":"s"}`),!h&&t.summary&&t.violations.length===0&&e.createElement("div",{className:o?"text-accent-600 dark:text-accent-400":"text-gray-500 dark:text-gray-400",style:{fontSize:10}},t.summary),!h&&!x&&C&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginTop:2}},C),t.picture_url&&e.createElement("div",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:11,marginTop:2}},"Has a picture"),t.starts_a_flow&&e.createElement("div",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:11,marginTop:2}},"Runs a flow"),t.opens&&e.createElement(w,{variant:"secondary",size:"sm",className:"mt-2",onClick:k=>{k.stopPropagation(),n()}},"Settings"),f.length>0&&e.createElement("div",{style:{padding:t.begins_here?"0 14px 8px":"10px 0 0"}},f.map(k=>e.createElement(Dt,{key:k,name:k,connected:t.connected.includes(k),connecting:r,armed:s===k,onArm:N=>p(k,N)}))))},gt=po;var Lt={position:"relative",zIndex:2,width:240,fontSize:11,whiteSpace:"nowrap",cursor:"pointer"},mo={...Lt,width:"auto",whiteSpace:"normal",overflowWrap:"anywhere"},uo=({node:t,header:o,onSelect:s,compact:r=!1})=>e.createElement("div",{ref:t.ref,"data-group-header":t.id,onClick:s,className:"font-mono text-gray-500 dark:text-gray-400",style:{...r?mo:Lt,...s?{}:{cursor:"default"}}},o),et=uo;var fo=({id:t,bounds:o,onDrop:s})=>e.createElement("div",{"data-group-box":t,onDragOver:r=>{r.preventDefault(),r.dataTransfer.dropEffect="move"},onDrop:r=>{r.preventDefault(),s()},className:"border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60",style:{position:"absolute",zIndex:1,borderRadius:8,boxSizing:"border-box",...o}}),Pt=fo;var go=t=>t!=null&&t!==""&&typeof t!="object",ho=["integer","float"],xo=(t,o,s)=>s&&o.labels?.[t]||t,ot=(t,o,s)=>{let r=Object.keys(o?.fields||{}).filter(n=>go(t.config[n])).map(n=>`${xo(n,o,s)}${ho.includes(o.fields[n])?"":":"} ${t.config[n]}`);return[s&&t.type_name||t.type,...r].join(" \xB7 ")};var It=(t,o,s)=>{let r=Math.min(...t.map(c=>c.left))-o.left+s.scrollLeft-12,n=Math.min(...t.map(c=>c.top))-o.top+s.scrollTop-10,a=Math.max(...t.map(c=>c.left+c.width))-o.left+s.scrollLeft+12,p=Math.max(...t.map(c=>c.top+c.height))-o.top+s.scrollTop+10;return{left:r,top:n,width:a-r,height:p-n}},yo=({left:t,top:o,width:s,height:r},n)=>n.x>=t&&n.x<=t+s&&n.y>=o&&n.y<=o+r,$t=(t,o)=>t.find(s=>yo(s.bounds,o))?.id||null,Ht=(t,o)=>t.filter(s=>!o.some(r=>r.id===s.source&&r.holds?.includes(s.target))),Wt=(t,o)=>o.some(s=>s.holds?.includes(t.id)&&!s.loose&&s.row===t.row-1);var ht=(t,o)=>t.includes(o)?t.filter(s=>s!==o):[...t,o],jt=(t,o)=>({...o?.choices||{},...t?.choices||{}});var bo=({as:t="input",disabled:o,className:s,...r})=>e.createElement(t,{...r,disabled:o,className:A("ks-input",o&&"ks-input-disabled",s)}),I=bo;var vo=t=>e.createElement(I,{...t,as:"select"}),Gt=vo;var wo=({className:t,...o})=>e.createElement("input",{type:"checkbox",...o,className:A("ks-checkbox",t)}),rt=wo;var ko=({name:t,value:o,label:s,hint:r,className:n,...a})=>e.createElement("label",{className:"inline-block cursor-pointer relative"},e.createElement("input",{type:"radio",name:t,value:o,...a,className:A("peer sr-only",n)}),e.createElement("span",{className:"ks-radio-card inline-flex flex-col cursor-pointer transition ks-radio-card-highlight"},e.createElement("span",{className:"ks-radio-card-header flex items-start justify-between"},e.createElement("span",{className:"ks-radio-card-label block"},s)),r!=null&&e.createElement("span",{className:"ks-radio-card-hint block text-sm"},r))),Vt=ko;var So=({name:t,options:o,value:s,onChange:r,className:n})=>e.createElement("div",{className:A("flex flex-wrap ks-grid-gap-sm",n)},o.map(a=>e.createElement(Vt,{key:a.value,name:t,...a,checked:a.value===s,onChange:()=>r(a.value)}))),Ft=So;var Ut=t=>(t||[]).map(o=>typeof o=="object"?o:{value:o,label:o}),Co=({name:t,type:o,value:s,choices:r,onChange:n,onSettle:a,onPick:p,pictureUrl:c})=>{if(o==="picture")return e.createElement("div",{className:"mb-3"},s&&c&&e.createElement("img",{src:c,alt:"The step's picture",style:{maxWidth:"100%"}}),s&&e.createElement(w,{type:"button",variant:"secondary",size:"sm","data-remove-picture":!0,onClick:()=>a("")},"Remove picture"),e.createElement("input",{type:"file",accept:"image/*",onChange:l=>l.target.files[0]&&p(l.target.files[0])}));if(o==="boolean")return e.createElement(rt,{checked:!!s,onChange:l=>a(l.target.checked)});if(o==="select"||o==="previous_step"||o==="from_step"||o==="flow")return e.createElement(Gt,{className:"mb-3",value:s??"",onChange:l=>a(l.target.value)},e.createElement("option",{value:""}),Ut(r).map(l=>e.createElement("option",{key:l.value,value:l.value},l.label)));if(o==="radio_cards")return e.createElement("div",{"data-radio-cards":!0,className:"mb-3 [&_label]:flex-[1_1_7rem] [&_.ks-radio-card]:flex [&_.ks-radio-card]:h-full"},e.createElement(Ft,{name:t,value:s,options:r||[],onChange:a}));if(o==="multi_select"){let l=Array.isArray(s)?s:[],m=u=>a(ht(l,u));return e.createElement("div",{style:{display:"flex",flexWrap:"wrap",gap:8}},(r||[]).map(u=>e.createElement("label",{key:u,style:{display:"inline-flex",alignItems:"center",gap:4}},e.createElement(rt,{checked:l.includes(u),onChange:()=>m(u)}),e.createElement("span",null,u))))}if(o==="flows"){let l=Array.isArray(s)?s:[];return e.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4},className:"mb-3"},Ut(r).map(m=>e.createElement("label",{key:m.value,style:{display:"inline-flex",alignItems:"center",gap:4}},e.createElement(rt,{checked:l.includes(m.value),onChange:()=>a(ht(l,m.value))}),e.createElement("span",null,m.label))))}return o==="integer"||o==="float"?e.createElement(I,{className:"mb-3",type:"number",step:o==="integer"?"1":"any",value:s??"",onChange:l=>n(l.target.value),onBlur:l=>a(l.target.value)}):e.createElement(I,{className:"mb-3",type:"text",value:s??"",onChange:l=>n(l.target.value),onBlur:l=>a(l.target.value)})},st=Co;var Xt=(t,o,s,r)=>t.map((n,a)=>a===o?{...n,[s]:r}:n);var No=({text:t})=>e.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{display:"block",fontSize:11,lineHeight:1.4,marginBottom:12},"data-setting-explanation":!0},t),nt=No;var Eo=(t,o,s,r)=>{let n=(t||{})[s],a=(o||{})[s];return a?(n||{})[r[a]]:n},_o=({holds:t,labels:o,explanations:s,rows:r,choices:n,outputsOf:a,onChange:p,onSettle:c})=>{let l=Array.isArray(r)?r:[],m=(u,x,h,d)=>{let f=Xt(l,u,x,h);d?c(f):p(f)};return e.createElement("div",{style:{marginBottom:12}},l.map((u,x)=>e.createElement("div",{key:x,className:"rounded-md border border-gray-200 dark:border-zinc-700",style:{padding:"8px 8px 2px",marginBottom:6}},Object.entries(t).map(([h,d])=>e.createElement("label",{key:h,style:{display:"block"}},e.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{display:"block",marginBottom:2,fontSize:11}},(o||{})[h]||h),e.createElement(st,{type:d,value:u[h],choices:Eo(n,a,h,u),onChange:f=>m(x,h,f,!1),onSettle:f=>m(x,h,f,!0)}),(s||{})[h]&&e.createElement(nt,{text:s[h]}))),e.createElement(w,{variant:"secondary",size:"sm",className:"mb-1.5",onClick:()=>c(l.filter((h,d)=>d!==x))},"Remove"))),e.createElement(w,{variant:"secondary",size:"sm",className:"w-full",onClick:()=>c([...l,{}])},"Add"))},Yt=_o;var Ao={start:null,end:"ks-value-list-end"},zo="grid grid-cols-1 sm:grid-cols-2 ks-grid-gap-sm",Oo="flex flex-col min-w-0",To="ks-value-list-label basis-auto text-xs",Mo=()=>e.createElement("svg",{"aria-label":"Right",role:"img",className:"ks-tone-success inline size-5 align-text-bottom",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor"},e.createElement("path",{fillRule:"evenodd",d:"M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z",clipRule:"evenodd"})),Bo=({value:t,fallback:o})=>String(t??"")===""?o:t,Do=({rows:t,align:o="start",columns:s=!1,className:r})=>e.createElement("dl",{className:A("ks-value-list",Ao[o],s&&zo,r)},t.map((n,a)=>e.createElement("div",{key:a,className:A(s?Oo:"ks-value-list-row",n.total&&"ks-value-list-total")},e.createElement("dt",{className:s?To:"ks-value-list-label"},n.label,n.note!=null&&e.createElement(e.Fragment,null," ",e.createElement("span",{className:"ks-value-list-note"},n.note))),e.createElement("dd",{className:"ks-value-list-value"},Bo(n),n.right&&e.createElement(e.Fragment,null," ",e.createElement(Mo,null)))))),qt=Do;var Lo=()=>e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2"},e.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})),Po=({summary:t,open:o=!1,className:s,children:r})=>e.createElement("details",{className:A("ks-disclosure group",s),open:o},e.createElement("summary",{className:"ks-disclosure-summary flex cursor-pointer list-none items-center justify-between [&::-webkit-details-marker]:hidden"},e.createElement("span",null,t),e.createElement("span",{className:"ks-disclosure-icon h-4 w-4 shrink-0 transition-transform group-open:rotate-180"},e.createElement(Lo,null))),e.createElement("div",{className:"ks-disclosure-body text-sm"},r)),Jt=Po;var Io=({language:t,caption:o,className:s,children:r})=>e.createElement("div",{className:A("ks-code overflow-hidden",s)},o!=null&&e.createElement("div",{className:"ks-code-caption font-mono text-xs"},o),e.createElement("pre",{className:"ks-code-block overflow-x-auto font-mono text-sm leading-relaxed"},e.createElement("code",{className:t==null?"":`language-${t}`},r))),Kt=Io;var xt="flex flex-col gap-1 mb-3",Zt="[&_dd]:font-mono",$o="[&_.ks-value-list]:grid-cols-2 [&_.ks-value-list]:gap-2",Ho="[&_.ks-value-list]:font-mono [&_.ks-value-list]:flex [&_.ks-value-list]:flex-col [&_.ks-value-list]:gap-1 [&_.ks-value-list-row]:gap-2 [&_.ks-value-list-row]:py-0 [&_.ks-value-list-row]:border-0 [&_.ks-value-list-label]:basis-[90px]",Wo="border-t border-gray-200 pt-2.5 dark:border-zinc-700 [&_.ks-disclosure]:border-0 [&_.ks-disclosure-summary]:flex-row-reverse [&_.ks-disclosure-summary]:justify-end [&_.ks-disclosure-summary]:gap-1 [&_.ks-disclosure-summary]:p-0 [&_.ks-disclosure-summary]:font-normal [&_.ks-disclosure-body]:p-0 [&_.ks-disclosure-body]:pt-1.5 [&_.ks-code-block]:p-2 [&_.ks-code-block]:text-[11px]",jo=t=>t.values?t.columns?`${xt} ${Zt} ${$o}`:`${xt} ${Zt} ${Ho}`:`${xt} ${Wo}`,Go=({details:t})=>e.createElement(e.Fragment,null,t.map((o,s)=>e.createElement("section",{key:s,className:jo(o)},o.heading&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400"},o.heading),o.values&&e.createElement(qt,{rows:o.values,columns:o.columns}),o.code&&o.code.map(r=>e.createElement(Jt,{key:r.summary,summary:r.summary},e.createElement(Kt,null,r.code)))))),Qt=Go;var Vo=({as:t="div",className:o,children:s,...r})=>e.createElement(t,{...r,className:A("ks-panel",o)},s),D=Vo;var at=(t,o)=>({className:s,children:r,...n})=>e.createElement(t,{...n,className:A(o,s)},r),q=at("label","ks-label"),Aa=at("p","ks-hint"),za=at("p","ks-error"),Oa=at("span","ks-required");var Fo={width:320,padding:"14px 16px",overflowY:"auto",display:"flex",flexDirection:"column",fontSize:12},Uo={marginTop:"auto",paddingTop:12,display:"flex",flexDirection:"column",gap:8},Xo=({node:t,fields:o,holds:s,labels:r,explanations:n,recordLabels:a,recordExplanations:p,recordChoices:c,recordOutputsOf:l,choices:m,onSave:u,onDelete:x,onClose:h,onPickPicture:d,refusal:f,notice:_})=>{let[v,C]=E(t.config),[k,N]=E(t.picture_url);L(()=>N(t.picture_url),[t.id,t.picture_url]),L(()=>C(t.config),[t.id,t.config]);let M=b=>{C(b),JSON.stringify(b)!==JSON.stringify(t.config)&&u(b)};return e.createElement(D,{as:"aside",style:Fo,className:"max-sm:absolute max-sm:inset-0 max-sm:z-30 max-sm:!w-auto","data-inspector":!0},e.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8,marginBottom:12}},e.createElement("div",null,e.createElement("p",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},t.id," \xB7 ",t.type),e.createElement("h2",{style:{fontSize:15,fontWeight:600}},t.label)),e.createElement("button",{title:"Close",onClick:h,className:"text-gray-500 dark:text-gray-400",style:{border:"none",background:"none",cursor:"pointer",fontSize:18,lineHeight:1}},"\xD7")),f&&e.createElement("p",{className:"text-red-800 dark:text-red-400",style:{fontWeight:600,marginBottom:12},"data-refusal":!0},f),_&&!f&&e.createElement("p",{className:"text-emerald-800 dark:text-emerald-400",style:{fontWeight:600,marginBottom:12},"data-notice":!0},_),Object.entries(o).map(([b,B])=>e.createElement(q,{key:b},e.createElement("span",{style:{display:"block",marginBottom:3}},r[b]||b),B==="list"?e.createElement(Yt,{holds:s[b]||{},labels:a[b]||{},explanations:(p||{})[b],rows:v[b],choices:{...(c||{})[b],...(t.record_choices||{})[b]},outputsOf:(l||{})[b],onChange:O=>C({...v,[b]:O}),onSettle:O=>M({...v,[b]:O})}):e.createElement(st,{name:b,type:B,value:v[b],choices:m[b],pictureUrl:k,onChange:O=>C({...v,[b]:O}),onSettle:O=>M({...v,[b]:O}),onPick:async O=>{let H=await d(O);H&&(N(H.url),M({...v,[b]:H.reference}))}}),(n||{})[b]&&e.createElement(nt,{text:n[b]}))),e.createElement(Qt,{details:t.details||[]}),e.createElement("div",{style:Uo},(t.links||[]).length>0&&e.createElement("div",{style:{display:"flex",gap:8}},t.links.map(b=>e.createElement(w,{key:b.address,variant:"secondary",size:"sm",className:"flex-1",href:b.address},b.label))),e.createElement(w,{variant:"danger",size:"sm",className:"w-full",onClick:x},"Delete step")))},Rt=Xo;var Yo={width:240,boxSizing:"border-box",padding:"10px 14px",borderRadius:8,textAlign:"center",fontSize:12,cursor:"pointer"},qo={minWidth:120,boxSizing:"border-box",padding:"8px 10px",borderRadius:6,textAlign:"center",fontSize:12,cursor:"pointer"},Jo="border-2 border-dashed border-amber-500 bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300",Ko="border-2 border-dashed border-accent-600 bg-accent-50 text-accent-800 dark:bg-accent-950 dark:text-accent-200",Zo=({node:t,dragging:o,onFill:s,onDrop:r,compact:n=!1})=>e.createElement("div",{ref:t.ref,"data-placeholder":t.id,title:`Choose the step \u201C${t.label}\u201D should lead to`,onClick:s,onDragOver:a=>{o&&(a.preventDefault(),a.dataTransfer.dropEffect="move")},onDrop:a=>{a.preventDefault(),r()},className:o?Ko:Jo,style:n?qo:Yo},e.createElement("div",{style:{fontWeight:600}},t.label),e.createElement("div",{style:{fontSize:11}},o?"drop a step here":"leads nowhere yet \u2014 click to choose")),te=Zo;var Qo=({entries:t,at:o,onPick:s,onConnect:r,onDismiss:n,hideStepTypeCodes:a})=>e.createElement(D,{className:"shadow-lg",style:{position:"absolute",zIndex:9,top:o.y,left:o.x,width:210,padding:8,borderRadius:8}},e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{margin:"0 0 6px",fontSize:11}},"Add a step"),t.map(p=>e.createElement(w,{key:p.type,variant:"secondary",size:"sm",className:"w-full mb-1.5 flex-col",onClick:()=>s(p)},p.label,!a&&e.createElement("span",{className:"opacity-75",style:{display:"block",fontSize:11}},p.type))),r&&e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:r},"Connect to a step already here"),e.createElement(w,{variant:"secondary",size:"sm",className:"w-full",onClick:n},"Cancel")),ee=Qo;var Ro=t=>o=>o.label.toLowerCase().includes(t.trim().toLowerCase()),tr=(t,o,s="")=>{let r=Object.values(o).flat(),n=Object.entries(o).map(([a,p])=>({heading:a,entries:p.map(c=>t.find(l=>l.type===c)).filter(Boolean)}));return[{heading:null,entries:t.filter(a=>!r.includes(a.type))},...n].map(a=>({...a,entries:a.entries.filter(Ro(s))})).filter(a=>a.entries.length>0)},er={width:200,flex:"none",boxSizing:"border-box",padding:"14px 12px",gap:6,fontSize:12,overflowY:"auto",borderWidth:"0 1px 0 0"},or={fontSize:11,textTransform:"uppercase",letterSpacing:".04em",padding:"8px 4px 2px"},rr={textAlign:"left",padding:"7px 9px",borderRadius:6,fontSize:12,cursor:"grab"},sr=({entries:t,groups:o,onPick:s,onCarry:r,onDrop:n})=>{let[a,p]=E("");return e.createElement(D,{as:"aside","aria-label":"Steps","data-step-list":!0,className:"hidden flex-col sm:flex",style:er},e.createElement(I,{type:"search","aria-label":"Search steps",placeholder:"Search steps",value:a,onChange:c=>p(c.target.value),style:{marginBottom:6,fontSize:12}}),tr(t,o,a).map(c=>e.createElement(e.Fragment,{key:c.heading||""},c.heading&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:or},c.heading),c.entries.map(l=>e.createElement(D,{as:"button",type:"button",key:l.type,"data-step-type":l.type,className:"bg-surface-50 dark:bg-surface-950",style:rr,draggable:!0,onClick:()=>s(l),onDragStart:m=>{m.dataTransfer.effectAllowed="copyMove",m.dataTransfer.setData("text/plain",l.type),r(l)},onDragEnd:n},l.label)))))},oe=sr;var nr={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},re=({label:t,title:o,idle:s,enabled:r,onUse:n})=>e.createElement(w,{variant:"secondary",size:"sm",title:r?o:s,disabled:!r,onClick:n,style:{opacity:r?1:.4,cursor:r?"pointer":"default"}},t),ar=({undoable:t,redoable:o,onAdd:s,onUndo:r,onRedo:n})=>e.createElement("div",{style:{position:"absolute",top:16,left:16,zIndex:5,display:"flex",gap:8}},e.createElement(w,{variant:"secondary",className:"rounded-full",style:nr,title:"Add a step",onClick:s},"+"),e.createElement(re,{label:"\u21B6 Undo",title:"Undo the last change",idle:"Nothing to undo",enabled:t,onUse:r}),e.createElement(re,{label:"\u21B7 Redo",title:"Redo the change you undid",idle:"Nothing to redo",enabled:o,onUse:n})),se=ar;var ir=({type:t="info",title:o,message:s,onDismiss:r,className:n})=>e.createElement("div",{className:A("ks-alert",`ks-alert-${t}`,n),role:"alert"},e.createElement("div",{className:"ks-alert-body"},e.createElement("div",{className:"ks-alert-content"},o&&e.createElement("p",{className:"ks-alert-title"},o),e.createElement("p",{className:o?"ks-alert-message-titled":"ks-alert-message"},s)),r&&e.createElement("button",{type:"button",className:"ks-alert-dismiss","aria-label":"Dismiss",onClick:r},"\xD7"))),ne=ir;var ae=t=>{let o=t.map(s=>`\u201C${s.name}\u201D`).join(", ");return t.length===1?`${o} is not connected to the flow and will be removed. Remove it to go on, or cancel and connect it first.`:`${o} are not connected to the flow and will be removed. Remove them to go on, or cancel and connect them first.`};var ie=({version:t,published:o})=>t?o?o===t?`Version ${t} \xB7 live`:`Version ${t} \xB7 visitors still on ${o}`:`Version ${t} \xB7 never published`:"No version yet";var lr={width:280,padding:20,overflowY:"auto"},le={fontWeight:600,marginBottom:6,marginTop:14},yt={fontSize:12,marginBottom:4,lineHeight:1.4},de={display:"block",marginBottom:3},ce=(t,o,s)=>r=>{r.target.value!==(t[o]??"")&&s({[o]:r.target.value})},dr=({flow:t,changes:o,refusal:s,notice:r,publishNote:n,warning:a,onCreate:p,onPublish:c,onAccept:l,onDecline:m,onSaveDetails:u,onClose:x})=>e.createElement(D,{as:"aside",style:lr,"data-builder-panel":!0},e.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8}},e.createElement("h2",{style:{fontWeight:600},"data-flow-name":!0},t.title||t.slug),e.createElement("button",{title:"Close",onClick:x,className:"text-gray-500 dark:text-gray-400",style:{border:"none",background:"none",cursor:"pointer",fontSize:18,lineHeight:1}},"\xD7")),e.createElement("a",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:12,display:"block"},href:t.history_url,"data-history":!0},ie(t)),a?e.createElement("div",{style:{marginTop:14},"data-unconnected-warning":!0},e.createElement(ne,{type:"warning",className:"mb-1.5",message:ae(a.steps)}),e.createElement(w,{size:"sm",className:"w-full mb-1.5",onClick:l,"data-accept-removal":!0},a.path==="/publish"?"Remove and publish":"Remove and create version"),e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:m,"data-decline-removal":!0},"Cancel")):e.createElement("div",{style:{marginTop:14}},e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:p,"data-create-version":!0},"Create version"),e.createElement(w,{size:"sm",className:"w-full mb-1.5",onClick:c,"data-publish":!0},"Publish"),n&&e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12,lineHeight:1.4},"data-publish-note":!0},n)),s&&e.createElement("p",{className:"text-red-800 dark:text-red-400",style:{...yt,fontWeight:600,marginTop:8},"data-refusal":!0},s),r&&!s&&e.createElement("p",{className:"text-emerald-800 dark:text-emerald-400",style:{...yt,fontWeight:600,marginTop:8},"data-notice":!0},r),e.createElement("h2",{style:le},"Changes since the last version"),o.length===0?e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12}},"Nothing has changed."):o.map((h,d)=>e.createElement("p",{key:d,style:yt,"data-change":!0},h)),e.createElement("h2",{style:le},"Details"),e.createElement(q,null,e.createElement("span",{style:de},"Title"),e.createElement(I,{className:"mb-3",defaultValue:t.title??"",onBlur:ce(t,"title",u),"data-flow-title":!0})),e.createElement(q,null,e.createElement("span",{style:de},"Start label"),e.createElement(I,{className:"mb-3",defaultValue:t.start_label??"",onBlur:ce(t,"start_label",u),"data-flow-start-label":!0})),e.createElement("div",{style:{marginTop:16}},e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.definition_url,"data-definition":!0},"Definition"),e.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.details_url,"data-details":!0},"Edit details"))),pe=dr;var cr=({variant:t="neutral",className:o,children:s,...r})=>e.createElement("span",{...r,className:A("ks-badge",`ks-badge-${t}`,o)},s),me=cr;var pr={center:"ks-tab-bar flex flex-wrap justify-center max-sm:flex-nowrap max-sm:overflow-x-auto max-sm:justify-start",start:"ks-tab-bar flex flex-wrap justify-start max-sm:flex-nowrap max-sm:overflow-x-auto"},mr={pills:"ks-tab-bar-pills",underline:"ks-tab-bar-underline"},ur="ks-tab text-sm transition max-sm:shrink-0 max-sm:whitespace-nowrap ks-tab-active",fr="ks-tab transition max-sm:shrink-0 max-sm:whitespace-nowrap ks-tab-active",gr=({shape:t,count:o})=>t?e.createElement("span",{className:"ks-tab-count"},o):e.createElement(me,{variant:"info"},o),hr=t=>typeof t=="string"?t!=="":t>0,xr=({tabs:t,value:o,onChange:s,align:r="center",shape:n,className:a})=>e.createElement("div",{className:a},e.createElement("div",{className:A(pr[r],mr[n])},t.map(p=>e.createElement("button",{key:p.value,type:"button",className:n?fr:ur,"data-active":p.value===o?"":void 0,onClick:()=>s(p.value)},p.label,hr(p.count)&&e.createElement(e.Fragment,null," ",e.createElement(gr,{shape:n,count:p.count}))))),t.find(p=>p.value===o)?.content),ue=xr;var yr={error:"text-red-800 dark:text-red-400",ok:"text-emerald-800 dark:text-emerald-400"},fe="mx-6 mb-6 flex max-h-[45%] flex-none flex-col overflow-y-auto rounded-lg max-sm:m-0 max-sm:max-h-none max-sm:rounded-none [&_.ks-tab-bar]:mb-0 [&_.ks-tab-bar]:px-2",br="max-sm:absolute max-sm:inset-0 max-sm:z-20",xe={padding:"10px 14px",fontSize:12,display:"flex",flexDirection:"column",gap:6},ge={display:"flex",gap:8,textAlign:"left"},he={flexShrink:0,whiteSpace:"nowrap"},vr=({check:t,onSelect:o})=>{let s=e.createElement(e.Fragment,null,e.createElement("span",{className:yr[t.level],style:{...he,fontWeight:500}},t.level),t.node&&e.createElement("span",{className:"font-mono",style:he},t.node),e.createElement("span",null,t.sentence));return t.node?e.createElement("button",{type:"button","data-check-row":!0,"data-step-id":t.node,style:{...ge,border:"none",background:"none",padding:0,cursor:"pointer",font:"inherit",color:"inherit"},onClick:()=>o(t.node)},s):e.createElement("div",{"data-check-row":!0,style:ge},s)},wr=({checks:t,onSelect:o})=>e.createElement("div",{style:xe},t.map((s,r)=>e.createElement(vr,{key:r,check:s,onSelect:o}))),kr=()=>typeof window<"u"&&!!window.matchMedia?.("(max-width: 639px)").matches,Sr=({checks:t,tabs:o,onSelect:s,opened:r=kr()?null:"validation"})=>{let[n,a]=E(r);return e.createElement(D,{as:"section","aria-label":"Validation and tests","data-drawer":!0,className:n?`${fe} ${br}`:fe},e.createElement(ue,{align:"start",shape:"underline",value:n,onChange:p=>a(p===n?null:p),tabs:[{value:"validation",label:"Validation",count:t.filter(p=>p.level==="error").length,content:e.createElement(wr,{checks:t,onSelect:s})},...o.map(p=>({value:p.label,label:p.label,count:p.count??"",content:e.createElement("div",{"data-drawer-content":!0,style:xe,dangerouslySetInnerHTML:{__html:p.content}})}))]}))},ye=Sr;var be={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},ve=t=>({opacity:t?1:0,transition:"opacity .12s"}),Cr=({link:t,onInsert:o,onRemove:s,onDrop:r,dragging:n,alwaysShowInsertButtons:a})=>{let[p,c]=E(!1),l=p||n;return e.createElement("div",{"data-connector":`${t.source}-${t.target}`,style:{position:"absolute",left:t.midX-34,top:t.midY-20,width:68,height:40,zIndex:4},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onDragEnter:()=>c(!0),onDragLeave:()=>c(!1),onDragOver:m=>{m.preventDefault(),m.dataTransfer.dropEffect="move"},onDrop:m=>{m.preventDefault(),c(!1),r()}},e.createElement("div",{style:{display:"flex",gap:4,justifyContent:"center",alignItems:"center",height:"100%"}},e.createElement(w,{variant:"secondary",title:n?"Move the step here":"Insert a step here",onClick:o,className:"rounded-full data-[over=true]:ring-2 data-[over=true]:ring-accent-600","data-over":!!(n&&p),style:{...be,...ve(l||a)}},"+"),!n&&e.createElement(w,{variant:"danger",title:"Remove this connection",onClick:s,className:"rounded-full",style:{...be,...ve(l)}},"\xD7")))},we=Cr;var Nr=({links:t,extent:o,dragging:s,onInsert:r,onRemove:n,onDrop:a,alwaysShowInsertButtons:p})=>e.createElement(e.Fragment,null,e.createElement("svg",{width:o.width,height:o.height,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:1}},e.createElement("defs",null,e.createElement("marker",{id:"easy_flow-arrow",viewBox:"0 0 10 10",refX:"8",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto"},e.createElement("path",{d:"M 0 0 L 10 5 L 0 10 z",className:"fill-gray-400 dark:fill-zinc-500"}))),t.map(c=>e.createElement("path",{key:c.id,"data-link":c.id,className:"stroke-gray-400 dark:stroke-zinc-500",fill:"none",strokeWidth:"1.5",markerEnd:"url(#easy_flow-arrow)",d:c.path}))),t.filter(c=>c.label).map(c=>e.createElement("div",{key:`${c.id}-label`,"data-link-label":c.id,className:"bg-surface-50 text-gray-500 dark:bg-surface-950 dark:text-gray-400",style:{position:"absolute",left:c.midX+(p?2:-10),top:c.midY-18,zIndex:3,fontSize:11,padding:"0 3px"}},c.label)),t.filter(c=>!c.placeholder).map(c=>e.createElement(we,{key:c.id,link:c,dragging:!!s,alwaysShowInsertButtons:p,onInsert:()=>r(c),onRemove:()=>n(c),onDrop:()=>a(c)}))),ke=Nr;var bt={width:22,height:22,padding:0,fontSize:14,lineHeight:"14px"},Se="opacity-0 transition-opacity group-data-[over=true]:opacity-100",Er={display:"flex",alignItems:"center",justifyContent:"flex-end",gap:2,height:"100%"},_r=({link:t,onInsert:o,onRemove:s,onDrop:r,alwaysShowInsertButtons:n,dragging:a,shown:p=!1,className:c="",style:l,children:m})=>e.createElement("div",{"data-joint":t?.id,className:`group ${c}`.trim(),style:l,onMouseEnter:u=>{u.currentTarget.dataset.over="true"},onMouseLeave:u=>{delete u.currentTarget.dataset.over},onDragOver:u=>{t&&r&&(u.preventDefault(),u.dataTransfer.dropEffect="move")},onDrop:u=>{t&&(u.preventDefault(),r(t))}},m,t&&o&&e.createElement("div",{style:Er},e.createElement(w,{variant:"secondary",title:"Insert a step here",onClick:u=>o(t,u),className:`rounded-full ${n?"opacity-100":Se}`,style:a?{...bt,opacity:1}:bt},"+"),e.createElement(w,{variant:"danger",title:"Remove this connection",onClick:()=>s(t),className:`rounded-full ${p?"opacity-100":Se}`,style:bt},"\xD7"))),it=_r;var Ar=(t,o)=>{let s=new Map(t.map(p=>[p,0])),r=new Map(t.map(p=>[p,[]])),n=new Map(t.map(p=>[p,0]));o.forEach(p=>{r.get(p.source).push(p.target),n.set(p.target,n.get(p.target)+1)});let a=t.filter(p=>n.get(p)===0);for(let p=0;p<a.length;p++){let c=a[p];r.get(c).forEach(l=>{s.set(l,Math.max(s.get(l),s.get(c)+1)),n.set(l,n.get(l)-1),n.get(l)===0&&a.push(l)})}return s},wt=(t,o)=>{let s=new Map(t.map(r=>[r,[]]));return o.forEach(r=>s.get(r.source).push(r)),s},zr=(t,o)=>{let s=wt(t,o),r=new Set(o.map(c=>c.target)),n=new Map,a=new Set,p=c=>{let l=[[c,0]];for(n.set(c,"open");l.length>0;){let m=l[l.length-1],u=s.get(m[0])[m[1]++];u?n.get(u.target)==="open"?a.add(u):n.has(u.target)||(n.set(u.target,"open"),l.push([u.target,0])):(n.set(m[0],"done"),l.pop())}};return t.filter(c=>!r.has(c)).forEach(p),t.forEach(c=>{n.has(c)||p(c)}),a},Or=(t,o,s)=>{let r=[];t.forEach(l=>{var m;return(r[m=s.get(l)]||(r[m]=[])).push(l)});let n=wt(t,o),a=new Map;n.forEach(l=>l.forEach((m,u)=>a.set(m,(u+1)/(l.length+1))));let p=new Map(t.map(l=>[l,[]]));o.forEach(l=>p.get(l.target).push(l));let c=new Map;return r.forEach(l=>{let m=new Map(l.map(u=>{let x=p.get(u),h=x.reduce((d,f)=>d+c.get(f.source)+a.get(f),0);return[u,x.length>0?h/x.length:1/0]}));l.sort((u,x)=>m.get(u)===m.get(x)?0:m.get(u)<m.get(x)?-1:1),l.forEach((u,x)=>c.set(u,x))}),c};var vt=(t,o,s)=>{let r=[];return t.forEach((n,a)=>{r[a]=a===0?s:r[a-1]+t[a-1]+o}),r},Tr=(t,o)=>t.length>0?t[t.length-1]+o[o.length-1]:0,Mr=t=>{let o=[t];for(let s=1;s*2<=t.length;s*=2){let r=o[o.length-1];o.push(r.slice(0,t.length-s*2+1).map((n,a)=>Math.max(n,r[a+s])))}return(s,r)=>{let n=Math.floor(Math.log2(r-s+1));return Math.max(o[n][s],o[n][r-(1<<n)+1])}},Ce=(t,o,s,r)=>{let n=zr(t,o),a=o.filter(g=>!n.has(g)),p=Ar(t,a),c=Or(t,a,p),l=[],m=[];t.forEach(g=>{var S;l[p.get(g)]=Math.max(l[p.get(g)]||0,s(g).width),(m[S=p.get(g)]||(m[S]=[]))[c.get(g)]=g});let u=g=>p.get(g.target)>p.get(g.source)+1,x=g=>{let S=new Map;return g.forEach(T=>{S.has(T.target)||S.set(T.target,S.size)}),S},h=x(o.filter(g=>n.has(g))),d=x(a.filter(u)),f=vt(l,64,r.left),_=r.top+h.size*14,v=new Map,C=m.map(g=>{let S=g.map(T=>s(T).height);return vt(S,24,_).forEach((T,W)=>v.set(g[W],T)),Tr(vt(S,24,_),S)}),k=Mr(C),N=Object.fromEntries(t.map(g=>[g,{column:p.get(g),row:c.get(g),x:f[p.get(g)],y:v.get(g),width:s(g).width,height:s(g).height}])),M=new Map;a.filter(u).forEach(g=>M.set(g.target,Math.max(M.get(g.target)||0,k(p.get(g.source)+1,p.get(g.target)-1))));let b=g=>n.has(g)?r.top+(h.size-1-h.get(g.target))*14:u(g)?M.get(g.target)+(d.get(g.target)+1)*14:null,B=g=>N[g].y+(s(g).arrives??N[g].height/2),O=g=>b(g)??B(g.target),H=new Map;wt(t,o).forEach(g=>[...g].sort((S,T)=>O(S)-O(T)).forEach((S,T)=>H.set(S,(T+1)/(g.length+1))));let pt=g=>{let S=N[g.source],T=N[g.target],W=S.y+S.height*H.get(g),U=B(g.target),X=f[S.column]+l[S.column]+40,V=b(g),Q=[[S.x+S.width,W],[X,W]],F=[[T.x-64+40,U],[T.x,U]];return{...g.drawn,points:V===null?[...Q,[X,U],F[1]]:[...Q,[X,V],[F[0][0],V],...F]}},K=o.map(pt),Z=[...Object.values(N).map(g=>[g.x+g.width,g.y+g.height]),...K.flatMap(g=>g.points)].reduce(([g,S],[T,W])=>[Math.max(g,T),Math.max(S,W)],[0,0]);return{places:N,links:K,width:Z[0]+r.right,height:Z[1]+r.bottom}},J="\0entry";var Br={left:44,top:40,right:20,bottom:40},Dr={left:0,top:8,right:16,bottom:12},lt=(t,o,{heights:s={}}={})=>{let r=new Set(t.map(d=>d.id)),n=new Map(t.flatMap(d=>(d.holds||[]).filter(f=>r.has(f)).map(f=>[f,d.id]))),a=new Map([[null,{ids:[],edges:[]}]]);t.filter(d=>d.holds).forEach(d=>a.set(d.id,{ids:[J],edges:[]})),t.forEach(d=>a.get(n.get(d.id)??null).ids.push(d.id)),o.filter(d=>r.has(d.source)&&r.has(d.target)).forEach(d=>{let f=n.get(d.target);f&&f===d.source?a.get(f).edges.push({source:J,target:d.target,drawn:d}):f&&f===n.get(d.source)?a.get(f).edges.push({source:d.source,target:d.target,drawn:d}):a.get(null).edges.push({source:n.get(d.source)??d.source,target:f??d.target,drawn:d})});let p=d=>({width:184,height:s[d]||64}),c=new Map([...a].filter(([d])=>d).map(([d,f])=>[d,Ce(f.ids,f.edges,_=>_===J?{width:0,height:64}:p(_),Dr)])),l=d=>s[d]||24,m=d=>{let f=c.get(d);return f?{width:f.width,height:l(d)+f.height,arrives:l(d)+f.places[J].y+64/2}:p(d)},u=Ce(a.get(null).ids,a.get(null).edges,m,Br),x={...u.places},h=[...u.links];return c.forEach((d,f)=>{let _=u.places[f],[v,C]=[_.x,_.y+l(f)];Object.entries(d.places).filter(([k])=>k!==J).forEach(([k,N])=>{x[k]={...N,x:N.x+v,y:N.y+C}}),d.links.forEach(k=>h.push({...k,points:k.points.map(([N,M])=>[N+v,M+C])}))}),{places:x,links:h,width:u.width,height:u.height}};var Lr={display:"flex",flexDirection:"column",gap:14,padding:"64px 16px 24px"},Pr={display:"flex",flexDirection:"column",gap:10,padding:"8px 10px",borderRadius:8},Ir={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,minHeight:26,paddingLeft:12,fontSize:11},$r=t=>(o,s)=>t[o.id].column-t[s.id].column||t[o.id].row-t[s.id].row,Hr=t=>t?.placeholder?"nowhere yet":t?.label,Wr=({node:t,leaving:o,named:s,draw:r,joints:n})=>e.createElement("div",{"data-step-row":t.id},r(t),o.map(a=>e.createElement(it,{key:a.id,link:a,...n,alwaysShowInsertButtons:!0,shown:!0,className:"border-l border-gray-300 text-gray-500 dark:border-zinc-600 dark:text-gray-400",style:Ir},e.createElement("span",null,[a.label,"\u2192",s.get(a.target)].filter(Boolean).join(" "))))),jr=({nodes:t,edges:o,draw:s,joints:r,children:n,style:a})=>{let{places:p}=lt(t,o),c=new Map(t.map(d=>[d.id,Hr(d)])),l=new Map(t.map(d=>[d.id,[]]));o.forEach(d=>{l.has(d.source)&&c.has(d.target)&&l.get(d.source).push(d)});let m=new Map(t.flatMap(d=>(d.holds||[]).map(f=>[f,d.id]))),u=[...t].sort($r(p)),x=new Map;u.filter(d=>m.has(d.id)).forEach(d=>{x.has(m.get(d.id))||x.set(m.get(d.id),[]),x.get(m.get(d.id)).push(d)});let h=d=>e.createElement(Wr,{key:d.id,node:d,leaving:l.get(d.id),named:c,draw:s,joints:r});return e.createElement("div",{"data-flow-rows":!0,style:{...Lr,...a}},n,u.filter(d=>!m.has(d.id)).map(d=>d.holds?e.createElement("div",{key:d.id,"data-group-box":d.id,className:"border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60",style:Pr},h(d),(x.get(d.id)||[]).map(h)):h(d)))},Ne=jr;var Gr={display:"flex",flexDirection:"column",alignItems:"flex-start",gap:14,padding:"64px 0 0"},Vr={position:"absolute",zIndex:3,maxWidth:56,fontSize:10,lineHeight:"13px",pointerEvents:"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Fr=t=>t.map(([o,s],r)=>`${r===0?"M":"L"} ${o} ${s}`).join(" "),Ur=t=>Object.fromEntries(Object.entries(t).filter(([,o])=>o?.firstElementChild).map(([o,s])=>[o,s.firstElementChild.offsetHeight])),Xr=(t,o)=>Object.keys(o).some(s=>t[s]!==o[s]),Yr=({nodes:t,edges:o,draw:s,joints:r})=>{let[n,a]=E({}),p=Y({}),c=P(()=>lt(t,o,{heights:n}),[t,o,n]);R(()=>{let m=Ur(p.current);Xr(n,m)&&a({...n,...m})});let l=m=>u=>{p.current[m]=u};return e.createElement("div",{"data-flow-graph":!0,style:{position:"relative",flex:"none",width:c.width,height:c.height}},e.createElement("svg",{width:c.width,height:c.height,style:{position:"absolute",top:0,left:0,pointerEvents:"none"}},e.createElement("defs",null,e.createElement("marker",{id:"easy_flow-graph-arrow",viewBox:"0 0 10 10",refX:"8",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto"},e.createElement("path",{d:"M 0 0 L 10 5 L 0 10 z",className:"fill-gray-400 dark:fill-zinc-500"}))),c.links.map(m=>e.createElement("path",{key:m.id,"data-link":m.id,d:Fr(m.points),fill:"none",strokeWidth:"1.5",className:"stroke-gray-400 dark:stroke-zinc-500",markerEnd:"url(#easy_flow-graph-arrow)"}))),t.map(m=>{let u=c.places[m.id];return m.holds?e.createElement("div",{key:m.id,ref:l(m.id),"data-group-box":m.id,className:"border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60",style:{position:"absolute",left:u.x,top:u.y,width:u.width,height:u.height,boxSizing:"border-box",borderRadius:8}},e.createElement("div",{style:{padding:"4px 10px"}},s(m))):e.createElement("div",{key:m.id,ref:l(m.id),style:{position:"absolute",left:u.x,top:u.y,width:u.width,zIndex:2}},s(m))}),c.links.filter(m=>m.label).map(m=>e.createElement("div",{key:`${m.id}-label`,"data-link-label":m.id,title:m.label,className:"text-gray-500 dark:text-gray-400",style:{...Vr,left:m.points[0][0]+6,top:m.points[0][1]-14}},m.label)),r.onInsert&&c.links.filter(m=>!m.placeholder).map(m=>e.createElement(it,{key:m.id,link:m,...r,style:{position:"absolute",left:m.points[0][0],top:m.points[0][1]-12,width:62,height:24,zIndex:3}})))},_e="(min-width: 640px)",qr=()=>typeof window>"u"||!window.matchMedia||window.matchMedia(_e).matches,Jr=()=>{let[t,o]=E(qr);return L(()=>{if(!window.matchMedia)return;let s=window.matchMedia(_e),r=()=>o(s.matches);return s.addEventListener("change",r),()=>s.removeEventListener("change",r)},[]),t},Kr=({nodes:t,edges:o,draw:s,joints:r,children:n,style:a})=>Jr()?e.createElement("div",{"data-flow-rows":!0,style:{...Gr,...a}},n,e.createElement(Yr,{nodes:t,edges:o,draw:s,joints:r})):e.createElement(Ne,{nodes:t,edges:o,draw:s,joints:r,style:a},n),dt=Kr;var ze="Your change was not saved because the server could not be reached.",Zr="Your change was saved, but the canvas could not be refreshed. Reload the page to see it.",Ae=async({base:t,fetch:o,onFlow:s,onError:r})=>{let n=await o(t+".json",{headers:{Accept:"application/json"}}).catch(()=>null),a=n?.ok?await n.json().catch(()=>null):null;return a?s(a):r(Zr)},Oe=({base:t,token:o,fetch:s,onFlow:r,onError:n,onNotice:a,onWarning:p=()=>{}})=>async(c,l,m)=>{let u={base:t,fetch:s,onFlow:r,onError:n},x=await s(t+c,{method:l,headers:{"Content-Type":"application/json","X-CSRF-Token":o},body:m&&JSON.stringify(m)}).catch(()=>null);if(!x)return a(null),n(ze);let h=await x.json().catch(()=>({}));return h.unconnected?(a(null),n(null),p({path:c,steps:h.unconnected}),Ae(u)):(p(null),x.ok?(n(null),a(h.notice||null),Ae(u)):(a(null),n(h.error||"That change was refused")))},Te=({base:t,token:o,fetch:s,onError:r})=>async n=>{let a=new FormData;a.append("picture",n);let p=await s(t+"/pictures",{method:"POST",headers:{"X-CSRF-Token":o},body:a}).catch(()=>null);if(!p)return r(ze),null;let c=await p.json().catch(()=>({}));return p.ok?(r(null),c):(r(c.error||"That picture was refused"),null)};var Qr=(t,o,s)=>{let[r,n]=E(s),[a,p]=E(null),[c,l]=E(null),[m,u]=E(null),x=P(()=>Oe({base:t,token:o,fetch:(...d)=>window.fetch(...d),onFlow:n,onError:p,onNotice:l,onWarning:u}),[t,o]),h=P(()=>Te({base:t,token:o,fetch:(...d)=>window.fetch(...d),onError:p}),[t,o]);return{flow:r,error:a,notice:c,warning:m,setWarning:u,send:x,pickPicture:h}},Me=Qr;var ct=(t,o,s,r)=>{let n=t.left-s.left+r.scrollLeft,a=t.top-s.top+r.scrollTop;return o==="left"?{x:n,y:a+t.height/2}:o==="right"?{x:n+t.width,y:a+t.height/2}:o==="top"?{x:n+t.width/2,y:a}:{x:n+t.width/2,y:a+t.height}},Rr=(t,o,s)=>s&&o==="top"?{x:t.x,y:s.top}:t,ts=(t,o)=>o==="top"?{x:t.x,y:t.y-3}:o==="left"?{x:t.x-3,y:t.y}:o==="right"?{x:t.x+3,y:t.y}:{x:t.x,y:t.y+3},es=(t,o,s,r,n)=>{let a={straight:`M ${o.x} ${o.y} L ${s.x} ${s.y}`,turn:`M ${o.x} ${o.y} H ${s.x} V ${s.y}`,lane:`M ${o.x} ${o.y} V ${r} H ${s.x} V ${s.y}`,detour:`M ${o.x} ${o.y} H ${n} V ${s.y} H ${s.x}`}[t.route];return{...t,path:a,midX:t.route==="detour"?n:(o.x+s.x)/2,midY:t.route==="lane"?r:(o.y+s.y)/2}},os=(t,o,s,r)=>{let[n,a]=E([]),[p,c]=E({width:"100%",height:"100%"}),[l,m]=E([]);return R(()=>{let u=()=>{let h=o.current?.getBoundingClientRect();if(!h)return;c({width:o.current.scrollWidth,height:o.current.scrollHeight});let d=t.nodes.filter(f=>f.holds&&!f.loose&&s.current[f.id]).map(f=>{let _=s.current[f.id],v=_.getBoundingClientRect(),C=f.holds.flatMap(N=>s.current[N]?[s.current[N].getBoundingClientRect()]:[]),k=[{left:v.left,top:v.top,width:Math.max(v.width,_.scrollWidth),height:v.height},...C];return{id:f.id,bounds:It(k,h,o.current)}});m(d),a(t.edges.flatMap(f=>{let _=s.current[f.source]?.getBoundingClientRect(),v=s.current[f.target]?.getBoundingClientRect();if(!_||!v)return[];let C=ct(_,f.leaves,h,o.current),k=d.find(B=>B.id===f.target)?.bounds,N=ts(Rr(ct(v,f.enters,h,o.current),f.enters,k),f.enters),M=(ct(_,"bottom",h,o.current).y+ct(v,"top",h,o.current).y)/2,b=f.leaves==="left"?Math.min(C.x,N.x)-28:Math.max(C.x,N.x)+28;return[es(f,C,N,M,b)]}))};u(),window.addEventListener("resize",u);let x=new ResizeObserver(u);return o.current&&x.observe(o.current),()=>{window.removeEventListener("resize",u),x.disconnect()}},r),{links:n,extent:p,boxes:l}},Be=os;var De=(t,o)=>{let s=new Set(o),r=t,n=2;for(;s.has(r);)r=`${t}_${n++}`;return r};var Le=({send:t,onPress:o})=>s=>{let r=s.target.closest?.("[data-bar-action]");r&&(r.closest("details")?.removeAttribute("open"),o(),r.dataset.barPath&&t(r.dataset.barPath,"POST"))};var ss=8,ns={display:"flex",height:"100%",minHeight:0,fontSize:13,position:"relative"},as={flex:1,minWidth:0,display:"flex",flexDirection:"column",position:"relative"},is={flex:1,minHeight:0,overflow:"auto",position:"relative"},Ie={position:"absolute",top:56,left:16,zIndex:5,width:264,padding:12,borderRadius:8},ls={...Ie,position:"static",alignSelf:"flex-start"},ds={display:"grid",rowGap:64,columnGap:0,padding:40,justifyContent:"center",position:"relative"},$e={position:"sticky",zIndex:8,top:8,margin:"8px auto 0",width:"fit-content",padding:"6px 12px",borderRadius:6,fontSize:12},cs=({port:t,onCancel:o})=>e.createElement("div",{className:"bg-accent-100 text-accent-800 dark:bg-accent-900 dark:text-accent-100",style:$e},"Choose the step \u201C",t||"next","\u201D should lead to \u2014 ",e.createElement("button",{onClick:o,className:"text-accent-800 underline dark:text-accent-100",style:{border:"none",background:"none",cursor:"pointer",fontSize:12,padding:0}},"cancel")),ps=({message:t})=>e.createElement("p",{"data-canvas-error":!0,className:"bg-red-50 text-red-800 dark:bg-red-950 dark:text-red-200",style:$e},t),ms=({base:t,token:o,initial:s})=>{let{flow:r,error:n,notice:a,warning:p,setWarning:c,send:l,pickPicture:m}=Me(t,o,s),[u,x]=E(null),[h,d]=E(null),[f,_]=E(null),[v,C]=E(null),[k,N]=E(null),[M,b]=E(!1),B=Y({}),O=Y(null);L(()=>{let i=Le({send:l,onPress:()=>{x(null),b(!0)}});return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[l]),L(()=>{if(!M){c(null);return}let i=y=>{y.target.isConnected&&!y.target.closest("[data-builder-panel], [data-open-panel], [data-bar-action]")&&b(!1)};return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[M]),L(()=>{document.dispatchEvent(new CustomEvent("easy_flow:flow-named",{detail:r.flow?.title||r.flow?.slug}))},[r.flow?.title,r.flow?.slug]),L(()=>{document.dispatchEvent(new CustomEvent("easy_flow:flow-status",{detail:{status:r.flow?.status,publishes:r.flow?.publishes}}))},[r.flow?.status,r.flow?.publishes]);let H=P(()=>Object.fromEntries(r.nodes.map(i=>[i.id,i])),[r.nodes]),{links:pt,extent:K,boxes:mt}=Be(r,O,B,[r,u,H]),Z=P(()=>{let i={};return r.violations.forEach(y=>{var z;return(i[z=y.node]||(i[z]=[])).push(y)}),i},[r.violations]),g=r.direction==="left_to_right",S=P(()=>r.nodes.filter(i=>!i.loose),[r.nodes]),T=r.nodes.filter(i=>i.loose),W=P(()=>{let i={};return r.edges.forEach(y=>{var z;return(i[z=y.source]||(i[z]=[])).push(y.label||null)}),i},[r.edges]),U=Math.max(0,...S.map(i=>i.row))+1,X=Math.max(0,...S.map(i=>i.column))+1,V=i=>{if(!f)return;let[y,z]=f;_(null),y!==i&&l("/edges","POST",{from:y,to:i,on:z||null})},Q=i=>{if(i.isDefaultPrevented()||!v)return;i.preventDefault();let y=v;C(null);let z=O.current.getBoundingClientRect(),_t=$t(mt,{x:i.clientX-z.left+O.current.scrollLeft,y:i.clientY-z.top+O.current.scrollTop}),Ue=r.nodes.find(Xe=>Xe.holds?.includes(y))?.id||null;_t!==Ue&&l(`/steps/${y}/group`,"PATCH",{group:_t})},F=i=>[...r.palette,...r.unoffered||[]].find(y=>y.type===i?.type),j=r.nodes.find(i=>i.id===u),$=F(j),ut=(i,y={})=>l("/steps","POST",{id:De(i.type,r.nodes.map(z=>z.id)),type:i.type,from:y.from,to:y.to,on:y.on}),kt=i=>{let[y,z]=[k,v];N(null),C(null),y?ut(y,{from:i.source,to:i.target}):z&&l("/steps/"+z+"/move","PATCH",{from:i.source,to:i.target})},St=i=>{let y=O.current.getBoundingClientRect();return{x:i.clientX-y.left+O.current.scrollLeft+8,y:i.clientY-y.top+O.current.scrollTop+8}},Ct=(i,y)=>({node:{...i,ref:z=>{B.current[i.id]=z},violations:Z[i.id]||[],connected:y},selected:i.id===u,armed:f&&f[0]===i.id?f[1]:null,connecting:!!f&&f[0]!==i.id,onSelect:()=>f?V(i.id):x(i.id),onOpen:z=>window.location.assign(z),onDragStart:()=>C(i.id),onDragEnd:()=>C(null),hideStepTypeCodes:r.hide_step_type_codes,compact:g}),Nt=i=>e.createElement(e.Fragment,null,i.placeholder&&e.createElement(te,{node:{...i,ref:y=>{B.current[i.id]=y}},dragging:!!v,compact:g,onFill:()=>d({from:i.from,on:i.on,at:{x:16,y:52}}),onDrop:()=>{let y=v;C(null),y&&l("/edges","POST",{from:i.from,to:y,on:i.on})}}),i.holds&&e.createElement(et,{node:{...i,ref:y=>{B.current[i.id]=y}},header:ot(i,F(i),r.hide_step_type_codes),compact:g,onSelect:()=>f?V(i.id):x(i.id)}),!i.placeholder&&!i.holds&&e.createElement(gt,{...Ct(i,W[i.id]||[]),onArm:(y,z)=>d({from:i.id,on:y,at:St(z)})})),Et=T.length>0&&e.createElement("div",{"data-loose":!0,className:"border border-dashed border-gray-300 bg-gray-50 dark:border-zinc-700 dark:bg-zinc-900",style:g?ls:Ie},e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginBottom:6}},"Not in the flow yet \u2014 drag one onto a connection"),T.map(i=>e.createElement("div",{key:i.id,style:{marginBottom:8}},e.createElement(gt,{...Ct(i,[]),onArm:(y,z)=>{z.stopPropagation(),_([i.id,y])}}))));return e.createElement("div",{className:"text-gray-900 dark:text-gray-100",style:ns,onMouseUp:()=>C(null),onKeyDown:i=>{i.key==="Escape"&&(x(null),_(null),d(null))},tabIndex:-1},e.createElement(oe,{entries:r.palette,groups:r.step_groups||{},onPick:i=>ut(i),onCarry:N,onDrop:()=>N(null)}),e.createElement("div",{className:"bg-surface-50 dark:bg-surface-950",style:as},e.createElement("div",{ref:O,style:is,onClick:i=>{i.target===O.current&&(x(null),_(null),b(!1))},onDragOver:i=>{v&&i.preventDefault()},onDrop:Q},f&&e.createElement(cs,{port:f[1],onCancel:()=>_(null)}),n&&!M&&!j&&e.createElement(ps,{message:n}),e.createElement(se,{undoable:r.undoable,redoable:r.redoable,onAdd:()=>d({at:{x:16,y:52}}),onUndo:()=>{x(null),l("/undo","POST")},onRedo:()=>{x(null),l("/redo","POST")}}),!g&&mt.map(i=>e.createElement(Pt,{key:i.id,id:i.id,bounds:i.bounds,onDrop:()=>{let y=v;C(null),y&&l(`/steps/${y}/group`,"PATCH",{group:i.id})}})),!g&&e.createElement(ke,{links:Ht(pt,r.nodes),extent:K,dragging:v||k,alwaysShowInsertButtons:r.always_show_insert_buttons,onInsert:i=>d({from:i.source,to:i.target,at:{x:i.midX+30,y:i.midY}}),onRemove:i=>{x(null),l("/edges","DELETE",{from:i.source,to:i.target})},onDrop:kt}),!g&&Et,g&&e.createElement(dt,{nodes:S,edges:r.edges,draw:Nt,joints:{alwaysShowInsertButtons:r.always_show_insert_buttons,dragging:!!(v||k),onInsert:(i,y)=>d({from:i.source,to:i.target,at:St(y)}),onRemove:i=>{x(null),l("/edges","DELETE",{from:i.source,to:i.target})},onDrop:kt}},Et),!g&&e.createElement("div",{style:{...ds,gridTemplateColumns:`repeat(${X+1}, ${280/2}px)`,gridTemplateRows:`repeat(${U}, auto)`}},S.map(i=>e.createElement("div",{key:i.id,style:{gridRow:i.row+1,gridColumn:`${i.column+1} / span 2`,zIndex:2,marginTop:Wt(i,r.nodes)?ss-64:0}},Nt(i)))),h&&e.createElement(ee,{entries:r.palette,at:h.at,onDismiss:()=>d(null),hideStepTypeCodes:r.hide_step_type_codes,onConnect:h.on!==void 0?()=>{_([h.from,h.on]),d(null)}:null,onPick:i=>{let y=h;d(null),ut(i,y)}})),e.createElement(ye,{checks:r.checks||[],tabs:r.drawer_tabs||[],onSelect:x})),M&&!j&&e.createElement(pe,{flow:r.flow||{},changes:r.changes||[],refusal:n,notice:a,publishNote:r.publish_note,warning:p,onClose:()=>b(!1),onCreate:()=>l("/versions","POST"),onPublish:()=>l("/publish","POST"),onAccept:()=>l(p.path,"POST",{remove_unconnected:p.steps.map(i=>i.id)}),onDecline:()=>c(null),onSaveDetails:i=>l("/details","PATCH",{flow:i})}),j&&e.createElement(Rt,{node:j,fields:$?.fields||{},holds:$?.records||{},labels:$?.labels||{},explanations:$?.explanations||{},recordLabels:$?.record_labels||{},recordExplanations:$?.record_explanations||{},recordChoices:$?.record_choices||{},recordOutputsOf:$?.record_outputs_of||{},choices:jt(j,$),onClose:()=>x(null),onSave:i=>l(`/steps/${j.id}`,"PATCH",{config:i}),onPickPicture:m,refusal:n,notice:a,onDelete:()=>{x(null),l(`/steps/${j.id}`,"DELETE")}}))},He=ms;var us={display:"block",minWidth:118,boxSizing:"border-box",borderRadius:6,padding:"8px 10px",textDecoration:"none"},Ge={fontSize:12,fontWeight:500,lineHeight:1.3},fs={...Ge,textAlign:"center",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},We={done:"border-green-600 bg-green-50 dark:border-green-500 dark:bg-green-950",paused:"border-amber-500 bg-amber-50 dark:border-amber-400 dark:bg-amber-950",pending:"border-gray-300 bg-white text-gray-500 dark:border-zinc-700 dark:bg-zinc-900 dark:text-gray-400",failed:"border-red-600 bg-red-50 dark:border-red-500 dark:bg-red-950"},je={done:"text-green-700 dark:text-green-400",paused:"text-amber-800 dark:text-amber-300",pending:"text-gray-500 dark:text-gray-400",failed:"text-red-700 dark:text-red-400"},gs=t=>[t.label,t.ends_here&&t.mark].filter(Boolean).join(" \xB7 "),hs="ring-2 ring-accent-600 ring-offset-2 dark:ring-offset-zinc-950",xs=({node:t,selected:o=!1})=>{let s=t.address?"a":"div",r=t.begins_here||t.ends_here;return e.createElement(s,{"data-step":t.id,href:t.address||void 0,className:`${t.state==="paused"?"border-2":"border"} ${We[t.state]||We.pending}${o?` ${hs}`:""}`,style:us},!r&&e.createElement("div",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},t.type),e.createElement("div",{style:r?fs:Ge},gs(t),t.version&&e.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{fontWeight:400,marginLeft:4}},t.version)),t.status&&e.createElement("div",{className:je[t.state]||je.pending,style:{fontSize:11}},t.status))},Ve=xs;var ys={gap:12,padding:0,maxWidth:"100%",overflowX:"auto"},bs=({nodes:t,edges:o,selected:s})=>e.createElement(dt,{nodes:t,edges:o,joints:{},style:ys,draw:r=>r.holds?e.createElement(et,{node:r,header:ot(r,r,!1),compact:!0}):e.createElement(Ve,{node:r,selected:r.id===s})}),Fe=bs;ft("easy_flow/flow-editor",He);ft("easy_flow/run-view",Fe);document.addEventListener("easy_flow:flow-named",t=>{let o=document.querySelector("[data-flow-heading]");o&&(o.textContent=t.detail)});document.addEventListener("easy_flow:flow-status",({detail:t})=>{t.status&&document.querySelectorAll("[data-version-status]").forEach(o=>{o.textContent=t.status}),t.publishes&&document.querySelectorAll("[data-bar-action=publish]").forEach(o=>{o.textContent=`Publish v${t.publishes}`})});Bt(document,At);})();
@@ -4,6 +4,8 @@ const card = { display: "block", minWidth: 118, boxSizing: "border-box", borderR
4
4
 
5
5
  const named = { fontSize: 12, fontWeight: 500, lineHeight: 1.3 }
6
6
 
7
+ const bookendName = { ...named, textAlign: "center", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }
8
+
7
9
  const STATES = {
8
10
  done: "border-green-600 bg-green-50 dark:border-green-500 dark:bg-green-950",
9
11
  paused: "border-amber-500 bg-amber-50 dark:border-amber-400 dark:bg-amber-950",
@@ -18,6 +20,8 @@ const STATUS_LINES = {
18
20
  failed: "text-red-700 dark:text-red-400"
19
21
  }
20
22
 
23
+ const markedOf = (node) => [ node.label, node.ends_here && node.mark ].filter(Boolean).join(" · ")
24
+
21
25
  const marked = "ring-2 ring-accent-600 ring-offset-2 dark:ring-offset-zinc-950"
22
26
 
23
27
  const RunCard = ({ node, selected = false }) => {
@@ -27,7 +31,7 @@ const RunCard = ({ node, selected = false }) => {
27
31
  return (
28
32
  <Card data-step={node.id} href={node.address || undefined} className={`${node.state === "paused" ? "border-2" : "border"} ${STATES[node.state] || STATES.pending}${selected ? ` ${marked}` : ""}`} style={card}>
29
33
  {!bookend && <div className="font-mono text-gray-500 dark:text-gray-400" style={{ fontSize: 11 }}>{node.type}</div>}
30
- <div style={bookend ? { ...named, textAlign: "center" } : named}>{node.label}{node.version && <span className="text-gray-500 dark:text-gray-400" style={{ fontWeight: 400, marginLeft: 4 }}>{node.version}</span>}</div>
34
+ <div style={bookend ? bookendName : named}>{markedOf(node)}{node.version && <span className="text-gray-500 dark:text-gray-400" style={{ fontWeight: 400, marginLeft: 4 }}>{node.version}</span>}</div>
31
35
  {node.status && <div className={STATUS_LINES[node.state] || STATUS_LINES.pending} style={{ fontSize: 11 }}>{node.status}</div>}
32
36
  </Card>
33
37
  )
@@ -7,7 +7,7 @@ const card = { width: CARD, boxSizing: "border-box", borderRadius: 8 }
7
7
 
8
8
  const compactCard = { minWidth: 120, boxSizing: "border-box", borderRadius: 6 }
9
9
 
10
- const bookendCard = { padding: "8px 14px", textAlign: "center", fontWeight: 600 }
10
+ const bookendCard = { padding: "8px 14px", textAlign: "center", fontWeight: 600, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }
11
11
 
12
12
  const named = { fontWeight: 600, lineHeight: 1.3 }
13
13
 
@@ -23,6 +23,8 @@ const edge = (target, troubled, selected) => {
23
23
  const headingOf = (node, hideStepTypeCodes) =>
24
24
  hideStepTypeCodes && node.label === node.id ? node.type_name || node.label : node.label
25
25
 
26
+ const markedOf = (node, heading) => [ heading, node.ends_here && node.mark ].filter(Boolean).join(" · ")
27
+
26
28
  const typeLineOf = (node, heading, hideStepTypeCodes) => {
27
29
  if (!hideStepTypeCodes) return node.type
28
30
  return heading === node.type_name ? null : node.type_name
@@ -50,7 +52,7 @@ const StepCard = ({ node, selected, armed, connecting, onSelect, onOpen, onArm,
50
52
  cursor: pinned ? "default" : connecting ? "crosshair" : "grab"
51
53
  }}>
52
54
  {!bookend && typeAbove && typeLine && <div className="font-mono text-gray-500 dark:text-gray-400" style={{ fontSize: 11 }}>{typeLine}</div>}
53
- {bookend && <div className="text-gray-500 dark:text-gray-400" style={bookendCard}>{heading}</div>}
55
+ {bookend && <div className="text-gray-500 dark:text-gray-400" style={bookendCard}>{markedOf(node, heading)}</div>}
54
56
  {!bookend && <div style={compact ? compactName : named}>{heading}</div>}
55
57
  {node.violations.length > 0 && <div data-error-count className="text-red-600 dark:text-red-400" style={{ fontSize: 10 }}>{`${node.violations.length} error${node.violations.length === 1 ? "" : "s"}`}</div>}
56
58
  {!bookend && node.summary && node.violations.length === 0 && <div className={selected ? "text-accent-600 dark:text-accent-400" : "text-gray-500 dark:text-gray-400"} style={{ fontSize: 10 }}>{node.summary}</div>}
@@ -21,7 +21,7 @@ module EasyFlow
21
21
 
22
22
  def drawn_step(node)
23
23
  { "id" => node.id, "type" => node.type, "type_name" => step_type_for(node)&.step_name, "label" => label_for(node), "summary" => summary_of(node), "details" => drawn_by_type(node, :details_of).to_a, "links" => drawn_by_type(node, :links_of).to_a,
24
- "config" => node.config.merge(kept_values(node)), "ports" => [], "ends_here" => ends_here?(node), "begins_here" => begins_here?(node),
24
+ "config" => node.config.merge(kept_values(node)), "ports" => [], "ends_here" => ends_here?(node), "mark" => mark_of(node), "begins_here" => begins_here?(node),
25
25
  "starts_a_flow" => starts_a_flow?(node), "holds" => holds(node), "opens" => opens(node), "loose" => loose?(node), "choices" => choices_for(node), "record_choices" => record_choices_for(node), "placeholder" => false, "picture_url" => picture_url(node), **placed[node.id] }
26
26
  end
27
27
 
@@ -241,6 +241,10 @@ module EasyFlow
241
241
  step_type_for(node)&.ends_here? || false
242
242
  end
243
243
 
244
+ def mark_of(node)
245
+ node.config["mark"].presence if ends_here?(node)
246
+ end
247
+
244
248
  def loose?(node)
245
249
  @document.entry.present? && @document.reachable.exclude?(node.id)
246
250
  end
@@ -1,5 +1,7 @@
1
1
  module EasyFlow
2
2
  class Digest
3
+ Path = Struct.new(:recorded, :latest, :latest_times)
4
+
3
5
  def initialize(document, registry: EasyFlow.registry)
4
6
  @document = document
5
7
  @registry = registry
@@ -72,6 +74,28 @@ module EasyFlow
72
74
  step_type(node)&.settings&.requirements_for(node.config).to_a
73
75
  end
74
76
 
77
+ def item_value(key, state)
78
+ visit = VisitKey.parse(key)
79
+ box = holder_of(visit.step)
80
+ items_of(box, latest_values(state))[visit.item - 1] if box && visit.item
81
+ end
82
+
83
+ def items_ended(id, state)
84
+ box = step(id)
85
+ ended = items_of(box, latest_values(state)).each_index.map { |index| item_values(box, index + 1, state) }
86
+ failed = ended.count { |values| values.any? { |held, value| failed?(step(held), state.merge(held => value), {}) } }
87
+
88
+ { "result" => failed.zero? ? "passed" : "failed", "items" => ended, "passed" => ended.size - failed, "failed" => failed }
89
+ end
90
+
91
+ def repeats?(node)
92
+ step_type(node)&.repeats_held_steps? || false
93
+ end
94
+
95
+ def holder_of(key)
96
+ steps.find { |node| repeats?(node) && Array(node.config["holds"]).include?(VisitKey.parse(key).step) }
97
+ end
98
+
75
99
  def next_step(state, times = {})
76
100
  walk(state, times)[1]
77
101
  end
@@ -136,6 +160,8 @@ module EasyFlow
136
160
  visits[cursor.id] += 1
137
161
  answers_at_visit[cursor.id] = answered
138
162
  key = visit_key(cursor.id, visits[cursor.id])
163
+ held = repeats?(cursor) && walk_items(cursor, state, times, Path.new(recorded, latest, latest_times))
164
+ return [ recorded, held ] if held
139
165
  return [ recorded, cursor.with(id: key) ] if pending?(cursor, key, state)
140
166
 
141
167
  if state.key?(key)
@@ -144,12 +170,88 @@ module EasyFlow
144
170
  latest_times[cursor.id] = times[key] if times.key?(key)
145
171
  answered += 1 if step_type(cursor)&.awaits_input?
146
172
  end
147
- cursor = successor(cursor, reached(state, recorded).merge(latest), latest_times)
173
+ cursor = repeats?(cursor) ? box_exit(cursor) : successor(cursor, reached(state, recorded).merge(latest), latest_times)
148
174
  end
149
175
 
150
176
  [ recorded, nil ]
151
177
  end
152
178
 
179
+ def walk_items(box, state, times, path)
180
+ items_of(box, path.latest).each_index do |index|
181
+ held = walk_item(box, index + 1, state, times, path)
182
+ return held if held
183
+ end
184
+ nil
185
+ end
186
+
187
+ def walk_item(box, item, state, times, path)
188
+ visits = Hash.new(0)
189
+ recorded_at_visit = {}
190
+ cursor = first_held(box)
191
+
192
+ while cursor && held_by?(box, cursor)
193
+ return if visits[cursor.id].positive? && recorded_at_visit[cursor.id] == path.recorded.size
194
+
195
+ visits[cursor.id] += 1
196
+ recorded_at_visit[cursor.id] = path.recorded.size
197
+ key = item_key(cursor.id, item, visits[cursor.id])
198
+ return cursor.with(id: key) if pending?(cursor, key, state)
199
+
200
+ if state.key?(key)
201
+ path.recorded << key
202
+ path.latest[cursor.id] = state[key]
203
+ path.latest_times[cursor.id] = times[key] if times.key?(key)
204
+ end
205
+ routed = reached(state, path.recorded).merge(path.latest)
206
+ return if failed?(cursor, routed, path.latest_times)
207
+
208
+ cursor = successor(cursor, routed, path.latest_times)
209
+ end
210
+ end
211
+
212
+ def failed?(node, state, times)
213
+ step_type(node)&.route(node, state, times).to_s == "failed"
214
+ end
215
+
216
+ def items_of(box, latest)
217
+ step_id, output = step_type(box).list_named_by(box).split(".", 2)
218
+ listed = latest[step_id]
219
+ listed = listed[output] if listed.is_a?(Hash) && output
220
+ listed.is_a?(Array) ? listed : []
221
+ end
222
+
223
+ def item_key(id, item, visit)
224
+ VisitKey.new(step: id, item: item, visit: visit).to_s
225
+ end
226
+
227
+ def latest_values(state)
228
+ state.keys.map { |key| VisitKey.parse(key) }.reject(&:item).group_by(&:step)
229
+ .transform_values { |visits| state[visits.max_by(&:visit).to_s] }
230
+ end
231
+
232
+ def item_values(box, item, state)
233
+ visits = state.keys.map { |key| VisitKey.parse(key) }.select { |visit| visit.item == item }
234
+ Array(box.config["holds"]).filter_map do |held|
235
+ latest = visits.select { |visit| visit.step == held }.max_by(&:visit)
236
+ [ held, state[latest.to_s] ] if latest
237
+ end.to_h
238
+ end
239
+
240
+ def held_by?(box, node)
241
+ Array(box.config["holds"]).include?(node.id)
242
+ end
243
+
244
+ def first_held(box)
245
+ entering = @document.edges_from(box.id).first
246
+ entering && @document.node(entering.to)
247
+ end
248
+
249
+ def box_exit(box)
250
+ held = Array(box.config["holds"])
251
+ leaving = @document.edges.find { |edge| held.include?(edge.from) && !held.include?(edge.to) && edge.on.to_s != "failed" }
252
+ leaving && @document.node(leaving.to)
253
+ end
254
+
153
255
  def reached(state, recorded)
154
256
  state.reject { |key, _value| step(key) && !recorded.include?(key) }
155
257
  end
@@ -172,7 +274,7 @@ module EasyFlow
172
274
  def pending?(node, key, state)
173
275
  return false if state.key?(key)
174
276
 
175
- step_type(node)&.awaits_input? || acts?(node) || step_type(node)&.waits? || false
277
+ step_type(node)&.awaits_input? || acts?(node) || step_type(node)&.waits? || repeats?(node)
176
278
  end
177
279
 
178
280
  def acts?(node)
@@ -0,0 +1,20 @@
1
+ module EasyFlow
2
+ class ForEach
3
+ include Step
4
+
5
+ step_name "For each"
6
+
7
+ holds_steps
8
+ repeats_held_steps_for :list
9
+ needs_a_saved_run "Steps can only be run for each item in a flow that saves its runs."
10
+
11
+ setting :list, type: :string
12
+ setting :concurrency, type: :integer
13
+ setting :on_item_failure, type: :select, options: %w[continue stop]
14
+
15
+ output :result, values: %w[passed failed]
16
+ output :items
17
+ output :passed, type: :integer
18
+ output :failed, type: :integer
19
+ end
20
+ end
@@ -9,28 +9,37 @@ module EasyFlow
9
9
  setting :step, type: :previous_step, label: "Earlier step"
10
10
  setting :output, outputs_of: :step, label: "Earlier step's output"
11
11
  setting :from_run_owner, type: :boolean, label: "The run's owner"
12
+ setting :current_item, type: :boolean, label: "The current item"
12
13
  end
13
14
  end
14
15
 
15
16
  def self.values_of(node, state, run: nil)
16
- Array(node.config["inputs"]).to_h { |input| [ input["name"], value_of(input, state, run) ] }
17
+ Array(node.config["inputs"]).to_h { |input| [ input["name"], value_of(node, input, state, run) ] }
17
18
  end
18
19
 
19
- def self.value_of(input, state, run)
20
+ def self.value_of(node, input, state, run)
20
21
  return run&.owner_id if input["from_run_owner"]
22
+ return run&.digest&.item_value(node.id, state) if input["current_item"]
21
23
 
22
- input["step"].present? ? latest_output(input, state, run) : input["value"]
24
+ input["step"].present? ? latest_output(node, input, state, run) : input["value"]
23
25
  end
24
26
  private_class_method :value_of
25
27
 
26
- def self.latest_output(input, state, run)
27
- latest_visit = state.keys.select { |key| key.split("@").first == input["step"] }.max_by { |key| key.split("@")[1].to_i }
28
+ def self.latest_output(node, input, state, run)
29
+ latest_visit = latest_visit_of(input["step"], VisitKey.parse(node.id).item, state)
28
30
  return if unreported?(input, state[latest_visit], run)
29
31
 
30
32
  CompletedAt.value_of(state, {}, latest_visit, input["output"])
31
33
  end
32
34
  private_class_method :latest_output
33
35
 
36
+ def self.latest_visit_of(step, item, state)
37
+ visits = state.keys.to_h { |key| [ key, VisitKey.parse(key) ] }.select { |_key, visit| visit.step == step }
38
+ same_item = visits.select { |_key, visit| visit.item == item }
39
+ (same_item.presence || visits.reject { |_key, visit| visit.item }).max_by { |_key, visit| visit.visit }&.first
40
+ end
41
+ private_class_method :latest_visit_of
42
+
34
43
  def self.unreported?(input, recorded, run)
35
44
  run && input["output"].present? && !recorded.is_a?(Hash) && !run.digest.plain_value_is?(input["step"], input["output"])
36
45
  end
@@ -41,7 +41,11 @@ module EasyFlow
41
41
  shown = @steps.fetch(node.id, {}).to_h.symbolize_keys
42
42
 
43
43
  { "id" => node.id, "type" => node.type, "label" => Name.of(node, @registry), "state" => state_of(node, shown), "status" => shown[:status], "address" => (shown[:address] unless bookend?(node)), "version" => shown[:version],
44
- "begins_here" => step_type_for(node)&.begins_here? || false, "ends_here" => step_type_for(node)&.ends_here? || false, "holds" => holds(node), **header_of(node), **placed.fetch(node.id, {}) }
44
+ "begins_here" => step_type_for(node)&.begins_here? || false, "ends_here" => step_type_for(node)&.ends_here? || false, "mark" => mark_of(node), "holds" => holds(node), **header_of(node), **placed.fetch(node.id, {}) }
45
+ end
46
+
47
+ def mark_of(node)
48
+ node.config["mark"].presence if step_type_for(node)&.ends_here?
45
49
  end
46
50
 
47
51
  def hidden?(node)
@@ -64,6 +64,10 @@ module EasyFlow
64
64
  private
65
65
 
66
66
  def refusal_of(node)
67
+ own_refusal(node) || own_refusal(node && @digest.holder_of(node.id))
68
+ end
69
+
70
+ def own_refusal(node)
67
71
  @registry.fetch(node.type).unsaved_refusal if node && @registry.registered?(node.type)
68
72
  end
69
73
 
@@ -76,7 +80,7 @@ module EasyFlow
76
80
  end
77
81
 
78
82
  def goes_on?(node, state, times = {})
79
- acts?(node) || ready?(node, state, times) || decided?(node, state)
83
+ acts?(node) || @digest.repeats?(node) || ready?(node, state, times) || decided?(node, state)
80
84
  end
81
85
 
82
86
  def allowed(node, state)
@@ -101,6 +105,7 @@ module EasyFlow
101
105
 
102
106
  def result_of(node, state, run)
103
107
  return allowed(node, state).first.to_s if decided?(node, state)
108
+ return @digest.items_ended(node.id, state) if @digest.repeats?(node)
104
109
 
105
110
  acts?(node) ? @registry.fetch(node.type).process(node, state, run: run) : true
106
111
  end
@@ -103,6 +103,10 @@ module EasyFlow
103
103
  @holds_steps = true
104
104
  end
105
105
 
106
+ def repeats_held_steps_for(setting)
107
+ @repeats_held_steps_for = setting
108
+ end
109
+
106
110
  def chooses_flow_from_run(&chooser)
107
111
  @run_chooser = chooser
108
112
  end
@@ -179,7 +183,7 @@ module EasyFlow
179
183
 
180
184
  def to_step_type
181
185
  StepType.new(id: @id, step_name: @step_name, settings: settings, awaits_input: @awaits_input,
182
- ends_here: @ends_here, begins_here: @begins_here, starts_a_flow: @starts_a_flow, plays_the_picked_flow: @plays_the_picked_flow, holds_steps: @holds_steps, flow_chooser: @flow_chooser, run_chooser: @run_chooser, behaviour: @behaviour, routing: @routing,
186
+ ends_here: @ends_here, begins_here: @begins_here, starts_a_flow: @starts_a_flow, plays_the_picked_flow: @plays_the_picked_flow, holds_steps: @holds_steps, repeats_held_steps_for: @repeats_held_steps_for, flow_chooser: @flow_chooser, run_chooser: @run_chooser, behaviour: @behaviour, routing: @routing,
183
187
  display: @display, drawn_by: @drawn_by, naming_field: @naming_field, naming: @naming, summarizing: @summarizing, details: @details, linking: @linking,
184
188
  outputs: @declared_outputs, outputs_named_by: @outputs_named_by, answer_check: @answer_check, answer_labelling: @answer_labelling, readiness: @readiness, return_rule: @return_rule, unsaved_refusal: @unsaved_refusal)
185
189
  end
@@ -11,7 +11,7 @@ module EasyFlow
11
11
  attr_reader :id, :step_name, :settings, :naming_field, :naming, :outputs, :outputs_named_by, :drawn_by, :unsaved_refusal
12
12
 
13
13
  def initialize(id:, step_name:, settings:, awaits_input:, behaviour:, routing:,
14
- ends_here: false, begins_here: false, starts_a_flow: false, plays_the_picked_flow: false, holds_steps: false, flow_chooser: nil, run_chooser: nil, display: nil, drawn_by: nil,
14
+ ends_here: false, begins_here: false, starts_a_flow: false, plays_the_picked_flow: false, holds_steps: false, repeats_held_steps_for: nil, flow_chooser: nil, run_chooser: nil, display: nil, drawn_by: nil,
15
15
  naming_field: nil, naming: nil, summarizing: nil, details: [], linking: nil, outputs: [], outputs_named_by: nil, answer_check: nil, answer_labelling: nil, readiness: nil, return_rule: nil, unsaved_refusal: nil)
16
16
  @id = id
17
17
  @step_name = step_name
@@ -22,6 +22,7 @@ module EasyFlow
22
22
  @starts_a_flow = starts_a_flow
23
23
  @plays_the_picked_flow = plays_the_picked_flow
24
24
  @holds_steps = holds_steps
25
+ @repeats_held_steps_for = repeats_held_steps_for
25
26
  @flow_chooser = flow_chooser
26
27
  @run_chooser = run_chooser
27
28
  @behaviour = behaviour
@@ -134,6 +135,14 @@ module EasyFlow
134
135
  @holds_steps
135
136
  end
136
137
 
138
+ def repeats_held_steps?
139
+ @holds_steps && @repeats_held_steps_for.present?
140
+ end
141
+
142
+ def list_named_by(node)
143
+ node.config[@repeats_held_steps_for.to_s].to_s if repeats_held_steps?
144
+ end
145
+
137
146
  def chooses_flow_from_run?
138
147
  !@run_chooser.nil?
139
148
  end
@@ -0,0 +1,13 @@
1
+ module EasyFlow
2
+ VisitKey = Data.define(:step, :item, :visit) do
3
+ def self.parse(key)
4
+ step, *rest = key.to_s.split("@")
5
+ item = rest.shift.delete_prefix("item").to_i if rest.first.to_s.start_with?("item")
6
+ new(step: step, item: item, visit: (rest.first || 1).to_i)
7
+ end
8
+
9
+ def to_s
10
+ [ step, ("item#{item}" if item), (visit if visit > 1) ].compact.join("@")
11
+ end
12
+ end
13
+ end
@@ -31,6 +31,7 @@ module EasyFlow
31
31
  EasyFlow::CompareTwoValues.register
32
32
  EasyFlow::AllOrAny.register
33
33
  EasyFlow::Count.register
34
+ EasyFlow::ForEach.register
34
35
  EasyFlow::ReadData.register
35
36
  EasyFlow::WriteData.register
36
37
  EasyFlow::Wait.register
@@ -1,3 +1,3 @@
1
1
  module EasyFlow
2
- VERSION = "0.52.0"
2
+ VERSION = "0.54.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-develop
3
- description: Use PROACTIVELY for adding a step type to easy_flow flows (a step that asks the visitor something, takes several answers at once, computes a value from earlier answers, records several values under names an admin enters in the step's settings, counts how many times an earlier step was answered so a loop can give up after a number of tries, picks the next branch, or holds the visitor until something outside the flow has happened), adding a step type an admin draws as a box that holds other steps on the canvas, such as a "for each" step, branching on whether all or any of several comparisons of earlier answers hold, holding a run until a number of minutes after an earlier answer, the next time of day after it, or a date, branching on the hour, weekday or time an earlier step was completed or on the minutes between two completed steps, reading when each step was completed and when a waiting run will move on, showing a step differently depending on the visitor's stored run, branching on what a visitor ticked on a checklist, moving a paused run on once what it waits for has happened, refusing a blank or invalid answer to a step with a message, offering an admin a step setting whose options are read from the app's own records, letting an admin pick another flow of the same host in a step's settings, adding a step type that starts another flow and works out which flow and version to run from its own settings, adding a step type that starts another flow chosen from the visitor's run, such as its owner or its answers, offering a visitor only the answers to a step that their earlier answers allow, filling in a step that has only one possible answer without asking it, skipping a step that does not apply to a visitor, letting an admin edit a value stored on one of the app's own records from a step's settings on the canvas, serving a host's flows from the app's own controller and routes, starting a visitor's run on a published version of a flow other than the live one, acting when a visitor finishes a flow, acting on the output a visitor's flow ended with, telling whether a run ended at an End step or was stopped by a loop that came back with nothing new answered and at which step, keeping a flow from being published while a step that starts another flow names a flow or version that cannot run or leads back to the flow it sits in, finding the run of another flow that a Flow step started, the run a waiting run is waiting on, and the run that started it, sending a visitor back to the run that started a flow once that flow ends, handling a run whose starting run was removed with its flow, handling a Flow step that cannot start its flow, whose flow ended with no output, or whose flow was stopped by a loop, taking one file or several from a visitor at a step, showing a one-line summary of a step's settings on its canvas card, showing a step's recorded answer by a label the step type works out, and reading a run's recorded answers and question labels, including every answer ticked on a checklist and every visit's answer when a flow loops back to a question already asked, and showing on the app's own page where a run stands, with each step's state, status line and link — MUST BE USED instead of hand-rolling questionnaire steps, checkbox lists, file upload steps, branching logic, answer lists filtered by earlier answers, skipped questions, number comparisons, comparisons of two earlier answers, and/or conditions over several comparisons, hard-coded setting options, copying a record's value into a flow and back, answer validation, retry counters, timers or scheduled delays, step completion timestamps, polling or "come back later" pages, flow controllers, answer lookups or hand-drawn run diagrams.
3
+ description: Use PROACTIVELY for adding a step type to easy_flow flows (a step that asks the visitor something, takes several answers at once, computes a value from earlier answers, records several values under names an admin enters in the step's settings, counts how many times an earlier step was answered so a loop can give up after a number of tries, picks the next branch, or holds the visitor until something outside the flow has happened), adding a step type an admin draws as a box that holds other steps on the canvas, running the steps a For each box holds once per item of a list an earlier step recorded and reading each item's values and the passed and failed counts after the box, branching on whether all or any of several comparisons of earlier answers hold, holding a run until a number of minutes after an earlier answer, the next time of day after it, or a date, branching on the hour, weekday or time an earlier step was completed or on the minutes between two completed steps, reading when each step was completed and when a waiting run will move on, showing a step differently depending on the visitor's stored run, branching on what a visitor ticked on a checklist, moving a paused run on once what it waits for has happened, refusing a blank or invalid answer to a step with a message, offering an admin a step setting whose options are read from the app's own records, letting an admin pick another flow of the same host in a step's settings, adding a step type that starts another flow and works out which flow and version to run from its own settings, adding a step type that starts another flow chosen from the visitor's run, such as its owner or its answers, offering a visitor only the answers to a step that their earlier answers allow, filling in a step that has only one possible answer without asking it, skipping a step that does not apply to a visitor, letting an admin edit a value stored on one of the app's own records from a step's settings on the canvas, serving a host's flows from the app's own controller and routes, starting a visitor's run on a published version of a flow other than the live one, acting when a visitor finishes a flow, acting on the output a visitor's flow ended with, telling whether a run ended at an End step or was stopped by a loop that came back with nothing new answered and at which step, keeping a flow from being published while a step that starts another flow names a flow or version that cannot run or leads back to the flow it sits in, finding the run of another flow that a Flow step started, the run a waiting run is waiting on, and the run that started it, sending a visitor back to the run that started a flow once that flow ends, handling a run whose starting run was removed with its flow, handling a Flow step that cannot start its flow, whose flow ended with no output, or whose flow was stopped by a loop, taking one file or several from a visitor at a step, showing a one-line summary of a step's settings on its canvas card, showing a step's recorded answer by a label the step type works out, and reading a run's recorded answers and question labels, including every answer ticked on a checklist and every visit's answer when a flow loops back to a question already asked, and showing on the app's own page where a run stands, with each step's state, status line and link — MUST BE USED instead of hand-rolling questionnaire steps, checkbox lists, file upload steps, branching logic, answer lists filtered by earlier answers, skipped questions, number comparisons, comparisons of two earlier answers, and/or conditions over several comparisons, hard-coded setting options, copying a record's value into a flow and back, answer validation, retry counters, timers or scheduled delays, step completion timestamps, polling or "come back later" pages, flow controllers, answer lookups or hand-drawn run diagrams.
4
4
  tools: Read, Write, Edit, Grep
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -9,7 +9,7 @@ This local follows the steps below exactly and invents none. Where a step names
9
9
 
10
10
  ## What easy_flow is
11
11
 
12
- A Rails engine for flows an admin draws on a canvas and a visitor runs one step at a time. Each step is an instance of a step type. The engine ships seventeen: start (`:start`), end (`:terminal`, whose one setting is the output an admin writes for a flow that ends there), question (`:question`, a question with a list of answers of which the visitor picks one, which the admin can mark required so a blank answer is refused), checklist (`:checklist`, a question with a list of answers of which the visitor ticks any number, which the admin can mark required so a visitor who ticks nothing is refused), Multiple select (`:multiple_select`, a question with a category and a list of answers, each with a value, a label and a weight, of which the visitor ticks any number, recording the list of ticked values, which the admin can mark required so a visitor who ticks nothing is refused with `Pick at least one answer to go on.`), Fill in the blank (`:fill_in_the_blank`, a question with a category and a list of accepted answers, each with a value, which the visitor answers by typing into a text box, recording the text exactly as typed, whose accepted answers are never sent to the visitor's page, which the admin can mark required so a visitor who types nothing or only spaces is refused with `Type an answer to go on.`; easy_flow records the answer and does not mark it right or wrong), File upload (`:file_upload`, a question the visitor answers by choosing one file from a file upload control labelled with the question text, with an admin setting listing the accepted file types as comma-separated extensions such as `.pdf, .png`, which limits the visitor's file picker to those types and is shown under the control as `Accepts` followed by the list as the admin wrote it, such as `Accepts .pdf, .png`, which the admin can mark required so a visitor who chooses no file is refused, and whose recorded answer is the reference the host's file store returned for the file), five that pick a branch from earlier answers with no code — condition (`:condition`, is or is not a chosen value, where the admin must pick one of the earlier step's outputs and the answer is read from that output when the earlier step recorded several and whole otherwise, so a Condition cannot be completed on a step whose type declares no output), switch (`:switch`, follows the connection labelled with the answer), compare (`:compare`, reads the answer as a number, from the output the admin picks when the earlier step recorded several, and checks it by more than, less than, at least or at most against an amount) and Compare two values (`:compare_two_values`, reads the answers of two earlier steps the admin picks as numbers, reading each from the output the admin picks when that step recorded several, and checks the first by more than, less than, at least, at most or equal to against the second plus an amount the admin may give, a blank amount adding nothing, checking the first against the amount alone when the admin leaves the second step empty, following its `true` or `false` connection, and following `false` when either answer is missing, is an array or is not a number) and All of or Any of (`:all_or_any`, holds a list of comparisons the admin enters and a `Must hold` setting of `all of` or `any of`, where each comparison asks for the same things as a Compare two values step, a step, its output, a comparison, an amount, and an optional second step and its output, and is checked the same way, a comparison with no second step checking the first answer against the amount alone, following its `true` connection when every comparison holds for `all of` or at least one holds for `any of`, and its `false` connection otherwise, including when it holds no comparisons, a comparison whose answer is missing, is an array or is not a number counting as not holding) — Count (`:count`, which acts without the visitor and records a whole number, how many visits to an earlier step the admin picks the run has recorded, counting only visits that gave the answer the admin picks or every visit when the admin picks none, reading that answer from the output the admin picks when the earlier step recorded several, named on the canvas `Count` followed by the earlier step's id and the answer, such as `Count tests failed`, and recording a new count under its own visit key each time a loop reaches it, so a compare step after it can end a loop once the count reaches an amount), Read data and Write data (`:read_data` and `:write_data`, which ask the app to carry out one thing from what it says can be read or written, with named inputs, and follow a `passed` or `failed` connection; `easy_flow-install` sets what the app offers), Wait (`:wait`, which holds the run until a time worked out from an earlier step the admin picks as `Counting from`; see "Hold a run until a time"), and Flow (`:flow_step`, names another flow of the same host and the number of one of its versions, with one connection for each different output that version's End steps write, and named on the canvas by that flow's title and the version number, such as `Intake, version 2`). On a compare, Compare two values or Count step, and in each comparison of an All of or Any of step, once the admin picks an earlier step, the admin must also pick which of that step's outputs to read: until then the step's card shows a warning that the step `needs a value for Output`, `needs a value for Other output` for a Compare two values step's second step, or `needs a value for Output in Comparisons entry <n>` and `needs a value for Other output in Comparisons entry <n>` for the comparison at position `n` counting from 1, and saving the flow as a new version and publishing it are refused. When a stored run stops at a Flow step, a run of the named flow is started on the named version, and the first run waits on the Flow step. When the second run ends with an output, that output is recorded in the first run at the Flow step, and the first run moves on along the connection labelled with that output. When the second run ends with no output, nothing is recorded and the first run stays waiting at the Flow step. On a question and on a checklist the admin can give each answer info, a longer explanation the visitor opens with an info button beside that answer. An admin may connect a step back to an earlier one, so a flow can ask the same question more than once, and each visit's answer is kept. The time each step visit was completed is kept together with its recorded value; see "Read when steps were completed". A File upload step takes a file only in a flow the admin set to save each step. In a flow set to save on finish or to save nothing, a visitor who chooses a file is shown `A file can only be uploaded in a flow that saves its runs.` and cannot go on with it. Before writing a step type to ask for one answer or several, to take a file, to branch on an answer or a number, to branch on how two earlier answers compare, to branch on whether all or any of several comparisons hold, to branch on when an earlier step was completed, to count the visits to an earlier step, or to hold a run until a time, ask the developer whether an admin placing one of the built-in types on the canvas is enough. None of condition, switch, compare, Compare two values or All of or Any of reads a checklist's answer, so branching on what a visitor ticked takes a step type of the app's own that defines `route`. Use this local when the app needs a step type of its own, needs a host's flows on its own pages with its own behaviour when a visitor finishes, needs a visitor's earlier answers to decide which answers a later step offers, or needs to read what a visitor answered. It assumes easy_flow is already installed and a host is declared; if not, hand off to `easy_flow-install` first.
12
+ A Rails engine for flows an admin draws on a canvas and a visitor runs one step at a time. Each step is an instance of a step type. The engine ships eighteen: start (`:start`), end (`:terminal`, whose one setting is the output an admin writes for a flow that ends there), question (`:question`, a question with a list of answers of which the visitor picks one, which the admin can mark required so a blank answer is refused), checklist (`:checklist`, a question with a list of answers of which the visitor ticks any number, which the admin can mark required so a visitor who ticks nothing is refused), Multiple select (`:multiple_select`, a question with a category and a list of answers, each with a value, a label and a weight, of which the visitor ticks any number, recording the list of ticked values, which the admin can mark required so a visitor who ticks nothing is refused with `Pick at least one answer to go on.`), Fill in the blank (`:fill_in_the_blank`, a question with a category and a list of accepted answers, each with a value, which the visitor answers by typing into a text box, recording the text exactly as typed, whose accepted answers are never sent to the visitor's page, which the admin can mark required so a visitor who types nothing or only spaces is refused with `Type an answer to go on.`; easy_flow records the answer and does not mark it right or wrong), File upload (`:file_upload`, a question the visitor answers by choosing one file from a file upload control labelled with the question text, with an admin setting listing the accepted file types as comma-separated extensions such as `.pdf, .png`, which limits the visitor's file picker to those types and is shown under the control as `Accepts` followed by the list as the admin wrote it, such as `Accepts .pdf, .png`, which the admin can mark required so a visitor who chooses no file is refused, and whose recorded answer is the reference the host's file store returned for the file), five that pick a branch from earlier answers with no code — condition (`:condition`, is or is not a chosen value, where the admin must pick one of the earlier step's outputs and the answer is read from that output when the earlier step recorded several and whole otherwise, so a Condition cannot be completed on a step whose type declares no output), switch (`:switch`, follows the connection labelled with the answer), compare (`:compare`, reads the answer as a number, from the output the admin picks when the earlier step recorded several, and checks it by more than, less than, at least or at most against an amount) and Compare two values (`:compare_two_values`, reads the answers of two earlier steps the admin picks as numbers, reading each from the output the admin picks when that step recorded several, and checks the first by more than, less than, at least, at most or equal to against the second plus an amount the admin may give, a blank amount adding nothing, checking the first against the amount alone when the admin leaves the second step empty, following its `true` or `false` connection, and following `false` when either answer is missing, is an array or is not a number) and All of or Any of (`:all_or_any`, holds a list of comparisons the admin enters and a `Must hold` setting of `all of` or `any of`, where each comparison asks for the same things as a Compare two values step, a step, its output, a comparison, an amount, and an optional second step and its output, and is checked the same way, a comparison with no second step checking the first answer against the amount alone, following its `true` connection when every comparison holds for `all of` or at least one holds for `any of`, and its `false` connection otherwise, including when it holds no comparisons, a comparison whose answer is missing, is an array or is not a number counting as not holding) — Count (`:count`, which acts without the visitor and records a whole number, how many visits to an earlier step the admin picks the run has recorded, counting only visits that gave the answer the admin picks or every visit when the admin picks none, reading that answer from the output the admin picks when the earlier step recorded several, named on the canvas `Count` followed by the earlier step's id and the answer, such as `Count tests failed`, and recording a new count under its own visit key each time a loop reaches it, so a compare step after it can end a loop once the count reaches an amount), Read data and Write data (`:read_data` and `:write_data`, which ask the app to carry out one thing from what it says can be read or written, with named inputs, and follow a `passed` or `failed` connection; `easy_flow-install` sets what the app offers), Wait (`:wait`, which holds the run until a time worked out from an earlier step the admin picks as `Counting from`; see "Hold a run until a time"), and Flow (`:flow_step`, names another flow of the same host and the number of one of its versions, with one connection for each different output that version's End steps write, and named on the canvas by that flow's title and the version number, such as `Intake, version 2`), and For each (`:for_each`, a group step drawn as a dashed box that runs the steps it holds once for each item of a list an earlier step recorded; see "Run steps once per item with a for_each step"). On a compare, Compare two values or Count step, and in each comparison of an All of or Any of step, once the admin picks an earlier step, the admin must also pick which of that step's outputs to read: until then the step's card shows a warning that the step `needs a value for Output`, `needs a value for Other output` for a Compare two values step's second step, or `needs a value for Output in Comparisons entry <n>` and `needs a value for Other output in Comparisons entry <n>` for the comparison at position `n` counting from 1, and saving the flow as a new version and publishing it are refused. When a stored run stops at a Flow step, a run of the named flow is started on the named version, and the first run waits on the Flow step. When the second run ends with an output, that output is recorded in the first run at the Flow step, and the first run moves on along the connection labelled with that output. When the second run ends with no output, nothing is recorded and the first run stays waiting at the Flow step. On a question and on a checklist the admin can give each answer info, a longer explanation the visitor opens with an info button beside that answer. An admin may connect a step back to an earlier one, so a flow can ask the same question more than once, and each visit's answer is kept. The time each step visit was completed is kept together with its recorded value; see "Read when steps were completed". A File upload step takes a file only in a flow the admin set to save each step. In a flow set to save on finish or to save nothing, a visitor who chooses a file is shown `A file can only be uploaded in a flow that saves its runs.` and cannot go on with it. Before writing a step type to ask for one answer or several, to take a file, to branch on an answer or a number, to branch on how two earlier answers compare, to branch on whether all or any of several comparisons hold, to branch on when an earlier step was completed, to count the visits to an earlier step, or to hold a run until a time, ask the developer whether an admin placing one of the built-in types on the canvas is enough. None of condition, switch, compare, Compare two values or All of or Any of reads a checklist's answer, so branching on what a visitor ticked takes a step type of the app's own that defines `route`. Use this local when the app needs a step type of its own, needs a host's flows on its own pages with its own behaviour when a visitor finishes, needs a visitor's earlier answers to decide which answers a later step offers, or needs to read what a visitor answered. It assumes easy_flow is already installed and a host is declared; if not, hand off to `easy_flow-install` first.
13
13
 
14
14
  ## Interface
15
15
 
@@ -184,25 +184,25 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
184
184
  ```
185
185
 
186
186
  Here `PlanFlow.for_customer` is the app's own lookup, returning `{ flow: <id>, version: <number> }` or `nil`.
187
- - `holds_steps` — a step of the type holds other steps of the same flow, such as a "for each" step. Ask the developer what the step should do with the steps it holds when a run reaches it. Do not pick, since the engine does nothing with them at run time.
187
+ - `holds_steps` — a step of the type holds other steps of the same flow. Ask the developer what the step should do with the steps it holds when a run reaches it. Do not pick. To run the held steps once per item of a list, place the built-in For each step instead of declaring a type; see "Run steps once per item with a for_each step".
188
188
  - On the canvas, a step of the type is drawn as a dashed box around the steps it holds, with a header line at its top in place of a step card. The header is the type's id followed by each filled-in setting as `<name>: <value>`, or `<name> <value>` for an `integer` or `float` setting, joined by ` · `, leaving out a blank setting and a setting whose value is a list or an array. On a host that hides step type codes, set through `easy_flow-install`, the header uses the type's `step_name` and each setting's label instead.
189
189
  - Clicking the header opens the step's settings. The header shows none of the error counts a step card shows, and has none of a card's buttons for starting a connection.
190
190
  - An admin puts a step in the box by dragging it onto the box, and takes it out by dragging it onto the canvas outside the box. A step is held by one group step at a time, a group step cannot hold itself or be put inside another group step, and a step cannot be moved into a step whose type does not declare `holds_steps`. Moving a step in or out leaves every connection as it was.
191
191
  - The ids of the steps held are kept in the flow's document under `holds` on the group step, so `node.config["holds"]` is an array of step ids, in the order they were moved in, or is missing when no step was ever moved in. Read it with `Array(node.config["holds"])`. Removing a held step takes its id out of the list, and saving the group step's settings keeps the list as it was.
192
192
  - The type must not declare a setting named `holds`, since a value saved under that name is dropped.
193
193
  - A run follows connections only. A run reaching a step of a type that declares none of `awaits_input`, `process`, `route` or `waits_until` passes on along its connection, and the steps it holds run once, where their connections place them, like any other steps.
194
+ - Never give the type the id `for_each`, which the built-in For each step takes.
194
195
 
195
196
  ```ruby
196
197
  module FlowSteps
197
- class ForEach
198
+ class Section
198
199
  include EasyFlow::Step
199
200
 
200
- step_name "For each"
201
+ step_name "Section"
201
202
 
202
203
  holds_steps
203
204
 
204
- setting :list, type: :string
205
- setting :on_item_failure, type: :select, options: %w[continue stop]
205
+ setting :title, type: :string
206
206
  end
207
207
  end
208
208
  ```
@@ -331,6 +331,8 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
331
331
  - `run: nil` in `process` is optional and must be written with its default. With it the step is given the stored run, or `nil` in a flow that saves no runs. A `process` without it keeps working as `process(node, state)`.
332
332
  - `EasyFlow::Inputs.values_of(node, state)` keeps working with those two arguments, and an entry with `The run's owner` ticked then gives nothing. Code outside `process` that reads a stored run's inputs passes the run itself, as `EasyFlow::Inputs.values_of(step, run.recorded.stringify_keys, run: run)`.
333
333
  - An entry that names an earlier step reads that step's output, at its latest visit when a loop reached it more than once. Any other entry gives its fixed value.
334
+ - An entry with `The current item` ticked, on a step held by a For each step, gives the value of the item that step is running for. It is stored as `"current_item" => true`, and gives nothing when no run is passed or the step is not held by a For each step.
335
+ - On a step held by a For each step, an entry naming another held step reads that step's latest visit for the same item, and an entry naming a step outside the box reads it as usual.
334
336
  - `state` in `process` still holds every visit under its own key, so a step type that adds up every visit keeps working.
335
337
  - An earlier step that recorded a plain value gives that value for whichever output the entry names.
336
338
  - `process` is not given completion times, so an entry naming "Hour completed", "Weekday completed" or "Minutes since 1970 when completed" gives nothing.
@@ -585,6 +587,36 @@ Use this when a visitor's run should stop until a set time has passed, such as a
585
587
  3. The view lays the steps out left to right whatever the host's `canvas_direction`, as the same graph a left-to-right canvas draws: compact cards in columns by stage, every connection drawn as a line labelled with the answer it is taken on, and a group step's box holding its steps as their own small graph. A flow wider than its box scrolls sideways inside it. On a screen narrower than 640 pixels each step sits on a row of its own with its connections listed under it. The Start and End steps are drawn as cards with their name alone, as the editor draws them, with every line into an End step and its branch label. The Start card is done once any step the app supplied has a state other than pending, and pending before that. A Start or End card is never a link, even when the app gives it an address, since neither has a page of its own. On a phone they are listed one per row with the other steps. It has no buttons and nothing on it changes the flow.
586
588
  4. Ask the developer what each step's status line says and where each card links. Do not pick.
587
589
 
590
+ ### Run steps once per item with a for_each step
591
+
592
+ 1. Ask the developer which earlier step records the list, and under which of its outputs. The list must be recorded as an array, such as `{ "variants" => ["short", "long"] }`.
593
+ 2. On the canvas, place a For each step and fill in its settings:
594
+ - `List` — the earlier step and its output as text, `<step>.<output>`, such as `outline.variants`, or the step id alone when it records the array as its plain value.
595
+ - `Concurrency` — how many items may run at the same time. It is saved and shown in the box's header, and items still run one after another.
596
+ - `On item failure` — `continue` or `stop`. It is saved and shown in the box's header, and a failed item still lets the next item start.
597
+ 3. Drag the steps to run per item into the box. Connect the For each step to the first held step, connect the held steps to each other, and connect the last held step to the step after the box.
598
+ 4. Publish the flow set to save each step. A For each step reached in a flow set to save on finish or to save nothing shows the visitor `Steps can only be run for each item in a flow that saves its runs.` and goes no further, at the For each step or at any step it holds.
599
+ 5. What then holds when a stored run reaches the For each step:
600
+ - The run walks the held steps for item 1, then item 2, and so on in list order, one item at a time.
601
+ - Each visit of a held step is recorded under `<step>@item<n>`, counting items from 1, such as `write@item2`. A held step visited again inside one item, such as after a `retry` connection back to itself, is recorded as `<step>@item<n>@<visit>`, such as `write@item2@2`, and other items' visits are left as they were.
602
+ - `run.next_step(run.recorded)` returns the held step to run next with that key as its `id`, so the app records its value with `run.record(step.id, value)` and reads its inputs with `EasyFlow::Inputs.values_of(step, run.recorded.stringify_keys, run: run)`.
603
+ - An item ends when its walk leaves the box, or when a held step's `route` returns `"failed"`, and the next item starts.
604
+ - Once every item has ended, `run.advance` records the For each step's own value under its id: `result` is `"passed"` when no item failed and `"failed"` otherwise, `items` is an array with one hash per item mapping each held step it reached to that step's latest value for the item, and `passed` and `failed` count the items.
605
+ - A list that is missing, is not an array or is empty runs no items, records `items` as `[]`, and the run goes on to the step after the box.
606
+ - A step after the box reads `result`, `items`, `passed` or `failed` through an input naming the For each step and that output.
607
+
608
+ ```ruby
609
+ step = run.next_step(run.recorded)
610
+ step.id
611
+ # => "write@item2"
612
+ EasyFlow::Inputs.values_of(step, run.recorded.stringify_keys, run: run)
613
+ # => { "variant" => "long" }
614
+ run.record(step.id, { "result" => "passed", "title" => "Long copy" })
615
+ run.advance
616
+ run.recorded[:variants]
617
+ # => { "result" => "passed", "items" => [{ "write" => { ... } }, ...], "passed" => 3, "failed" => 0 }
618
+ ```
619
+
588
620
  ### Read a run and its answers
589
621
 
590
622
  1. Find runs scoped to one host so one host never sees another's: `EasyFlow::Run.joins(:flow).where(easy_flow_definitions: { host: "intake" })`.
@@ -625,7 +657,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
625
657
  ## Conventions
626
658
 
627
659
  - A step type's id comes from its class name or the id passed to `EasyFlow.step`, and it is stored in flow documents, so renaming the class or id breaks every flow that uses it.
628
- - Never give a step type one of the built-in ids: `start`, `terminal`, `question`, `checklist`, `multiple_select`, `fill_in_the_blank`, `file_upload`, `condition`, `switch`, `compare`, `compare_two_values`, `all_or_any`, `count`, `read_data`, `write_data`, `wait`, `flow_step`.
660
+ - Never give a step type one of the built-in ids: `start`, `terminal`, `question`, `checklist`, `multiple_select`, `fill_in_the_blank`, `file_upload`, `condition`, `switch`, `compare`, `compare_two_values`, `all_or_any`, `count`, `read_data`, `write_data`, `wait`, `flow_step`, `for_each`.
629
661
  - Register class-based step types inside `to_prepare`. A type registered anywhere else is lost on code reload in development.
630
662
  - Registering a type does not put it in the palette of a host that names a list of offered step types without the type's id. Which step types a host offers is set through `easy_flow-install`, not here.
631
663
  - A type that declares `ends_here` is in every host's palette, and a type that declares `begins_here` is in no host's palette.
@@ -646,12 +678,13 @@ Use this when a visitor's run should stop until a set time has passed, such as a
646
678
  - A `:previous_step` setting is required unless declared `optional: true`, and an `outputs_of:` setting must be filled once the step it reads is picked, or the flow cannot be saved as a version or published.
647
679
  - Only the canvas's Create version and Publish requests remove unconnected steps, and only when the request's `remove_unconnected` names exactly the steps unconnected at that moment. `Definition#publish`, `Definition#create_version` and `Validator#violations` never remove one, and `violations` lists each as `unreachable`, so app code that checks `violations` before publishing goes on refusing such a flow. A request that names none is answered with status 422, the refusal in `error`, and the steps in `unconnected`.
648
680
  - A type that routes declares the values its output takes, or the canvas offers no connections to label.
649
- - A step of a `holds_steps` type keeps the ids of the steps it holds in `node.config["holds"]`, never declares a setting named `holds`, and changes nothing about how a run moves, so what it does with the steps it holds is the type's own code.
681
+ - A step of a `holds_steps` type keeps the ids of the steps it holds in `node.config["holds"]`, never declares a setting named `holds`, and changes nothing about how a run moves, so what it does with the steps it holds is the type's own code, apart from the built-in For each step, which runs them once per item.
650
682
  - An output named by `outputs_named_by` takes its name from an entry's `name`, lists no values, and is never a connection leaving the step.
651
683
  - A run starts only on a version its own flow has published and not retired or withdrawn, and any other version raises `ActiveRecord::RecordInvalid`.
652
684
  - Always read a run against `run.pinned_definition`, never the flow's live version, since a run keeps the version it started on after a new one is published.
653
685
  - Always look flows and runs up through a host.
654
- - In a flow that loops, a later visit's answer is keyed `<id>@<n>`, so code that reads answers never assumes one answer per step id. A step id may not contain `@`, and a flow with one is refused when published.
686
+ - In a flow that loops, a later visit's answer is keyed `<id>@<n>`, and a step held by a For each step is keyed `<id>@item<n>` or `<id>@item<n>@<visit>`, so code that reads answers never assumes one answer per step id, and takes the part of a key before the first `@` to find its step.
687
+ - A Count step and any code that reads every visit of a step together count a held step's visits across all items. A step id may not contain `@`, and a flow with one is refused when published.
655
688
  - A loop that comes back to a step with no answer given since the last visit to it ends the flow there and `run.stopped_on_loop` names that step, so every loop needs a step that awaits input.
656
689
  - `run.ended_at_end?` is `true` only for a run whose last step reached is of an `ends_here` type, so a run a loop stopped, or one that ended at a step with no connection to follow, is never counted as ended at an End step.
657
690
  - A step's input field is named `answers[<step.id>]` for one value or `answers[<step.id>][]` for several. Any other name is ignored, and a hash is treated as blank.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-info
3
- description: Use to learn what easy_flow offers — guided flows an admin draws on a canvas and a visitor runs one step at a time, versioned documents of steps and connections, flows that loop back to ask a step again, a loop that stops a run when nothing new was answered and the step it came back to, whether a run ended at an End step, hosts and the step types each offers its admins, runs and the published version each starts on, each visit a run records with its value and the time the step was completed, and the output a flow gives when it ends, the built-in step types including questions and checklists that can require an answer and explain each answer behind an info button, file upload steps that hand a visitor's file to the app's file store and read it back by its name, and branching on an answer, including one named output of a step that recorded several, on comparing a number with an amount, or on comparing two earlier answers or one earlier answer with an amount alone, steps flagged when they name an earlier step without choosing which of its outputs to read, branching on a list of such comparisons that must all hold or of which any one must hold, branching on the hour, weekday or minute a step was completed, Wait steps that hold a run until a number of minutes or a time of day after an earlier step was completed, or until a date, and are named after what they wait for, the Check again button a visitor sees at a waiting step in a flow that keeps nothing, Count steps that count how often an earlier step was answered so a loop can give up after a number of tries, Flow steps that name another flow, open its canvas when their card is clicked with a button back to the flow it was opened from, start a run of it for the same owner when a stored run reaches them, are flagged when the flow or version they name cannot run or leads back to the flow they sit in, let the waiting run name that inner run, move that run on along the output it ends with, leave it waiting when the inner run is stopped by a loop, and fail with an error naming the step when its version was taken out of service or its inner run ended with no output, removing a flow and why it is refused while a waiting run depends on it, step types the host app registers, including ones whose outputs are named by the entries an admin lists in one of their settings, ones that start another flow and work out which flow and version to run from their own settings and are named after that flow, or choose it from the run they are in, the answers a host allows a step in a run and the steps it fills in or passes over, the checks they make on an answer, what a step shows a visitor and how that can depend on the visitor's run, and steps that hold a run until something outside the flow has happened, group steps drawn as a box an admin drags steps into and out of, and the settings an admin fills in, including picks whose options come from the app's data, choices drawn as radio cards with a hint under each, and settings kept on one of the app's own records.
3
+ description: Use to learn what easy_flow offers — guided flows an admin draws on a canvas and a visitor runs one step at a time, versioned documents of steps and connections, flows that loop back to ask a step again, a loop that stops a run when nothing new was answered and the step it came back to, whether a run ended at an End step, hosts and the step types each offers its admins, runs and the published version each starts on, each visit a run records with its value and the time the step was completed, and the output a flow gives when it ends, the built-in step types including questions and checklists that can require an answer and explain each answer behind an info button, file upload steps that hand a visitor's file to the app's file store and read it back by its name, and branching on an answer, including one named output of a step that recorded several, on comparing a number with an amount, or on comparing two earlier answers or one earlier answer with an amount alone, steps flagged when they name an earlier step without choosing which of its outputs to read, branching on a list of such comparisons that must all hold or of which any one must hold, branching on the hour, weekday or minute a step was completed, Wait steps that hold a run until a number of minutes or a time of day after an earlier step was completed, or until a date, and are named after what they wait for, the Check again button a visitor sees at a waiting step in a flow that keeps nothing, Count steps that count how often an earlier step was answered so a loop can give up after a number of tries, Flow steps that name another flow, open its canvas when their card is clicked with a button back to the flow it was opened from, start a run of it for the same owner when a stored run reaches them, are flagged when the flow or version they name cannot run or leads back to the flow they sit in, let the waiting run name that inner run, move that run on along the output it ends with, leave it waiting when the inner run is stopped by a loop, and fail with an error naming the step when its version was taken out of service or its inner run ended with no output, removing a flow and why it is refused while a waiting run depends on it, step types the host app registers, including ones whose outputs are named by the entries an admin lists in one of their settings, ones that start another flow and work out which flow and version to run from their own settings and are named after that flow, or choose it from the run they are in, the answers a host allows a step in a run and the steps it fills in or passes over, the checks they make on an answer, what a step shows a visitor and how that can depend on the visitor's run, and steps that hold a run until something outside the flow has happened, group steps drawn as a box an admin drags steps into and out of, the For each step that runs the steps its box holds once per item of a list and records each item's values and how many passed and failed, and the settings an admin fills in, including picks whose options come from the app's data, choices drawn as radio cards with a hint under each, and settings kept on one of the app's own records.
4
4
  tools: Read
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -11,7 +11,7 @@ This local explains easy_flow and the words it uses. It makes no changes and giv
11
11
 
12
12
  easy_flow is a Rails engine for guided, branching flows. An admin builds a flow on a canvas by placing steps and connecting them, previews it, and publishes it. A visitor then walks the published flow one step at a time, and each answer decides which step comes next.
13
13
 
14
- Reach for it when an app needs a questionnaire, an intake form, or any decision path that an admin should be able to change without a deploy. The engine ships a start step, an end step, a question step, a checklist step, a multiple select step, a fill in the blank step, a file upload step, five steps that pick a branch from earlier answers, a Count step that counts earlier answers, a Wait step that holds a run until a time, a Flow step that names another flow, and a Play flows step that lets a visitor play several flows in the order they choose. Anything else a flow needs to ask, do, or wait for is a step type the app declares itself.
14
+ Reach for it when an app needs a questionnaire, an intake form, or any decision path that an admin should be able to change without a deploy. The engine ships a start step, an end step, a question step, a checklist step, a multiple select step, a fill in the blank step, a file upload step, five steps that pick a branch from earlier answers, a Count step that counts earlier answers, a Wait step that holds a run until a time, a Flow step that names another flow, a For each step that runs the steps it holds once per item of a list, and a Play flows step that lets a visitor play several flows in the order they choose. Anything else a flow needs to ask, do, or wait for is a step type the app declares itself.
15
15
 
16
16
  ## Interface
17
17
 
@@ -36,7 +36,8 @@ easy_flow declares no commands of its own for this local. Its surface is split b
36
36
  - To let a visitor tick several answers on one step, no code is needed: an admin places a checklist step on the canvas.
37
37
  - To explain an answer to the visitor, no code is needed: an admin fills in that answer's info on a question or checklist step.
38
38
  - To start another flow from inside a flow, no code is needed: an admin places a Flow step on the canvas and picks that flow and its version. The connections leaving the step are labelled with the ways that flow can end, and a stored run moves on along the one named after the output its inner run ended with. Clicking the step's card opens the canvas of the flow it runs, and that canvas has a button back to the flow it was opened from. A Flow step cannot start the flow it sits in, directly or through other flows.
39
- - To add a step type that holds other steps, such as a "for each" step, use **easy_flow-develop**. easy_flow ships no such step type of its own. Once one is offered, an admin places it on the canvas and drags steps into its box, with no further code.
39
+ - To run some steps once for each item of a list an earlier step recorded, no step type is needed: an admin places a For each step on the canvas, names the list as `<step>.<output>`, and drags the steps into its box. A stored run walks the held steps for each item in list order, one item at a time, records each visit under `<step>@item<n>`, and once every item has ended records the For each step's `result`, `items`, `passed` and `failed`, which later steps read as inputs. A flow that keeps nothing refuses to run it. Reading those keys from the app's own code is in **easy_flow-develop**.
40
+ - To add another step type that holds other steps, use **easy_flow-develop**. Once one is offered, an admin places it on the canvas and drags steps into its box, with no further code.
40
41
  - To ask a step again, such as repeating a question until the visitor says they are done, no code is needed: an admin connects a later step back to an earlier one on the canvas.
41
42
  - To end a loop after a number of tries, no code is needed: an admin places a Count step after the step being repeated and a Compare step after the Count step, and connects the Compare step's false connection back to the repeated step.
42
43
  - If the question is only what a word below means, this page is the answer.
@@ -60,7 +61,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
60
61
  - **Output** — a value a step records into the run, with a type and a label. Later steps read outputs, and a setting that points at an earlier step offers that step's known values on the canvas. A step type may also take further outputs from a list setting, one for each entry the admin gives a name, labelled with that name written as a phrase, such as "First reading" for `first_reading`. An entry left without a name adds no output. Those outputs are offered wherever the step's declared outputs are, such as when a Condition, Compare, Compare two values, All of or Any of or Count step picks which output to read.
61
62
  - **Chosen output** — which of an earlier step's outputs a step reads. Every built-in step that names an earlier step and then reads one of its outputs asks the admin to pick that output, as does a step type of the app's own whose output setting points at a step setting. Once the earlier step is named, a step with no output picked is reported as missing that setting, and the same holds for each comparison in an All of or Any of list, for its first step and for its second step. A step that names no earlier step, such as a Compare two values step with its second step left empty, is not asked for that step's output.
62
63
  - **Start** and **End** — the built-in step types that begin and finish a flow. An End step has one setting, its output, and a second, its mark, in a host that sets `marks_ends`.
63
- - **End mark** — success or failure, chosen by an admin on each End step of a host that sets `marks_ends`, so a run that ended says whether it ended well. Publishing such a flow with an End left unmarked is refused. A stored run gives the mark of the End it reached, and gives none when it has not reached one or reached one left unmarked.
64
+ - **End mark** — success or failure, chosen by an admin on each End step of a host that sets `marks_ends`, so a run that ended says whether it ended well. Publishing such a flow with an End left unmarked is refused. A stored run gives the mark of the End it reached, and gives none when it has not reached one or reached one left unmarked. An End card on the canvas and in the run view shows its mark after the word End, such as "End · success", on one line cut short when the mark is too long for the card, and an unmarked End card reads "End".
64
65
  - **Flow output** — the text an admin writes into the output setting of an End step, given as the result of a stored run that has reached that step. A flow may hold several End steps with a different output on each, so the output says which way the flow ended. A run that has not reached an End step, or that ended on one whose output was left blank, gives no output.
65
66
  - **Question** — the built-in step type that asks the visitor: a question text, an optional category, a yes-or-no required setting, and a list of answers, each with a value, a label, a weight, a hint and an info. The visitor picks one answer, and that answer's value is recorded.
66
67
  - **Checklist** — the built-in step type that asks the visitor to tick any number of answers: a question text, a yes-or-no required setting, and a list of answers, each with a value, a label and an info. The list of ticked values is recorded, and a checklist left with nothing ticked records an empty list.
@@ -106,7 +107,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
106
107
  - **Hidden step type codes** — a setting a host may turn on, `hide_step_type_codes`, that hides step type code names on its canvas. The add menu lists each step type by its name alone, and a step's box shows its step type's name in place of the code name, with a step that has no name of its own headed by its step type's name. It is off by default, and with it off the add menu and step boxes show the code names. The settings panel shows a step's id and code name either way.
107
108
  - **Canvas direction** — a setting a host may set, `canvas_direction`, to `:left_to_right` to lay its canvas out left to right in place of top to bottom. Steps sit as compact cards in columns by stage, every connection is drawn as a line labelled with the answer it is taken on, a loop back runs above the steps, a group step's box holds its steps as their own small graph, a flow wider than the canvas scrolls sideways, and a phone-width screen shows one step per row with its connections listed under it. Top to bottom is the default.
108
109
  - **Step list** — a list beside the editing canvas, on screens 640 pixels and wider, of every step type the host offers, with a search field that keeps only the types whose name holds what was typed. A host may set `step_groups`, a hash of headings each with the step types listed under it, in the host's order, and the types it puts in no group are listed above the first heading. Clicking a type adds the step unconnected, as the add menu does, and dragging a type onto a connection inserts the step on that connection. On a phone the list is hidden and the add menu is the way to add steps.
109
- - **Run view** — a read-only view of one flow version that an app draws on its own page with `easy_flow_run_view`, showing each step as a compact card with its type code, name, the version and status line the app supplies, and an edge coloured by the state the app supplies, done, paused, pending or failed. A paused step's edge is thicker, the step the app names as selected is ringed, a card the app gives an address is a link to it, and steps sit in the same graph a left-to-right canvas draws, with every connection drawn as a line, a group step's box holding its steps, and one card per row with its connections listed on a phone. The Start and End steps are drawn as cards with their name alone and never link anywhere, Start shows as done once any step has left pending, and an End shows as done when the app names it as the step the run ended at and as pending otherwise. An app can hide Start and End. It has no editing controls.
110
+ - **Run view** — a read-only view of one flow version that an app draws on its own page with `easy_flow_run_view`, showing each step as a compact card with its type code, name, the version and status line the app supplies, and an edge coloured by the state the app supplies, done, paused, pending or failed. A paused step's edge is thicker, the step the app names as selected is ringed, a card the app gives an address is a link to it, and steps sit in the same graph a left-to-right canvas draws, with every connection drawn as a line, a group step's box holding its steps, and one card per row with its connections listed on a phone. The Start and End steps are drawn as cards with their name alone, an End followed by its mark when it has one, and never link anywhere, Start shows as done once any step has left pending, and an End shows as done when the app names it as the step the run ended at and as pending otherwise. An app can hide Start and End. It has no editing controls.
110
111
  - **Publish note** — a setting a host may set, `publish_note`, whose sentence is shown directly under the Publish button in its flow panel. With none set, the panel shows no note.
111
112
  - **Back link** — a setting a host may set, `back_link`, holding a label and an address, or a callable that takes the flow being shown and returns them, that shows a link with that label and address at the start of the editor's top bar in place of `All flows`. With a callable, each flow's canvas shows the back link worked out for that flow. With none set, the bar shows `All flows`.
112
113
  - **Top bar** — the bar across the top of the canvas and of the definition text page. From left to right it shows the back link, the flow's name, the draft's status, such as `draft from v14 · unsaved 2 changes` or `new draft · unsaved 0 changes` for a flow with no version yet, and a Canvas / Text switch between the canvas and the definition text. On the canvas its buttons are `This flow`, `Try it`, the host's editor buttons, `Save draft` and a `Publish` button naming the version it will create, such as `Publish v15`. `Save draft` creates a version as the panel's Create version does, and both open the flow panel with the result. The status and the Publish label follow each change made on the canvas. The definition text page's bar shows `Try it` and the host's editor buttons, and the page keeps its own Save button. On a screen narrower than 640 pixels the back link, name, status and switch wrap onto more lines, and the buttons are reached from an actions menu in the bar.
@@ -57,7 +57,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
57
57
  - `visitor_authorization_method` — a method on the base controller, called with the flow, returning true when the visitor may run it. With none set, every visitor is refused.
58
58
  - `refusal_method` — a method on the base controller, called with the refusal error when a visitor is refused or a flow is unpublished or withdrawn. With none set, the response is `404 Not Found`.
59
59
  - `owner_method` — a method on the base controller, called with no arguments, returning the record whose flows the current request works with, such as the signed-in account. When set, the admin pages list, create and edit only that record's flows, a visitor runs only that record's flows, and two records may each hold a flow with the same slug. With none set, every flow in the host is shared by everyone who reaches it. Ask the developer whether each host's flows belong to one record or are shared.
60
- - `offers` — the step types this host's admins can add from the canvas palette, as a list of step type names. With none set, every registered step type is offered. The engine's own names are `question`, `checklist`, `multiple_select`, `fill_in_the_blank`, `file_upload`, `condition`, `switch`, `compare`, `compare_two_values`, `all_or_any`, `count`, `wait`, `flow_step` and `play_flows`, `file_upload` being the File upload step, which needs the file store from step 10, `compare_two_values` being the Compare two values step, which compares the outputs of two earlier steps, `all_or_any` being the All of or Any of step, which decides whether all or any of several such comparisons hold, `count` being the Count step, which counts how often an earlier step was answered, `wait` being the Wait step, which holds a run until a time counted from an earlier answer or until a date, `flow_step` being the Flow step, which names one of the same host's flows, and `play_flows` being the Play flows step, which lists several of the same host's flows for a visitor to play in the order they choose. A step type the app declares is named by the id it was declared with, or after its class when it is a step class, so `Steps::Notify` is `notify`. The End step is offered whether it is listed or not, and the Start step is never offered. Ask the developer which step types each host should offer.
60
+ - `offers` — the step types this host's admins can add from the canvas palette, as a list of step type names. With none set, every registered step type is offered. The engine's own names are `question`, `checklist`, `multiple_select`, `fill_in_the_blank`, `file_upload`, `condition`, `switch`, `compare`, `compare_two_values`, `all_or_any`, `count`, `wait`, `flow_step`, `for_each` and `play_flows`, `file_upload` being the File upload step, which needs the file store from step 10, `compare_two_values` being the Compare two values step, which compares the outputs of two earlier steps, `all_or_any` being the All of or Any of step, which decides whether all or any of several such comparisons hold, `count` being the Count step, which counts how often an earlier step was answered, `wait` being the Wait step, which holds a run until a time counted from an earlier answer or until a date, `flow_step` being the Flow step, which names one of the same host's flows, `for_each` being the For each step, which runs the steps its box holds once per item of a list and needs a flow that saves its runs, and `play_flows` being the Play flows step, which lists several of the same host's flows for a visitor to play in the order they choose. A step type the app declares is named by the id it was declared with, or after its class when it is a step class, so `Steps::Notify` is `notify`. The End step is offered whether it is listed or not, and the Start step is never offered. Ask the developer which step types each host should offer.
61
61
  - `always_show_insert_buttons` — set to `true` to show each connection's button for inserting a step on this host's canvas without the pointer over the connection. A connection's label then sits to the right of the line so the button does not cover it. With none set, the button shows only with the pointer over the connection.
62
62
  - `hide_step_type_codes` — set to `true` to hide step type code names on this host's canvas. The add menu then lists each step type by its name alone, and a step's box shows its step type's name in place of the code name. With none set, the add menu and step boxes show the code names. The settings panel shows a step's id and code name either way.
63
63
  - `canvas_direction` — set to `:left_to_right` to lay this host's canvas out left to right. Steps then sit as compact cards in columns by stage, each step to the right of every step that leads into it apart from connections that loop back. Every connection is drawn as a line, labelled with the answer it is taken on, and branches fan out into separate rows and join again at the step they share. A connection that loops back runs above the steps and one that skips columns runs below them, so no line crosses a card. A group step's box holds its steps as their own small graph, entered from the step before it and left for the step after it. A flow wider than the canvas scrolls sideways inside it. An admin inserts or removes a connection with the buttons on its line, and drops a step or a step type onto the line to put it there. On a screen narrower than 640 pixels, each step sits on a row of its own with its connections listed under it. With none set, or with `:top_to_bottom`, the canvas is laid out top to bottom as before.
@@ -164,7 +164,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
164
164
  - A step type of the app's own that starts another flow is treated as a Flow step by every check above: the warnings about a missing flow, a version that cannot run and a flow that leads back, the refusal to remove a flow a waiting run depends on, and the job on `default`. It runs the flow and version its own settings name, or the ones its declaration works out from its other settings, and needs no setting in the initializer beyond being listed in a host's `offers` when that host sets `offers`.
165
165
  - A step type of the app's own whose outputs an admin names on each step offers those names wherever an earlier step's outputs are offered: on a Condition step, on each side of a Compare two values step, and in each comparison of an All of or Any of step. It needs no setting in the initializer beyond being listed in a host's `offers` when that host sets `offers`.
166
166
  - A step type of the app's own that chooses the flow to start from the run it is in is the exception. It never shows the warnings about a missing flow, a version that cannot run or a flow that leads back, so a flow holding it can be published with no flow in its settings. When a run reaches it and it chooses no flow, the engine raises `EasyFlow::InnerFlowError` naming the step and starts no run, and the visitor gets the app's error page. When the run it started ends at an End step with no output, the engine records `ended` as the step's answer and the job on `default` moves the run on from it, rather than failing.
167
- - A step type of the app's own that holds other steps, such as a "for each" step, is drawn on the canvas as a dashed box with a header line at the top and the steps it holds inside. It needs no migration and no setting in the initializer beyond being listed in a host's `offers` when that host sets `offers`. Flows with no such step load and run as before.
167
+ - The built-in For each step and a step type of the app's own that holds other steps are drawn on the canvas as a dashed box with a header line at the top and the steps it holds inside. Neither needs a migration or a setting in the initializer beyond being listed in a host's `offers` when that host sets `offers`. Flows with no such step load and run as before.
168
168
  - After adding a step type that holds other steps to a flow, check that its header line shows the step type's code followed by each filled-in setting, or the type's name and the settings' labels on a host with `hide_step_type_codes` set, and that clicking the header opens the step's settings.
169
169
  - After adding a step type that holds other steps to a flow, check that dragging another step onto its box puts the step inside the box, that dragging it onto the canvas outside the box takes it out, and that both leave the step's connections as they were.
170
170
  - After setting `canvas_direction` to `:left_to_right` on a host, check that its canvas shows the steps in columns with every connection drawn as a labelled line, that a flow wider than the canvas scrolls sideways inside it, and that a phone-width screen shows one step per row with its connections listed under it.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.52.0
4
+ version: 0.54.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -157,6 +157,7 @@ files:
157
157
  - app/models/easy_flow/edge.rb
158
158
  - app/models/easy_flow/edit_history.rb
159
159
  - app/models/easy_flow/flow_step.rb
160
+ - app/models/easy_flow/for_each.rb
160
161
  - app/models/easy_flow/inputs.rb
161
162
  - app/models/easy_flow/layout.rb
162
163
  - app/models/easy_flow/name.rb
@@ -191,6 +192,7 @@ files:
191
192
  - app/models/easy_flow/version.rb
192
193
  - app/models/easy_flow/violation.rb
193
194
  - app/models/easy_flow/violation_sentence.rb
195
+ - app/models/easy_flow/visit_key.rb
194
196
  - app/models/easy_flow/wait.rb
195
197
  - app/models/easy_flow/write_data.rb
196
198
  - app/views/easy_flow/flows/complete.html.erb