easy_flow 0.39.0 → 0.41.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: 6b149b55629914a9ccc0cb3d30f7dc4688f6a24e85131cc4706cd969e4dde44e
4
- data.tar.gz: e0f11051707fe000eb4c755e7c2f8bb3ac18bffb79addb9f5490ae318d633e84
3
+ metadata.gz: b5b6acd893c719746aa2949ee2a996f8dfb27f2288e97821db9bc4c2d13c0a33
4
+ data.tar.gz: aabcf1b5f5da44b5faccaf10a47e58fd48fe3c18bbda405ca54f9a510b3393c0
5
5
  SHA512:
6
- metadata.gz: 4872c78fe7b63df9b8b75e9eab0765001b559ecd72416eb4528b4b317d8665fb318deed214ae74871acd3036e531287f2039d690c97fc9f0ea1b4a438ede1752
7
- data.tar.gz: 99cc4153c0540f2395e0edc3e56b542a2340181a565dd70280f49c703cfe42af33fa11fa41b7e3f514f3b35a361e65382c3039f97fc4cdc165d75883f96451a0
6
+ metadata.gz: 3a8855251cb3d8ff90ca57de888a41c632bf18b82a211ab70984befde8d79181c1de3ad1d9be7da828e221e6c5d106fa11bdbf3e48690ef377f42103aecfe55f
7
+ data.tar.gz: a7262b8eaf1f33db916d79bdf960299b12bf667932c88add357bf45db08f1a3eb52997eb57cf24c50f2de2673042a03e48334185ffb907942b43a0bc1d9782ce
@@ -1 +1 @@
1
- (()=>{var jt=globalThis.ReactDOM;var{createPortal:Ie,createRoot:et,flushSync:Oe,hydrateRoot:Me,preconnect:He,prefetchDNS:je,preinit:Fe,preinitModule:We,preload:Ve,preloadModule:Ue,requestFormReset:Ye,unstable_batchedUpdates:Xe,useFormState:Ge,useFormStatus:qe,version:Je}=jt;var ot=globalThis.React,e=ot,{Children:Ze,Component:Qe,Fragment:Re,PureComponent:to,StrictMode:eo,Suspense:oo,cloneElement:ro,createContext:no,createElement:so,createRef:ao,forwardRef:io,isValidElement:lo,lazy:co,memo:po,startTransition:uo,useCallback:mo,useContext:fo,useDebugValue:go,useDeferredValue:yo,useEffect:A,useId:ho,useImperativeHandle:xo,useLayoutEffect:rt,useMemo:$,useReducer:bo,useRef:G,useState:w,useSyncExternalStore:vo,useTransition:ko}=ot;var nt=new Map,H=new Map,st=(t,o)=>nt.set(t,o),at=()=>{H.forEach(t=>t.unmount()),H.clear()},it=(t,o)=>t.querySelectorAll("[data-react-ui]").forEach(n=>{if(H.has(n))return;let r=nt.get(n.dataset.reactUi),a=o(n);H.set(n,a),a.render(e.createElement(r,JSON.parse(n.dataset.props)))});var lt=(t,o)=>{let n=()=>it(t,o);t.addEventListener("turbo:load",n),t.addEventListener("turbo:frame-load",n),t.addEventListener("turbo:before-cache",at),t.readyState==="loading"?t.addEventListener("DOMContentLoaded",n):n()};var N=(...t)=>t.filter(Boolean).join(" ");var Ft={primary:"ks-button-primary",secondary:"ks-button-secondary",danger:"ks-button-danger"},Wt={sm:"ks-button-sm",md:"ks-button-md",lg:"ks-button-lg"},Vt=({variant:t="primary",size:o="md",className:n,children:r,...a})=>{let l=a.href?"a":"button";return e.createElement(l,{...a,className:N("ks-button",Ft[t],Wt[o],n)},r)},v=Vt;var Ut="border border-amber-500 bg-white text-amber-700 dark:bg-zinc-900 dark:text-amber-400",Yt="border border-gray-300 bg-white text-gray-500 dark:border-zinc-600 dark:bg-zinc-900 dark:text-gray-400",Xt="border border-accent-600 bg-accent-600 text-white",Gt=({name:t,connected:o,armed:n,onArm:r,connecting:a})=>e.createElement("button",{onClick:l=>{a||(l.stopPropagation(),r(l))},title:n?"Now choose a step to connect to":"Connect this branch",className:n?Xt:o?Yt:Ut,style:{padding:"1px 8px",marginRight:4,borderRadius:999,fontSize:11,cursor:"pointer"}},t||"next"),dt=Gt;var qt={width:240,boxSizing:"border-box",borderRadius:8},Jt={padding:"8px 14px",textAlign:"center",fontWeight:600},Kt={fontWeight:600,lineHeight:1.3},Zt=(t,o,n)=>{let r=n?"ring-4 ring-accent-600/15":"shadow-sm";return t||n&&!o?`border-accent-600 ${r}`:o?`border-red-600 ${r}`:"border-gray-300 shadow-sm dark:border-zinc-700"},Qt=(t,o)=>o&&t.label===t.id&&t.type_name||t.label,Rt=(t,o,n)=>n?o===t.type_name?null:t.type_name:t.type,te=({node:t,selected:o,armed:n,connecting:r,onSelect:a,onOpen:l,onArm:p,onDragEnd:i,onDragStart:d,hideStepTypeCodes:y})=>{let h=t.begins_here||t.ends_here,c=t.begins_here,f=t.ends_here?[]:t.ports,g=r&&!c,u=Qt(t,y),k=Rt(t,u,y);return e.createElement("div",{ref:t.ref,"data-step":t.id,draggable:!c,onDragStart:b=>{b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("text/plain",t.id),d()},onDragEnd:i,onClick:t.opens&&!r?()=>l(t.opens):a,className:`bg-white border-2 dark:bg-zinc-900 ${Zt(g,t.violations.length>0,o)}`,style:{...qt,padding:h?0:"12px 14px",cursor:c?"default":r?"crosshair":"grab"}},h&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:Jt},u),!h&&e.createElement("div",{style:Kt},u),!h&&k&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginTop:2}},k),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(v,{variant:"secondary",size:"sm",className:"mt-2",onClick:b=>{b.stopPropagation(),a()}},"Settings"),t.violations.map(b=>e.createElement("div",{key:b.problem+b.detail,className:"text-red-600 dark:text-red-400",style:{fontSize:11,padding:"0 14px 6px"}},b.sentence)),f.length>0&&e.createElement("div",{style:{padding:t.begins_here?"0 14px 8px":"10px 0 0"}},f.map(b=>e.createElement(dt,{key:b,name:b,connected:t.connected.includes(b),connecting:r,armed:n===b,onArm:C=>p(b,C)}))))},q=te;var J=(t,o)=>t.includes(o)?t.filter(n=>n!==o):[...t,o],ct=(t,o)=>({...o?.choices||{},...t?.choices||{}});var ee=({as:t="input",disabled:o,className:n,...r})=>e.createElement(t,{...r,disabled:o,className:N("ks-input",o&&"ks-input-disabled",n)}),E=ee;var oe=t=>e.createElement(E,{...t,as:"select"}),pt=oe;var re=({className:t,...o})=>e.createElement("input",{type:"checkbox",...o,className:N("ks-checkbox",t)}),j=re;var ut=t=>(t||[]).map(o=>typeof o=="object"?o:{value:o,label:o}),ne=({type:t,value:o,choices:n,onChange:r,onSettle:a,onPick:l,pictureUrl:p})=>{if(t==="picture")return e.createElement("div",{className:"mb-3"},o&&p&&e.createElement("img",{src:p,alt:"The step's picture",style:{maxWidth:"100%"}}),o&&e.createElement("button",{type:"button","data-remove-picture":!0,className:"ks-button ks-button-secondary ks-button-sm",onClick:()=>a("")},"Remove picture"),e.createElement("input",{type:"file",accept:"image/*",onChange:i=>i.target.files[0]&&l(i.target.files[0])}));if(t==="boolean")return e.createElement(j,{checked:!!o,onChange:i=>a(i.target.checked)});if(t==="select"||t==="previous_step"||t==="from_step"||t==="flow")return e.createElement(pt,{className:"mb-3",value:o??"",onChange:i=>a(i.target.value)},e.createElement("option",{value:""}),ut(n).map(i=>e.createElement("option",{key:i.value,value:i.value},i.label)));if(t==="multi_select"){let i=Array.isArray(o)?o:[],d=y=>a(J(i,y));return e.createElement("div",{style:{display:"flex",flexWrap:"wrap",gap:8}},(n||[]).map(y=>e.createElement("label",{key:y,style:{display:"inline-flex",alignItems:"center",gap:4}},e.createElement(j,{checked:i.includes(y),onChange:()=>d(y)}),e.createElement("span",null,y))))}if(t==="flows"){let i=Array.isArray(o)?o:[];return e.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4},className:"mb-3"},ut(n).map(d=>e.createElement("label",{key:d.value,style:{display:"inline-flex",alignItems:"center",gap:4}},e.createElement(j,{checked:i.includes(d.value),onChange:()=>a(J(i,d.value))}),e.createElement("span",null,d.label))))}return t==="integer"||t==="float"?e.createElement(E,{className:"mb-3",type:"number",step:t==="integer"?"1":"any",value:o??"",onChange:i=>r(i.target.value),onBlur:i=>a(i.target.value)}):e.createElement(E,{className:"mb-3",type:"text",value:o??"",onChange:i=>r(i.target.value),onBlur:i=>a(i.target.value)})},F=ne;var mt=(t,o,n,r)=>t.map((a,l)=>l===o?{...a,[n]:r}:a);var se=({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),W=se;var ae=(t,o,n,r)=>{let a=(t||{})[n],l=(o||{})[n];return l?(a||{})[r[l]]:a},ie=({holds:t,labels:o,explanations:n,rows:r,choices:a,outputsOf:l,onChange:p,onSettle:i})=>{let d=Array.isArray(r)?r:[],y=(h,c,f,g)=>{let u=mt(d,h,c,f);g?i(u):p(u)};return e.createElement("div",{style:{marginBottom:12}},d.map((h,c)=>e.createElement("div",{key:c,className:"rounded-md border border-gray-200 dark:border-zinc-700",style:{padding:"8px 8px 2px",marginBottom:6}},Object.entries(t).map(([f,g])=>e.createElement("label",{key:f,style:{display:"block"}},e.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{display:"block",marginBottom:2,fontSize:11}},(o||{})[f]||f),e.createElement(F,{type:g,value:h[f],choices:ae(a,l,f,h),onChange:u=>y(c,f,u,!1),onSettle:u=>y(c,f,u,!0)}),(n||{})[f]&&e.createElement(W,{text:n[f]}))),e.createElement(v,{variant:"secondary",size:"sm",className:"mb-1.5",onClick:()=>i(d.filter((f,g)=>g!==c))},"Remove"))),e.createElement(v,{variant:"secondary",size:"sm",className:"w-full",onClick:()=>i([...d,{}])},"Add"))},ft=ie;var le=({as:t="div",className:o,children:n,...r})=>e.createElement(t,{...r,className:N("ks-panel",o)},n),I=le;var V=(t,o)=>({className:n,children:r,...a})=>e.createElement(t,{...a,className:N(o,n)},r),M=V("label","ks-label"),gr=V("p","ks-hint"),yr=V("p","ks-error"),hr=V("span","ks-required");var de={width:280,padding:20,overflowY:"auto"},ce=({node:t,fields:o,holds:n,labels:r,explanations:a,recordLabels:l,recordExplanations:p,recordChoices:i,recordOutputsOf:d,choices:y,onSave:h,onDelete:c,onClose:f,onPickPicture:g,refusal:u})=>{let[k,b]=w(t.config),[C,D]=w(t.picture_url);A(()=>D(t.picture_url),[t.id,t.picture_url]),A(()=>b(t.config),[t.id,t.config]);let T=x=>{b(x),JSON.stringify(x)!==JSON.stringify(t.config)&&h(x)};return e.createElement(I,{as:"aside",style:de,"data-inspector":!0},e.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8}},e.createElement("h2",{style:{fontWeight:600,marginBottom:2}},t.label),e.createElement("button",{title:"Close",onClick:f,className:"text-gray-500 dark:text-gray-400",style:{border:"none",background:"none",cursor:"pointer",fontSize:18,lineHeight:1}},"\xD7")),e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginBottom:16}},t.id," \xB7 ",t.type),u&&e.createElement("p",{className:"text-red-800 dark:text-red-400",style:{fontWeight:600,marginBottom:12},"data-refusal":!0},u),Object.entries(o).map(([x,B])=>e.createElement(M,{key:x},e.createElement("span",{style:{display:"block",marginBottom:3}},r[x]||x),B==="list"?e.createElement(ft,{holds:n[x]||{},labels:l[x]||{},explanations:(p||{})[x],rows:k[x],choices:{...(i||{})[x],...(t.record_choices||{})[x]},outputsOf:(d||{})[x],onChange:S=>b({...k,[x]:S}),onSettle:S=>T({...k,[x]:S})}):e.createElement(F,{type:B,value:k[x],choices:y[x],pictureUrl:C,onChange:S=>b({...k,[x]:S}),onSettle:S=>T({...k,[x]:S}),onPick:async S=>{let O=await g(S);O&&(D(O.url),T({...k,[x]:O.reference}))}}),(a||{})[x]&&e.createElement(W,{text:a[x]}))),e.createElement(v,{variant:"danger",size:"sm",className:"w-full",onClick:c},"Delete step"))},gt=ce;var pe={width:240,boxSizing:"border-box",padding:"10px 14px",borderRadius:8,textAlign:"center",fontSize:12,cursor:"pointer"},ue="border-2 border-dashed border-amber-500 bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300",me="border-2 border-dashed border-accent-600 bg-accent-50 text-accent-800 dark:bg-accent-950 dark:text-accent-200",fe=({node:t,dragging:o,onFill:n,onDrop:r})=>e.createElement("div",{ref:t.ref,"data-placeholder":t.id,title:`Choose the step \u201C${t.label}\u201D should lead to`,onClick:n,onDragOver:a=>{o&&(a.preventDefault(),a.dataTransfer.dropEffect="move")},onDrop:a=>{a.preventDefault(),r()},className:o?me:ue,style:pe},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")),yt=fe;var ge=({entries:t,at:o,onPick:n,onConnect:r,onDismiss:a,hideStepTypeCodes:l})=>e.createElement(I,{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(v,{key:p.type,variant:"secondary",size:"sm",className:"w-full mb-1.5 flex-col",onClick:()=>n(p)},p.label,!l&&e.createElement("span",{className:"opacity-75",style:{display:"block",fontSize:11}},p.type))),r&&e.createElement(v,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:r},"Connect to a step already here"),e.createElement(v,{variant:"secondary",size:"sm",className:"w-full",onClick:a},"Cancel")),ht=ge;var ye={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},xt=({label:t,title:o,idle:n,enabled:r,onUse:a})=>e.createElement(v,{variant:"secondary",size:"sm",title:r?o:n,disabled:!r,onClick:a,style:{opacity:r?1:.4,cursor:r?"pointer":"default"}},t),he=({undoable:t,redoable:o,onAdd:n,onUndo:r,onRedo:a})=>e.createElement("div",{style:{position:"absolute",top:16,left:16,zIndex:5,display:"flex",gap:8}},e.createElement(v,{variant:"secondary",className:"rounded-full",style:ye,title:"Add a step",onClick:n},"+"),e.createElement(xt,{label:"\u21B6 Undo",title:"Undo the last change",idle:"Nothing to undo",enabled:t,onUse:r}),e.createElement(xt,{label:"\u21B7 Redo",title:"Redo the change you undid",idle:"Nothing to redo",enabled:o,onUse:a})),bt=he;var xe=({type:t="info",title:o,message:n,onDismiss:r,className:a})=>e.createElement("div",{className:N("ks-alert",`ks-alert-${t}`,a),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"},n)),r&&e.createElement("button",{type:"button",className:"ks-alert-dismiss","aria-label":"Dismiss",onClick:r},"\xD7"))),vt=xe;var kt=t=>{let o=t.map(n=>`\u201C${n.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 wt=({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 be={width:280,padding:20,overflowY:"auto"},K={fontWeight:600,marginBottom:6,marginTop:14},U={fontSize:12,marginBottom:4,lineHeight:1.4},Ct={display:"block",marginBottom:3},Nt=(t,o,n)=>r=>{r.target.value!==(t[o]??"")&&n({[o]:r.target.value})},ve=({flow:t,changes:o,problems:n,refusal:r,notice:a,publishNote:l,warning:p,onCreate:i,onPublish:d,onAccept:y,onDecline:h,onSaveDetails:c,onClose:f})=>e.createElement(I,{as:"aside",style:be,"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:f,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},wt(t)),p?e.createElement("div",{style:{marginTop:14},"data-unconnected-warning":!0},e.createElement(vt,{type:"warning",className:"mb-1.5",message:kt(p.steps)}),e.createElement(v,{size:"sm",className:"w-full mb-1.5",onClick:y,"data-accept-removal":!0},p.path==="/publish"?"Remove and publish":"Remove and create version"),e.createElement(v,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:h,"data-decline-removal":!0},"Cancel")):e.createElement("div",{style:{marginTop:14}},e.createElement(v,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:i,"data-create-version":!0},"Create version"),e.createElement(v,{size:"sm",className:"w-full mb-1.5",onClick:d,"data-publish":!0},"Publish"),l&&e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12,lineHeight:1.4},"data-publish-note":!0},l)),e.createElement("h2",{style:K},"Problems"),r&&e.createElement("p",{className:"text-red-800 dark:text-red-400",style:{...U,fontWeight:600},"data-refusal":!0},r),a&&!r&&e.createElement("p",{className:"text-emerald-800 dark:text-emerald-400",style:{...U,fontWeight:600},"data-notice":!0},a),n.length===0&&!r?e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12}},"Nothing wrong with this flow."):n.map(g=>e.createElement("p",{key:`${g.node}-${g.problem}`,className:"text-amber-700 dark:text-amber-400",style:U,"data-problem":!0},"\u26A0 ",g.sentence)),e.createElement("h2",{style:K},"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((g,u)=>e.createElement("p",{key:u,style:U,"data-change":!0},g)),e.createElement("h2",{style:K},"Details"),e.createElement(M,null,e.createElement("span",{style:Ct},"Title"),e.createElement(E,{className:"mb-3",defaultValue:t.title??"",onBlur:Nt(t,"title",c),"data-flow-title":!0})),e.createElement(M,null,e.createElement("span",{style:Ct},"Start label"),e.createElement(E,{className:"mb-3",defaultValue:t.start_label??"",onBlur:Nt(t,"start_label",c),"data-flow-start-label":!0})),e.createElement("div",{style:{marginTop:16}},e.createElement(v,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.definition_url,"data-definition":!0},"Definition"),e.createElement(v,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.details_url,"data-details":!0},"Edit details"))),St=ve;var zt={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},Bt=t=>({opacity:t?1:0,transition:"opacity .12s"}),ke=({link:t,onInsert:o,onRemove:n,onDrop:r,dragging:a,alwaysShowInsertButtons:l})=>{let[p,i]=w(!1),d=p||a;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:()=>i(!0),onMouseLeave:()=>i(!1),onDragEnter:()=>i(!0),onDragLeave:()=>i(!1),onDragOver:y=>{y.preventDefault(),y.dataTransfer.dropEffect="move"},onDrop:y=>{y.preventDefault(),i(!1),r()}},e.createElement("div",{style:{display:"flex",gap:4,justifyContent:"center",alignItems:"center",height:"100%"}},e.createElement(v,{variant:"secondary",title:a?"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":!!(a&&p),style:{...zt,...Bt(d||l)}},"+"),!a&&e.createElement(v,{variant:"danger",title:"Remove this connection",onClick:n,className:"rounded-full",style:{...zt,...Bt(d)}},"\xD7")))},_t=ke;var we=({links:t,extent:o,dragging:n,onInsert:r,onRemove:a,onDrop:l,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(i=>e.createElement("path",{key:i.id,"data-link":i.id,className:"stroke-gray-400 dark:stroke-zinc-500",fill:"none",strokeWidth:"1.5",markerEnd:"url(#easy_flow-arrow)",d:i.path}))),t.filter(i=>i.label).map(i=>e.createElement("div",{key:`${i.id}-label`,"data-link-label":i.id,className:"bg-surface-50 text-gray-500 dark:bg-surface-950 dark:text-gray-400",style:{position:"absolute",left:i.midX+(p?2:-10),top:i.midY-18,zIndex:3,fontSize:11,padding:"0 3px"}},i.label)),t.filter(i=>!i.placeholder).map(i=>e.createElement(_t,{key:i.id,link:i,dragging:!!n,alwaysShowInsertButtons:p,onInsert:()=>r(i),onRemove:()=>a(i),onDrop:()=>l(i)}))),Tt=we;var Et="Your change was not saved because the server could not be reached.",Pt=({base:t,token:o,fetch:n,onFlow:r,onError:a,onNotice:l,onWarning:p=()=>{}})=>async(i,d,y)=>{let h=await n(t+i,{method:d,headers:{"Content-Type":"application/json","X-CSRF-Token":o},body:y&&JSON.stringify(y)}).catch(()=>null);if(!h)return l(null),a(Et);let c=await h.json().catch(()=>({}));if(c.unconnected)return l(null),a(null),p({path:i,steps:c.unconnected}),r(await(await n(t+".json",{headers:{Accept:"application/json"}})).json());if(p(null),!h.ok)return l(null),a(c.error||"That change was refused");a(null),l(c.notice||null),r(await(await n(t+".json",{headers:{Accept:"application/json"}})).json())},At=({base:t,token:o,fetch:n,onError:r})=>async a=>{let l=new FormData;l.append("picture",a);let p=await n(t+"/pictures",{method:"POST",headers:{"X-CSRF-Token":o},body:l}).catch(()=>null);if(!p)return r(Et),null;let i=await p.json().catch(()=>({}));return p.ok?(r(null),i):(r(i.error||"That picture was refused"),null)};var Ce=(t,o,n)=>{let[r,a]=w(n),[l,p]=w(null),[i,d]=w(null),[y,h]=w(null),c=$(()=>Pt({base:t,token:o,fetch:(...g)=>window.fetch(...g),onFlow:a,onError:p,onNotice:d,onWarning:h}),[t,o]),f=$(()=>At({base:t,token:o,fetch:(...g)=>window.fetch(...g),onError:p}),[t,o]);return{flow:r,error:l,notice:i,warning:y,setWarning:h,send:c,pickPicture:f}},Dt=Ce;var Y=(t,o,n,r)=>{let a=t.left-n.left+r.scrollLeft,l=t.top-n.top+r.scrollTop;return o==="left"?{x:a,y:l+t.height/2}:o==="right"?{x:a+t.width,y:l+t.height/2}:o==="top"?{x:a+t.width/2,y:l}:{x:a+t.width/2,y:l+t.height}},Ne=(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},Se=(t,o,n,r,a)=>{let l={straight:`M ${o.x} ${o.y} L ${n.x} ${n.y}`,turn:`M ${o.x} ${o.y} H ${n.x} V ${n.y}`,lane:`M ${o.x} ${o.y} V ${r} H ${n.x} V ${n.y}`,detour:`M ${o.x} ${o.y} H ${a} V ${n.y} H ${n.x}`}[t.route];return{...t,path:l,midX:t.route==="detour"?a:(o.x+n.x)/2,midY:t.route==="lane"?r:(o.y+n.y)/2}},ze=(t,o,n,r)=>{let[a,l]=w([]),[p,i]=w({width:"100%",height:"100%"});return rt(()=>{let d=()=>{let h=o.current?.getBoundingClientRect();h&&(i({width:o.current.scrollWidth,height:o.current.scrollHeight}),l(t.edges.flatMap(c=>{let f=n.current[c.source]?.getBoundingClientRect(),g=n.current[c.target]?.getBoundingClientRect();if(!f||!g)return[];let u=Y(f,c.leaves,h,o.current),k=Ne(Y(g,c.enters,h,o.current),c.enters),b=(Y(f,"bottom",h,o.current).y+Y(g,"top",h,o.current).y)/2,C=c.leaves==="left"?Math.min(u.x,k.x)-28:Math.max(u.x,k.x)+28;return[Se(c,u,k,b,C)]})))};d(),window.addEventListener("resize",d);let y=new ResizeObserver(d);return o.current&&y.observe(o.current),()=>{window.removeEventListener("resize",d),y.disconnect()}},r),{links:a,extent:p}},$t=ze;var Lt=(t,o)=>{let n=new Set(o),r=t,a=2;for(;n.has(r);)r=`${t}_${a++}`;return r};var Te={display:"flex",height:"100%",minHeight:0,fontSize:13},Ee={flex:1,overflow:"auto",position:"relative"},Pe={position:"absolute",top:56,left:16,zIndex:5,width:264,padding:12,borderRadius:8},Ae={display:"grid",rowGap:64,columnGap:0,padding:40,justifyContent:"center",position:"relative"},De={position:"sticky",zIndex:8,top:8,margin:"8px auto 0",width:"fit-content",padding:"6px 12px",borderRadius:6,fontSize:12},$e=({port:t,onCancel:o})=>e.createElement("div",{className:"bg-accent-100 text-accent-800 dark:bg-accent-900 dark:text-accent-100",style:De},"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")),Le=({base:t,token:o,initial:n})=>{let{flow:r,error:a,notice:l,warning:p,setWarning:i,send:d,pickPicture:y}=Dt(t,o,n),[h,c]=w(null),[f,g]=w(null),[u,k]=w(null),[b,C]=w(null),[D,T]=w(!1),x=G({}),B=G(null);A(()=>{let s=()=>{c(null),T(!0)};return document.addEventListener("easy_flow:open-flow",s),()=>document.removeEventListener("easy_flow:open-flow",s)},[]),A(()=>{if(!D){i(null);return}let s=m=>{m.target.isConnected&&!m.target.closest("[data-builder-panel], [data-open-panel]")&&T(!1)};return document.addEventListener("click",s),()=>document.removeEventListener("click",s)},[D]),A(()=>{document.dispatchEvent(new CustomEvent("easy_flow:flow-named",{detail:r.flow?.title||r.flow?.slug}))},[r.flow?.title,r.flow?.slug]);let S=$(()=>Object.fromEntries(r.nodes.map(s=>[s.id,s])),[r.nodes]),{links:O,extent:Ot}=$t(r,B,x,[r,h,S]),Z=$(()=>{let s={};return r.violations.forEach(m=>{var z;return(s[z=m.node]||(s[z]=[])).push(m)}),s},[r.violations]),X=r.nodes.filter(s=>!s.loose),Q=r.nodes.filter(s=>s.loose),Mt=Math.max(0,...X.map(s=>s.row))+1,Ht=Math.max(0,...X.map(s=>s.column))+1,R=s=>{if(!u)return;let[m,z]=u;k(null),m!==s&&d("/edges","POST",{from:m,to:s,on:z||null})},P=r.nodes.find(s=>s.id===h),_=[...r.palette,...r.unoffered||[]].find(s=>s.type===P?.type);return e.createElement("div",{className:"text-gray-900 dark:text-gray-100",style:Te,onMouseUp:()=>C(null),onKeyDown:s=>{s.key==="Escape"&&(c(null),k(null),g(null))},tabIndex:-1},e.createElement("div",{ref:B,className:"bg-surface-50 dark:bg-surface-950",style:Ee,onClick:s=>{s.target===B.current&&(c(null),k(null),T(!1))}},u&&e.createElement($e,{port:u[1],onCancel:()=>k(null)}),e.createElement(bt,{undoable:r.undoable,redoable:r.redoable,onAdd:()=>g({at:{x:16,y:52}}),onUndo:()=>{c(null),d("/undo","POST")},onRedo:()=>{c(null),d("/redo","POST")}}),e.createElement(Tt,{links:O,extent:Ot,dragging:b,alwaysShowInsertButtons:r.always_show_insert_buttons,onInsert:s=>g({from:s.source,to:s.target,at:{x:s.midX+30,y:s.midY}}),onRemove:s=>{c(null),d("/edges","DELETE",{from:s.source,to:s.target})},onDrop:s=>{let m=b;C(null),d("/steps/"+m+"/move","PATCH",{from:s.source,to:s.target})}}),Q.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:Pe},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"),Q.map(s=>e.createElement("div",{key:s.id,style:{marginBottom:8}},e.createElement(q,{node:{...s,ref:m=>{x.current[s.id]=m},violations:Z[s.id]||[],connected:[]},selected:h===s.id,armed:u&&u[0]===s.id?u[1]:null,connecting:!!u,onSelect:()=>u?R(s.id):c(s.id),onOpen:m=>window.location.assign(m),onArm:(m,z)=>{z.stopPropagation(),k([s.id,m])},onDragStart:()=>C(s.id),onDragEnd:()=>C(null),hideStepTypeCodes:r.hide_step_type_codes})))),e.createElement("div",{style:{...Ae,gridTemplateColumns:`repeat(${Ht+1}, ${280/2}px)`,gridTemplateRows:`repeat(${Mt}, auto)`}},X.map(s=>e.createElement("div",{key:s.id,style:{gridRow:s.row+1,gridColumn:`${s.column+1} / span 2`,zIndex:2}},s.placeholder&&e.createElement(yt,{node:{...s,ref:m=>{x.current[s.id]=m}},dragging:!!b,onFill:()=>g({from:s.from,on:s.on,at:{x:16,y:52}}),onDrop:()=>{let m=b;C(null),m&&d("/edges","POST",{from:s.from,to:m,on:s.on})}}),!s.placeholder&&e.createElement(q,{node:{...s,ref:m=>{x.current[s.id]=m},violations:Z[s.id]||[],connected:r.edges.filter(m=>m.source===s.id).map(m=>m.label||null)},selected:s.id===h,armed:u&&u[0]===s.id?u[1]:null,connecting:!!u&&u[0]!==s.id,onSelect:()=>u?R(s.id):c(s.id),onOpen:m=>window.location.assign(m),onArm:(m,z)=>{let tt=B.current.getBoundingClientRect();g({from:s.id,on:m,at:{x:z.clientX-tt.left+B.current.scrollLeft+8,y:z.clientY-tt.top+B.current.scrollTop+8}})},onDragEnd:()=>C(null),onDragStart:()=>C(s.id),hideStepTypeCodes:r.hide_step_type_codes})))),f&&e.createElement(ht,{entries:r.palette,at:f.at,onDismiss:()=>g(null),hideStepTypeCodes:r.hide_step_type_codes,onConnect:f.on!==void 0?()=>{k([f.from,f.on]),g(null)}:null,onPick:s=>{let m=f;g(null),d("/steps","POST",{id:Lt(s.type,r.nodes.map(z=>z.id)),type:s.type,from:m.from,to:m.to,on:m.on})}})),D&&!P&&e.createElement(St,{flow:r.flow||{},changes:r.changes||[],problems:r.violations,refusal:a,notice:l,publishNote:r.publish_note,warning:p,onClose:()=>T(!1),onCreate:()=>d("/versions","POST"),onPublish:()=>d("/publish","POST"),onAccept:()=>d(p.path,"POST",{remove_unconnected:p.steps.map(s=>s.id)}),onDecline:()=>i(null),onSaveDetails:s=>d("/details","PATCH",{flow:s})}),P&&e.createElement(gt,{node:P,fields:_?.fields||{},holds:_?.records||{},labels:_?.labels||{},explanations:_?.explanations||{},recordLabels:_?.record_labels||{},recordExplanations:_?.record_explanations||{},recordChoices:_?.record_choices||{},recordOutputsOf:_?.record_outputs_of||{},choices:ct(P,_),onClose:()=>c(null),onSave:s=>d(`/steps/${P.id}`,"PATCH",{config:s}),onPickPicture:y,refusal:a,onDelete:()=>{c(null),d(`/steps/${P.id}`,"DELETE")}}))},It=Le;st("easy_flow/flow-editor",It);document.addEventListener("easy_flow:flow-named",t=>{let o=document.querySelector("[data-flow-heading]");o&&(o.textContent=t.detail)});lt(document,et);})();
1
+ (()=>{var Rt=globalThis.ReactDOM;var{createPortal:oo,createRoot:rt,flushSync:ro,hydrateRoot:no,preconnect:so,prefetchDNS:ao,preinit:io,preinitModule:lo,preload:co,preloadModule:po,requestFormReset:uo,unstable_batchedUpdates:mo,useFormState:fo,useFormStatus:go,version:ho}=Rt;var nt=globalThis.React,e=nt,{Children:xo,Component:bo,Fragment:vo,PureComponent:ko,StrictMode:wo,Suspense:Co,cloneElement:No,createContext:So,createElement:Bo,createRef:zo,forwardRef:_o,isValidElement:Eo,lazy:To,memo:Do,startTransition:Ao,useCallback:Oo,useContext:Po,useDebugValue:$o,useDeferredValue:Mo,useEffect:P,useId:Lo,useImperativeHandle:Io,useLayoutEffect:st,useMemo:$,useReducer:Ho,useRef:J,useState:w,useSyncExternalStore:jo,useTransition:Wo}=nt;var at=new Map,j=new Map,it=(t,o)=>at.set(t,o),lt=()=>{j.forEach(t=>t.unmount()),j.clear()},dt=(t,o)=>t.querySelectorAll("[data-react-ui]").forEach(n=>{if(j.has(n))return;let r=at.get(n.dataset.reactUi),a=o(n);j.set(n,a),a.render(e.createElement(r,JSON.parse(n.dataset.props)))});var ct=(t,o)=>{let n=()=>dt(t,o);t.addEventListener("turbo:load",n),t.addEventListener("turbo:frame-load",n),t.addEventListener("turbo:before-cache",lt),t.readyState==="loading"?t.addEventListener("DOMContentLoaded",n):n()};var _=(...t)=>t.filter(Boolean).join(" ");var te={primary:"ks-button-primary",secondary:"ks-button-secondary",danger:"ks-button-danger"},ee={sm:"ks-button-sm",md:"ks-button-md",lg:"ks-button-lg"},oe=({variant:t="primary",size:o="md",className:n,children:r,...a})=>{let d=a.href?"a":"button";return e.createElement(d,{...a,className:_("ks-button",te[t],ee[o],n)},r)},k=oe;var re="border border-amber-500 bg-white text-amber-700 dark:bg-zinc-900 dark:text-amber-400",ne="border border-gray-300 bg-white text-gray-500 dark:border-zinc-600 dark:bg-zinc-900 dark:text-gray-400",se="border border-accent-600 bg-accent-600 text-white",ae=({name:t,connected:o,armed:n,onArm:r,connecting:a})=>e.createElement("button",{onClick:d=>{a||(d.stopPropagation(),r(d))},title:n?"Now choose a step to connect to":"Connect this branch",className:n?se:o?ne:re,style:{padding:"1px 8px",marginRight:4,borderRadius:999,fontSize:11,cursor:"pointer"}},t||"next"),pt=ae;var ie={width:240,boxSizing:"border-box",borderRadius:8},le={padding:"8px 14px",textAlign:"center",fontWeight:600},de={fontWeight:600,lineHeight:1.3},ce=(t,o,n)=>{let r=n?"ring-4 ring-accent-600/15":"shadow-sm";return t||n&&!o?`border-accent-600 ${r}`:o?`border-red-600 ${r}`:"border-gray-300 shadow-sm dark:border-zinc-700"},pe=(t,o)=>o&&t.label===t.id&&t.type_name||t.label,ue=(t,o,n)=>n?o===t.type_name?null:t.type_name:t.type,me=({node:t,selected:o,armed:n,connecting:r,onSelect:a,onOpen:d,onArm:u,onDragEnd:i,onDragStart:p,hideStepTypeCodes:x})=>{let b=t.begins_here||t.ends_here,m=t.begins_here,g=t.ends_here?[]:t.ports,h=r&&!m,l=pe(t,x),v=ue(t,l,x);return e.createElement("div",{ref:t.ref,"data-step":t.id,draggable:!m,onDragStart:f=>{f.dataTransfer.effectAllowed="move",f.dataTransfer.setData("text/plain",t.id),p()},onDragEnd:i,onClick:t.opens&&!r?()=>d(t.opens):a,className:`bg-white border-2 dark:bg-zinc-900 ${ce(h,t.violations.length>0,o)}`,style:{...ie,padding:b?0:"12px 14px",cursor:m?"default":r?"crosshair":"grab"}},b&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:le},l),!b&&e.createElement("div",{style:de},l),!b&&v&&e.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginTop:2}},v),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(k,{variant:"secondary",size:"sm",className:"mt-2",onClick:f=>{f.stopPropagation(),a()}},"Settings"),t.violations.map(f=>e.createElement("div",{key:f.problem+f.detail,className:"text-red-600 dark:text-red-400",style:{fontSize:11,padding:"0 14px 6px"}},f.sentence)),g.length>0&&e.createElement("div",{style:{padding:t.begins_here?"0 14px 8px":"10px 0 0"}},g.map(f=>e.createElement(pt,{key:f,name:f,connected:t.connected.includes(f),connecting:r,armed:n===f,onArm:C=>u(f,C)}))))},K=me;var fe=({node:t,header:o,onSelect:n})=>e.createElement("div",{ref:t.ref,"data-group-header":t.id,onClick:n,className:"font-mono text-gray-500 dark:text-gray-400",style:{position:"relative",zIndex:2,width:240,fontSize:11,whiteSpace:"nowrap",cursor:"pointer"}},o),ut=fe;var ge=({id:t,bounds:o,onDrop:n})=>e.createElement("div",{"data-group-box":t,onDragOver:r=>{r.preventDefault(),r.dataTransfer.dropEffect="move"},onDrop:r=>{r.preventDefault(),n()},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}}),mt=ge;var he=t=>t!=null&&t!==""&&typeof t!="object",ye=["integer","float"],xe=(t,o,n)=>n&&o.labels?.[t]||t,ft=(t,o,n)=>{let r=Object.keys(o?.fields||{}).filter(a=>he(t.config[a])).map(a=>`${xe(a,o,n)}${ye.includes(o.fields[a])?"":":"} ${t.config[a]}`);return[n&&t.type_name||t.type,...r].join(" \xB7 ")};var gt=(t,o,n)=>{let r=Math.min(...t.map(i=>i.left))-o.left+n.scrollLeft-12,a=Math.min(...t.map(i=>i.top))-o.top+n.scrollTop-10,d=Math.max(...t.map(i=>i.left+i.width))-o.left+n.scrollLeft+12,u=Math.max(...t.map(i=>i.top+i.height))-o.top+n.scrollTop+10;return{left:r,top:a,width:d-r,height:u-a}},be=({left:t,top:o,width:n,height:r},a)=>a.x>=t&&a.x<=t+n&&a.y>=o&&a.y<=o+r,ht=(t,o)=>t.find(n=>be(n.bounds,o))?.id||null,yt=(t,o)=>t.filter(n=>!o.some(r=>r.id===n.source&&r.holds?.includes(n.target))),xt=(t,o)=>o.some(n=>n.holds?.includes(t.id)&&!n.loose&&n.row===t.row-1);var Z=(t,o)=>t.includes(o)?t.filter(n=>n!==o):[...t,o],bt=(t,o)=>({...o?.choices||{},...t?.choices||{}});var ve=({as:t="input",disabled:o,className:n,...r})=>e.createElement(t,{...r,disabled:o,className:_("ks-input",o&&"ks-input-disabled",n)}),A=ve;var ke=t=>e.createElement(A,{...t,as:"select"}),vt=ke;var we=({className:t,...o})=>e.createElement("input",{type:"checkbox",...o,className:_("ks-checkbox",t)}),W=we;var kt=t=>(t||[]).map(o=>typeof o=="object"?o:{value:o,label:o}),Ce=({type:t,value:o,choices:n,onChange:r,onSettle:a,onPick:d,pictureUrl:u})=>{if(t==="picture")return e.createElement("div",{className:"mb-3"},o&&u&&e.createElement("img",{src:u,alt:"The step's picture",style:{maxWidth:"100%"}}),o&&e.createElement("button",{type:"button","data-remove-picture":!0,className:"ks-button ks-button-secondary ks-button-sm",onClick:()=>a("")},"Remove picture"),e.createElement("input",{type:"file",accept:"image/*",onChange:i=>i.target.files[0]&&d(i.target.files[0])}));if(t==="boolean")return e.createElement(W,{checked:!!o,onChange:i=>a(i.target.checked)});if(t==="select"||t==="previous_step"||t==="from_step"||t==="flow")return e.createElement(vt,{className:"mb-3",value:o??"",onChange:i=>a(i.target.value)},e.createElement("option",{value:""}),kt(n).map(i=>e.createElement("option",{key:i.value,value:i.value},i.label)));if(t==="multi_select"){let i=Array.isArray(o)?o:[],p=x=>a(Z(i,x));return e.createElement("div",{style:{display:"flex",flexWrap:"wrap",gap:8}},(n||[]).map(x=>e.createElement("label",{key:x,style:{display:"inline-flex",alignItems:"center",gap:4}},e.createElement(W,{checked:i.includes(x),onChange:()=>p(x)}),e.createElement("span",null,x))))}if(t==="flows"){let i=Array.isArray(o)?o:[];return e.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4},className:"mb-3"},kt(n).map(p=>e.createElement("label",{key:p.value,style:{display:"inline-flex",alignItems:"center",gap:4}},e.createElement(W,{checked:i.includes(p.value),onChange:()=>a(Z(i,p.value))}),e.createElement("span",null,p.label))))}return t==="integer"||t==="float"?e.createElement(A,{className:"mb-3",type:"number",step:t==="integer"?"1":"any",value:o??"",onChange:i=>r(i.target.value),onBlur:i=>a(i.target.value)}):e.createElement(A,{className:"mb-3",type:"text",value:o??"",onChange:i=>r(i.target.value),onBlur:i=>a(i.target.value)})},F=Ce;var wt=(t,o,n,r)=>t.map((a,d)=>d===o?{...a,[n]:r}:a);var Ne=({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),V=Ne;var Se=(t,o,n,r)=>{let a=(t||{})[n],d=(o||{})[n];return d?(a||{})[r[d]]:a},Be=({holds:t,labels:o,explanations:n,rows:r,choices:a,outputsOf:d,onChange:u,onSettle:i})=>{let p=Array.isArray(r)?r:[],x=(b,m,g,h)=>{let l=wt(p,b,m,g);h?i(l):u(l)};return e.createElement("div",{style:{marginBottom:12}},p.map((b,m)=>e.createElement("div",{key:m,className:"rounded-md border border-gray-200 dark:border-zinc-700",style:{padding:"8px 8px 2px",marginBottom:6}},Object.entries(t).map(([g,h])=>e.createElement("label",{key:g,style:{display:"block"}},e.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{display:"block",marginBottom:2,fontSize:11}},(o||{})[g]||g),e.createElement(F,{type:h,value:b[g],choices:Se(a,d,g,b),onChange:l=>x(m,g,l,!1),onSettle:l=>x(m,g,l,!0)}),(n||{})[g]&&e.createElement(V,{text:n[g]}))),e.createElement(k,{variant:"secondary",size:"sm",className:"mb-1.5",onClick:()=>i(p.filter((g,h)=>h!==m))},"Remove"))),e.createElement(k,{variant:"secondary",size:"sm",className:"w-full",onClick:()=>i([...p,{}])},"Add"))},Ct=Be;var ze=({as:t="div",className:o,children:n,...r})=>e.createElement(t,{...r,className:_("ks-panel",o)},n),M=ze;var U=(t,o)=>({className:n,children:r,...a})=>e.createElement(t,{...a,className:_(o,n)},r),H=U("label","ks-label"),Wr=U("p","ks-hint"),Fr=U("p","ks-error"),Vr=U("span","ks-required");var _e={width:280,padding:20,overflowY:"auto"},Ee=({node:t,fields:o,holds:n,labels:r,explanations:a,recordLabels:d,recordExplanations:u,recordChoices:i,recordOutputsOf:p,choices:x,onSave:b,onDelete:m,onClose:g,onPickPicture:h,refusal:l})=>{let[v,f]=w(t.config),[C,E]=w(t.picture_url);P(()=>E(t.picture_url),[t.id,t.picture_url]),P(()=>f(t.config),[t.id,t.config]);let N=y=>{f(y),JSON.stringify(y)!==JSON.stringify(t.config)&&b(y)};return e.createElement(M,{as:"aside",style:_e,"data-inspector":!0},e.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8}},e.createElement("h2",{style:{fontWeight:600,marginBottom:2}},t.label),e.createElement("button",{title:"Close",onClick:g,className:"text-gray-500 dark:text-gray-400",style:{border:"none",background:"none",cursor:"pointer",fontSize:18,lineHeight:1}},"\xD7")),e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginBottom:16}},t.id," \xB7 ",t.type),l&&e.createElement("p",{className:"text-red-800 dark:text-red-400",style:{fontWeight:600,marginBottom:12},"data-refusal":!0},l),Object.entries(o).map(([y,S])=>e.createElement(H,{key:y},e.createElement("span",{style:{display:"block",marginBottom:3}},r[y]||y),S==="list"?e.createElement(Ct,{holds:n[y]||{},labels:d[y]||{},explanations:(u||{})[y],rows:v[y],choices:{...(i||{})[y],...(t.record_choices||{})[y]},outputsOf:(p||{})[y],onChange:z=>f({...v,[y]:z}),onSettle:z=>N({...v,[y]:z})}):e.createElement(F,{type:S,value:v[y],choices:x[y],pictureUrl:C,onChange:z=>f({...v,[y]:z}),onSettle:z=>N({...v,[y]:z}),onPick:async z=>{let L=await h(z);L&&(E(L.url),N({...v,[y]:L.reference}))}}),(a||{})[y]&&e.createElement(V,{text:a[y]}))),e.createElement(k,{variant:"danger",size:"sm",className:"w-full",onClick:m},"Delete step"))},Nt=Ee;var Te={width:240,boxSizing:"border-box",padding:"10px 14px",borderRadius:8,textAlign:"center",fontSize:12,cursor:"pointer"},De="border-2 border-dashed border-amber-500 bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300",Ae="border-2 border-dashed border-accent-600 bg-accent-50 text-accent-800 dark:bg-accent-950 dark:text-accent-200",Oe=({node:t,dragging:o,onFill:n,onDrop:r})=>e.createElement("div",{ref:t.ref,"data-placeholder":t.id,title:`Choose the step \u201C${t.label}\u201D should lead to`,onClick:n,onDragOver:a=>{o&&(a.preventDefault(),a.dataTransfer.dropEffect="move")},onDrop:a=>{a.preventDefault(),r()},className:o?Ae:De,style:Te},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")),St=Oe;var Pe=({entries:t,at:o,onPick:n,onConnect:r,onDismiss:a,hideStepTypeCodes:d})=>e.createElement(M,{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(u=>e.createElement(k,{key:u.type,variant:"secondary",size:"sm",className:"w-full mb-1.5 flex-col",onClick:()=>n(u)},u.label,!d&&e.createElement("span",{className:"opacity-75",style:{display:"block",fontSize:11}},u.type))),r&&e.createElement(k,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:r},"Connect to a step already here"),e.createElement(k,{variant:"secondary",size:"sm",className:"w-full",onClick:a},"Cancel")),Bt=Pe;var $e={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},zt=({label:t,title:o,idle:n,enabled:r,onUse:a})=>e.createElement(k,{variant:"secondary",size:"sm",title:r?o:n,disabled:!r,onClick:a,style:{opacity:r?1:.4,cursor:r?"pointer":"default"}},t),Me=({undoable:t,redoable:o,onAdd:n,onUndo:r,onRedo:a})=>e.createElement("div",{style:{position:"absolute",top:16,left:16,zIndex:5,display:"flex",gap:8}},e.createElement(k,{variant:"secondary",className:"rounded-full",style:$e,title:"Add a step",onClick:n},"+"),e.createElement(zt,{label:"\u21B6 Undo",title:"Undo the last change",idle:"Nothing to undo",enabled:t,onUse:r}),e.createElement(zt,{label:"\u21B7 Redo",title:"Redo the change you undid",idle:"Nothing to redo",enabled:o,onUse:a})),_t=Me;var Le=({type:t="info",title:o,message:n,onDismiss:r,className:a})=>e.createElement("div",{className:_("ks-alert",`ks-alert-${t}`,a),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"},n)),r&&e.createElement("button",{type:"button",className:"ks-alert-dismiss","aria-label":"Dismiss",onClick:r},"\xD7"))),Et=Le;var Tt=t=>{let o=t.map(n=>`\u201C${n.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 Dt=({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 Ie={width:280,padding:20,overflowY:"auto"},Q={fontWeight:600,marginBottom:6,marginTop:14},Y={fontSize:12,marginBottom:4,lineHeight:1.4},At={display:"block",marginBottom:3},Ot=(t,o,n)=>r=>{r.target.value!==(t[o]??"")&&n({[o]:r.target.value})},He=({flow:t,changes:o,problems:n,refusal:r,notice:a,publishNote:d,warning:u,onCreate:i,onPublish:p,onAccept:x,onDecline:b,onSaveDetails:m,onClose:g})=>e.createElement(M,{as:"aside",style:Ie,"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:g,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},Dt(t)),u?e.createElement("div",{style:{marginTop:14},"data-unconnected-warning":!0},e.createElement(Et,{type:"warning",className:"mb-1.5",message:Tt(u.steps)}),e.createElement(k,{size:"sm",className:"w-full mb-1.5",onClick:x,"data-accept-removal":!0},u.path==="/publish"?"Remove and publish":"Remove and create version"),e.createElement(k,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:b,"data-decline-removal":!0},"Cancel")):e.createElement("div",{style:{marginTop:14}},e.createElement(k,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:i,"data-create-version":!0},"Create version"),e.createElement(k,{size:"sm",className:"w-full mb-1.5",onClick:p,"data-publish":!0},"Publish"),d&&e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12,lineHeight:1.4},"data-publish-note":!0},d)),e.createElement("h2",{style:Q},"Problems"),r&&e.createElement("p",{className:"text-red-800 dark:text-red-400",style:{...Y,fontWeight:600},"data-refusal":!0},r),a&&!r&&e.createElement("p",{className:"text-emerald-800 dark:text-emerald-400",style:{...Y,fontWeight:600},"data-notice":!0},a),n.length===0&&!r?e.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12}},"Nothing wrong with this flow."):n.map(h=>e.createElement("p",{key:`${h.node}-${h.problem}`,className:"text-amber-700 dark:text-amber-400",style:Y,"data-problem":!0},"\u26A0 ",h.sentence)),e.createElement("h2",{style:Q},"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,l)=>e.createElement("p",{key:l,style:Y,"data-change":!0},h)),e.createElement("h2",{style:Q},"Details"),e.createElement(H,null,e.createElement("span",{style:At},"Title"),e.createElement(A,{className:"mb-3",defaultValue:t.title??"",onBlur:Ot(t,"title",m),"data-flow-title":!0})),e.createElement(H,null,e.createElement("span",{style:At},"Start label"),e.createElement(A,{className:"mb-3",defaultValue:t.start_label??"",onBlur:Ot(t,"start_label",m),"data-flow-start-label":!0})),e.createElement("div",{style:{marginTop:16}},e.createElement(k,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.definition_url,"data-definition":!0},"Definition"),e.createElement(k,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.details_url,"data-details":!0},"Edit details"))),Pt=He;var $t={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},Mt=t=>({opacity:t?1:0,transition:"opacity .12s"}),je=({link:t,onInsert:o,onRemove:n,onDrop:r,dragging:a,alwaysShowInsertButtons:d})=>{let[u,i]=w(!1),p=u||a;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:()=>i(!0),onMouseLeave:()=>i(!1),onDragEnter:()=>i(!0),onDragLeave:()=>i(!1),onDragOver:x=>{x.preventDefault(),x.dataTransfer.dropEffect="move"},onDrop:x=>{x.preventDefault(),i(!1),r()}},e.createElement("div",{style:{display:"flex",gap:4,justifyContent:"center",alignItems:"center",height:"100%"}},e.createElement(k,{variant:"secondary",title:a?"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":!!(a&&u),style:{...$t,...Mt(p||d)}},"+"),!a&&e.createElement(k,{variant:"danger",title:"Remove this connection",onClick:n,className:"rounded-full",style:{...$t,...Mt(p)}},"\xD7")))},Lt=je;var We=({links:t,extent:o,dragging:n,onInsert:r,onRemove:a,onDrop:d,alwaysShowInsertButtons:u})=>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(i=>e.createElement("path",{key:i.id,"data-link":i.id,className:"stroke-gray-400 dark:stroke-zinc-500",fill:"none",strokeWidth:"1.5",markerEnd:"url(#easy_flow-arrow)",d:i.path}))),t.filter(i=>i.label).map(i=>e.createElement("div",{key:`${i.id}-label`,"data-link-label":i.id,className:"bg-surface-50 text-gray-500 dark:bg-surface-950 dark:text-gray-400",style:{position:"absolute",left:i.midX+(u?2:-10),top:i.midY-18,zIndex:3,fontSize:11,padding:"0 3px"}},i.label)),t.filter(i=>!i.placeholder).map(i=>e.createElement(Lt,{key:i.id,link:i,dragging:!!n,alwaysShowInsertButtons:u,onInsert:()=>r(i),onRemove:()=>a(i),onDrop:()=>d(i)}))),It=We;var Ht="Your change was not saved because the server could not be reached.",jt=({base:t,token:o,fetch:n,onFlow:r,onError:a,onNotice:d,onWarning:u=()=>{}})=>async(i,p,x)=>{let b=await n(t+i,{method:p,headers:{"Content-Type":"application/json","X-CSRF-Token":o},body:x&&JSON.stringify(x)}).catch(()=>null);if(!b)return d(null),a(Ht);let m=await b.json().catch(()=>({}));if(m.unconnected)return d(null),a(null),u({path:i,steps:m.unconnected}),r(await(await n(t+".json",{headers:{Accept:"application/json"}})).json());if(u(null),!b.ok)return d(null),a(m.error||"That change was refused");a(null),d(m.notice||null),r(await(await n(t+".json",{headers:{Accept:"application/json"}})).json())},Wt=({base:t,token:o,fetch:n,onError:r})=>async a=>{let d=new FormData;d.append("picture",a);let u=await n(t+"/pictures",{method:"POST",headers:{"X-CSRF-Token":o},body:d}).catch(()=>null);if(!u)return r(Ht),null;let i=await u.json().catch(()=>({}));return u.ok?(r(null),i):(r(i.error||"That picture was refused"),null)};var Fe=(t,o,n)=>{let[r,a]=w(n),[d,u]=w(null),[i,p]=w(null),[x,b]=w(null),m=$(()=>jt({base:t,token:o,fetch:(...h)=>window.fetch(...h),onFlow:a,onError:u,onNotice:p,onWarning:b}),[t,o]),g=$(()=>Wt({base:t,token:o,fetch:(...h)=>window.fetch(...h),onError:u}),[t,o]);return{flow:r,error:d,notice:i,warning:x,setWarning:b,send:m,pickPicture:g}},Ft=Fe;var G=(t,o,n,r)=>{let a=t.left-n.left+r.scrollLeft,d=t.top-n.top+r.scrollTop;return o==="left"?{x:a,y:d+t.height/2}:o==="right"?{x:a+t.width,y:d+t.height/2}:o==="top"?{x:a+t.width/2,y:d}:{x:a+t.width/2,y:d+t.height}},Ve=(t,o,n)=>n&&o==="top"?{x:t.x,y:n.top}:t,Ue=(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},Ye=(t,o,n,r,a)=>{let d={straight:`M ${o.x} ${o.y} L ${n.x} ${n.y}`,turn:`M ${o.x} ${o.y} H ${n.x} V ${n.y}`,lane:`M ${o.x} ${o.y} V ${r} H ${n.x} V ${n.y}`,detour:`M ${o.x} ${o.y} H ${a} V ${n.y} H ${n.x}`}[t.route];return{...t,path:d,midX:t.route==="detour"?a:(o.x+n.x)/2,midY:t.route==="lane"?r:(o.y+n.y)/2}},Ge=(t,o,n,r)=>{let[a,d]=w([]),[u,i]=w({width:"100%",height:"100%"}),[p,x]=w([]);return st(()=>{let b=()=>{let g=o.current?.getBoundingClientRect();if(!g)return;i({width:o.current.scrollWidth,height:o.current.scrollHeight});let h=t.nodes.filter(l=>l.holds&&!l.loose&&n.current[l.id]).map(l=>{let v=n.current[l.id],f=v.getBoundingClientRect(),C=l.holds.flatMap(N=>n.current[N]?[n.current[N].getBoundingClientRect()]:[]),E=[{left:f.left,top:f.top,width:Math.max(f.width,v.scrollWidth),height:f.height},...C];return{id:l.id,bounds:gt(E,g,o.current)}});x(h),d(t.edges.flatMap(l=>{let v=n.current[l.source]?.getBoundingClientRect(),f=n.current[l.target]?.getBoundingClientRect();if(!v||!f)return[];let C=G(v,l.leaves,g,o.current),E=h.find(z=>z.id===l.target)?.bounds,N=Ue(Ve(G(f,l.enters,g,o.current),l.enters,E),l.enters),y=(G(v,"bottom",g,o.current).y+G(f,"top",g,o.current).y)/2,S=l.leaves==="left"?Math.min(C.x,N.x)-28:Math.max(C.x,N.x)+28;return[Ye(l,C,N,y,S)]}))};b(),window.addEventListener("resize",b);let m=new ResizeObserver(b);return o.current&&m.observe(o.current),()=>{window.removeEventListener("resize",b),m.disconnect()}},r),{links:a,extent:u,boxes:p}},Vt=Ge;var Ut=(t,o)=>{let n=new Set(o),r=t,a=2;for(;n.has(r);)r=`${t}_${a++}`;return r};var qe=8,Je={display:"flex",height:"100%",minHeight:0,fontSize:13},Ke={flex:1,overflow:"auto",position:"relative"},Ze={position:"absolute",top:56,left:16,zIndex:5,width:264,padding:12,borderRadius:8},Qe={display:"grid",rowGap:64,columnGap:0,padding:40,justifyContent:"center",position:"relative"},Re={position:"sticky",zIndex:8,top:8,margin:"8px auto 0",width:"fit-content",padding:"6px 12px",borderRadius:6,fontSize:12},to=({port:t,onCancel:o})=>e.createElement("div",{className:"bg-accent-100 text-accent-800 dark:bg-accent-900 dark:text-accent-100",style:Re},"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")),eo=({base:t,token:o,initial:n})=>{let{flow:r,error:a,notice:d,warning:u,setWarning:i,send:p,pickPicture:x}=Ft(t,o,n),[b,m]=w(null),[g,h]=w(null),[l,v]=w(null),[f,C]=w(null),[E,N]=w(!1),y=J({}),S=J(null);P(()=>{let s=()=>{m(null),N(!0)};return document.addEventListener("easy_flow:open-flow",s),()=>document.removeEventListener("easy_flow:open-flow",s)},[]),P(()=>{if(!E){i(null);return}let s=c=>{c.target.isConnected&&!c.target.closest("[data-builder-panel], [data-open-panel]")&&N(!1)};return document.addEventListener("click",s),()=>document.removeEventListener("click",s)},[E]),P(()=>{document.dispatchEvent(new CustomEvent("easy_flow:flow-named",{detail:r.flow?.title||r.flow?.slug}))},[r.flow?.title,r.flow?.slug]);let z=$(()=>Object.fromEntries(r.nodes.map(s=>[s.id,s])),[r.nodes]),{links:L,extent:Xt,boxes:R}=Vt(r,S,y,[r,b,z]),tt=$(()=>{let s={};return r.violations.forEach(c=>{var B;return(s[B=c.node]||(s[B]=[])).push(c)}),s},[r.violations]),X=r.nodes.filter(s=>!s.loose),et=r.nodes.filter(s=>s.loose),qt=Math.max(0,...X.map(s=>s.row))+1,Jt=Math.max(0,...X.map(s=>s.column))+1,q=s=>{if(!l)return;let[c,B]=l;v(null),c!==s&&p("/edges","POST",{from:c,to:s,on:B||null})},Kt=s=>{if(s.isDefaultPrevented()||!f)return;s.preventDefault();let c=f;C(null);let B=S.current.getBoundingClientRect(),I=ht(R,{x:s.clientX-B.left+S.current.scrollLeft,y:s.clientY-B.top+S.current.scrollTop}),Zt=r.nodes.find(Qt=>Qt.holds?.includes(c))?.id||null;I!==Zt&&p(`/steps/${c}/group`,"PATCH",{group:I})},ot=s=>[...r.palette,...r.unoffered||[]].find(c=>c.type===s?.type),O=r.nodes.find(s=>s.id===b),T=ot(O);return e.createElement("div",{className:"text-gray-900 dark:text-gray-100",style:Je,onMouseUp:()=>C(null),onKeyDown:s=>{s.key==="Escape"&&(m(null),v(null),h(null))},tabIndex:-1},e.createElement("div",{ref:S,className:"bg-surface-50 dark:bg-surface-950",style:Ke,onClick:s=>{s.target===S.current&&(m(null),v(null),N(!1))},onDragOver:s=>{f&&s.preventDefault()},onDrop:Kt},l&&e.createElement(to,{port:l[1],onCancel:()=>v(null)}),e.createElement(_t,{undoable:r.undoable,redoable:r.redoable,onAdd:()=>h({at:{x:16,y:52}}),onUndo:()=>{m(null),p("/undo","POST")},onRedo:()=>{m(null),p("/redo","POST")}}),R.map(s=>e.createElement(mt,{key:s.id,id:s.id,bounds:s.bounds,onDrop:()=>{let c=f;C(null),c&&p(`/steps/${c}/group`,"PATCH",{group:s.id})}})),e.createElement(It,{links:yt(L,r.nodes),extent:Xt,dragging:f,alwaysShowInsertButtons:r.always_show_insert_buttons,onInsert:s=>h({from:s.source,to:s.target,at:{x:s.midX+30,y:s.midY}}),onRemove:s=>{m(null),p("/edges","DELETE",{from:s.source,to:s.target})},onDrop:s=>{let c=f;C(null),p("/steps/"+c+"/move","PATCH",{from:s.source,to:s.target})}}),et.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:Ze},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"),et.map(s=>e.createElement("div",{key:s.id,style:{marginBottom:8}},e.createElement(K,{node:{...s,ref:c=>{y.current[s.id]=c},violations:tt[s.id]||[],connected:[]},selected:b===s.id,armed:l&&l[0]===s.id?l[1]:null,connecting:!!l,onSelect:()=>l?q(s.id):m(s.id),onOpen:c=>window.location.assign(c),onArm:(c,B)=>{B.stopPropagation(),v([s.id,c])},onDragStart:()=>C(s.id),onDragEnd:()=>C(null),hideStepTypeCodes:r.hide_step_type_codes})))),e.createElement("div",{style:{...Qe,gridTemplateColumns:`repeat(${Jt+1}, ${280/2}px)`,gridTemplateRows:`repeat(${qt}, auto)`}},X.map(s=>e.createElement("div",{key:s.id,style:{gridRow:s.row+1,gridColumn:`${s.column+1} / span 2`,zIndex:2,marginTop:xt(s,r.nodes)?qe-64:0}},s.placeholder&&e.createElement(St,{node:{...s,ref:c=>{y.current[s.id]=c}},dragging:!!f,onFill:()=>h({from:s.from,on:s.on,at:{x:16,y:52}}),onDrop:()=>{let c=f;C(null),c&&p("/edges","POST",{from:s.from,to:c,on:s.on})}}),s.holds&&e.createElement(ut,{node:{...s,ref:c=>{y.current[s.id]=c}},header:ft(s,ot(s),r.hide_step_type_codes),onSelect:()=>l?q(s.id):m(s.id)}),!s.placeholder&&!s.holds&&e.createElement(K,{node:{...s,ref:c=>{y.current[s.id]=c},violations:tt[s.id]||[],connected:r.edges.filter(c=>c.source===s.id).map(c=>c.label||null)},selected:s.id===b,armed:l&&l[0]===s.id?l[1]:null,connecting:!!l&&l[0]!==s.id,onSelect:()=>l?q(s.id):m(s.id),onOpen:c=>window.location.assign(c),onArm:(c,B)=>{let I=S.current.getBoundingClientRect();h({from:s.id,on:c,at:{x:B.clientX-I.left+S.current.scrollLeft+8,y:B.clientY-I.top+S.current.scrollTop+8}})},onDragEnd:()=>C(null),onDragStart:()=>C(s.id),hideStepTypeCodes:r.hide_step_type_codes})))),g&&e.createElement(Bt,{entries:r.palette,at:g.at,onDismiss:()=>h(null),hideStepTypeCodes:r.hide_step_type_codes,onConnect:g.on!==void 0?()=>{v([g.from,g.on]),h(null)}:null,onPick:s=>{let c=g;h(null),p("/steps","POST",{id:Ut(s.type,r.nodes.map(B=>B.id)),type:s.type,from:c.from,to:c.to,on:c.on})}})),E&&!O&&e.createElement(Pt,{flow:r.flow||{},changes:r.changes||[],problems:r.violations,refusal:a,notice:d,publishNote:r.publish_note,warning:u,onClose:()=>N(!1),onCreate:()=>p("/versions","POST"),onPublish:()=>p("/publish","POST"),onAccept:()=>p(u.path,"POST",{remove_unconnected:u.steps.map(s=>s.id)}),onDecline:()=>i(null),onSaveDetails:s=>p("/details","PATCH",{flow:s})}),O&&e.createElement(Nt,{node:O,fields:T?.fields||{},holds:T?.records||{},labels:T?.labels||{},explanations:T?.explanations||{},recordLabels:T?.record_labels||{},recordExplanations:T?.record_explanations||{},recordChoices:T?.record_choices||{},recordOutputsOf:T?.record_outputs_of||{},choices:bt(O,T),onClose:()=>m(null),onSave:s=>p(`/steps/${O.id}`,"PATCH",{config:s}),onPickPicture:x,refusal:a,onDelete:()=>{m(null),p(`/steps/${O.id}`,"DELETE")}}))},Gt=eo;it("easy_flow/flow-editor",Gt);document.addEventListener("easy_flow:flow-named",t=>{let o=document.querySelector("[data-flow-heading]");o&&(o.textContent=t.detail)});ct(document,rt);})();
@@ -65,6 +65,10 @@ module EasyFlow
65
65
  apply(:moved, params[:step]) { |edited| edited.move(params[:step], on: edge_endpoints, leaving: port_for(params[:step])) }
66
66
  end
67
67
 
68
+ def group_step
69
+ apply(:moved, params[:step]) { |edited| edited.group(params[:step], into: params[:group].presence) }
70
+ end
71
+
68
72
  def remove_step
69
73
  return render json: { error: refusal_to_remove }, status: :unprocessable_entity if begins_the_flow?(params[:step])
70
74
 
@@ -1,5 +1,8 @@
1
1
  import React, { useEffect, useMemo, useRef, useState } from "react"
2
2
  import StepCard from "./StepCard"
3
+ import GroupHeader from "./GroupHeader"
4
+ import GroupBox from "./GroupBox"
5
+ import { boxAt, headerOf, linksOutside, underHeader } from "./group"
3
6
  import Inspector from "./Inspector"
4
7
  import Placeholder from "./Placeholder"
5
8
  import { offeredTo } from "./choices"
@@ -12,6 +15,8 @@ import useConnectors from "./useConnectors"
12
15
  import { CARD, GAP_X, GAP_Y } from "./styles"
13
16
  import { nextId } from "./ids"
14
17
 
18
+ const HEADER_GAP = 8
19
+
15
20
  const page = { display: "flex", height: "100%", minHeight: 0, fontSize: 13 }
16
21
  const scroll = { flex: 1, overflow: "auto", position: "relative" }
17
22
  const waiting = { position: "absolute", top: 56, left: 16, zIndex: 5, width: CARD + 24, padding: 12, borderRadius: 8 }
@@ -59,7 +64,7 @@ const Canvas = ({ base, token, initial }) => {
59
64
  }, [ flow.flow?.title, flow.flow?.slug ])
60
65
 
61
66
  const byId = useMemo(() => Object.fromEntries(flow.nodes.map((node) => [ node.id, node ])), [ flow.nodes ])
62
- const { links, extent } = useConnectors(flow, surface, cards, [ flow, selected, byId ])
67
+ const { links, extent, boxes } = useConnectors(flow, surface, cards, [ flow, selected, byId ])
63
68
 
64
69
  const violationsFor = useMemo(() => {
65
70
  const grouped = {}
@@ -80,15 +85,29 @@ const Canvas = ({ base, token, initial }) => {
80
85
  if (source !== target) send("/edges", "POST", { from: source, to: target, on: port || null })
81
86
  }
82
87
 
88
+ const regroup = (event) => {
89
+ if (event.isDefaultPrevented() || !dragging) return
90
+ event.preventDefault()
91
+ const held = dragging
92
+ setDragging(null)
93
+ const frame = surface.current.getBoundingClientRect()
94
+ const into = boxAt(boxes, { x: event.clientX - frame.left + surface.current.scrollLeft, y: event.clientY - frame.top + surface.current.scrollTop })
95
+ const from = flow.nodes.find((node) => node.holds?.includes(held))?.id || null
96
+ if (into !== from) send(`/steps/${held}/group`, "PATCH", { group: into })
97
+ }
98
+
99
+ const entryOf = (node) => [ ...flow.palette, ...(flow.unoffered || []) ].find((entry) => entry.type === node?.type)
83
100
  const selectedNode = flow.nodes.find((node) => node.id === selected)
84
- const entryFor = [ ...flow.palette, ...(flow.unoffered || []) ].find((entry) => entry.type === selectedNode?.type)
101
+ const entryFor = entryOf(selectedNode)
85
102
 
86
103
  return (
87
104
  <div className="text-gray-900 dark:text-gray-100" style={page} onMouseUp={() => setDragging(null)}
88
105
  onKeyDown={(event) => { if (event.key === "Escape") { setSelected(null); setArmed(null); setAdding(null) } }}
89
106
  tabIndex={-1}>
90
107
  <div ref={surface} className="bg-surface-50 dark:bg-surface-950" style={scroll}
91
- onClick={(event) => { if (event.target === surface.current) { setSelected(null); setArmed(null); setShowing(false) } }}>
108
+ onClick={(event) => { if (event.target === surface.current) { setSelected(null); setArmed(null); setShowing(false) } }}
109
+ onDragOver={(event) => { if (dragging) event.preventDefault() }}
110
+ onDrop={regroup}>
92
111
  {armed && (
93
112
  <Choosing port={armed[1]} onCancel={() => setArmed(null)} />
94
113
  )}
@@ -97,7 +116,12 @@ const Canvas = ({ base, token, initial }) => {
97
116
  onUndo={() => { setSelected(null); send("/undo", "POST") }}
98
117
  onRedo={() => { setSelected(null); send("/redo", "POST") }} />
99
118
 
100
- <ConnectorLayer links={links} extent={extent} dragging={dragging} alwaysShowInsertButtons={flow.always_show_insert_buttons}
119
+ {boxes.map((box) => (
120
+ <GroupBox key={box.id} id={box.id} bounds={box.bounds}
121
+ onDrop={() => { const held = dragging; setDragging(null); if (held) send(`/steps/${held}/group`, "PATCH", { group: box.id }) }} />
122
+ ))}
123
+
124
+ <ConnectorLayer links={linksOutside(links, flow.nodes)} extent={extent} dragging={dragging} alwaysShowInsertButtons={flow.always_show_insert_buttons}
101
125
  onInsert={(link) => setAdding({ from: link.source, to: link.target, at: { x: link.midX + 30, y: link.midY } })}
102
126
  onRemove={(link) => { setSelected(null); send("/edges", "DELETE", { from: link.source, to: link.target }) }}
103
127
  onDrop={(link) => { const held = dragging; setDragging(null); send("/steps/" + held + "/move", "PATCH", { from: link.source, to: link.target }) }} />
@@ -130,7 +154,7 @@ const Canvas = ({ base, token, initial }) => {
130
154
 
131
155
  <div style={{ ...grid, gridTemplateColumns: `repeat(${columns + 1}, ${(CARD + GAP_X) / 2}px)`, gridTemplateRows: `repeat(${rows}, auto)` }}>
132
156
  {attached.map((node) => (
133
- <div key={node.id} style={{ gridRow: node.row + 1, gridColumn: `${node.column + 1} / span 2`, zIndex: 2 }}>
157
+ <div key={node.id} style={{ gridRow: node.row + 1, gridColumn: `${node.column + 1} / span 2`, zIndex: 2, marginTop: underHeader(node, flow.nodes) ? HEADER_GAP - GAP_Y : 0 }}>
134
158
  {node.placeholder && (
135
159
  <Placeholder node={{ ...node, ref: (element) => { cards.current[node.id] = element } }}
136
160
  dragging={Boolean(dragging)}
@@ -141,7 +165,12 @@ const Canvas = ({ base, token, initial }) => {
141
165
  if (held) send("/edges", "POST", { from: node.from, to: held, on: node.on })
142
166
  }} />
143
167
  )}
144
- {!node.placeholder && <StepCard
168
+ {node.holds && (
169
+ <GroupHeader node={{ ...node, ref: (element) => { cards.current[node.id] = element } }}
170
+ header={headerOf(node, entryOf(node), flow.hide_step_type_codes)}
171
+ onSelect={() => (armed ? connectTo(node.id) : setSelected(node.id))} />
172
+ )}
173
+ {!node.placeholder && !node.holds && <StepCard
145
174
  node={{
146
175
  ...node,
147
176
  ref: (element) => { cards.current[node.id] = element },
@@ -0,0 +1,11 @@
1
+ import React from "react"
2
+
3
+ const GroupBox = ({ id, bounds, onDrop }) => (
4
+ <div data-group-box={id}
5
+ onDragOver={(event) => { event.preventDefault(); event.dataTransfer.dropEffect = "move" }}
6
+ onDrop={(event) => { event.preventDefault(); onDrop() }}
7
+ className="border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60"
8
+ style={{ position: "absolute", zIndex: 1, borderRadius: 8, boxSizing: "border-box", ...bounds }} />
9
+ )
10
+
11
+ export default GroupBox
@@ -0,0 +1,10 @@
1
+ import React from "react"
2
+ import { CARD } from "./styles"
3
+
4
+ const GroupHeader = ({ node, header, onSelect }) => (
5
+ <div ref={node.ref} data-group-header={node.id} onClick={onSelect}
6
+ className="font-mono text-gray-500 dark:text-gray-400"
7
+ style={{ position: "relative", zIndex: 2, width: CARD, fontSize: 11, whiteSpace: "nowrap", cursor: "pointer" }}>{header}</div>
8
+ )
9
+
10
+ export default GroupHeader
@@ -0,0 +1,35 @@
1
+ const filledIn = (value) => value !== undefined && value !== null && value !== "" && typeof value !== "object"
2
+
3
+ const NUMBERS = [ "integer", "float" ]
4
+
5
+ const settingName = (name, entry, hideStepTypeCodes) => (hideStepTypeCodes && entry.labels?.[name]) || name
6
+
7
+ export const headerOf = (node, entry, hideStepTypeCodes) => {
8
+ const named = Object.keys(entry?.fields || {}).filter((name) => filledIn(node.config[name]))
9
+ .map((name) => `${settingName(name, entry, hideStepTypeCodes)}${NUMBERS.includes(entry.fields[name]) ? "" : ":"} ${node.config[name]}`)
10
+
11
+ return [ hideStepTypeCodes ? node.type_name || node.type : node.type, ...named ].join(" · ")
12
+ }
13
+
14
+ const ROOM_ABOVE = 10
15
+ const ROOM_BESIDE = 12
16
+
17
+ export const boxAround = (boxes, frame, surface) => {
18
+ const left = Math.min(...boxes.map((box) => box.left)) - frame.left + surface.scrollLeft - ROOM_BESIDE
19
+ const top = Math.min(...boxes.map((box) => box.top)) - frame.top + surface.scrollTop - ROOM_ABOVE
20
+ const right = Math.max(...boxes.map((box) => box.left + box.width)) - frame.left + surface.scrollLeft + ROOM_BESIDE
21
+ const bottom = Math.max(...boxes.map((box) => box.top + box.height)) - frame.top + surface.scrollTop + ROOM_ABOVE
22
+
23
+ return { left, top, width: right - left, height: bottom - top }
24
+ }
25
+
26
+ const inside = ({ left, top, width, height }, point) =>
27
+ point.x >= left && point.x <= left + width && point.y >= top && point.y <= top + height
28
+
29
+ export const boxAt = (boxes, point) => boxes.find((box) => inside(box.bounds, point))?.id || null
30
+
31
+ export const linksOutside = (links, nodes) =>
32
+ links.filter((link) => !nodes.some((node) => node.id === link.source && node.holds?.includes(link.target)))
33
+
34
+ export const underHeader = (node, nodes) =>
35
+ nodes.some((group) => group.holds?.includes(node.id) && !group.loose && group.row === node.row - 1)
@@ -1,4 +1,5 @@
1
1
  import { useLayoutEffect, useState } from "react"
2
+ import { boxAround } from "./group"
2
3
 
3
4
  export const anchor = (box, side, frame, surface) => {
4
5
  const left = box.left - frame.left + surface.scrollLeft
@@ -10,6 +11,9 @@ export const anchor = (box, side, frame, surface) => {
10
11
  return { x: left + box.width / 2, y: top + box.height }
11
12
  }
12
13
 
14
+ export const entering = (point, side, bounds) =>
15
+ bounds && side === "top" ? { x: point.x, y: bounds.top } : point
16
+
13
17
  export const shy = (point, side) => {
14
18
  if (side === "top") return { x: point.x, y: point.y - 3 }
15
19
  if (side === "left") return { x: point.x - 3, y: point.y }
@@ -35,6 +39,7 @@ export const drawn = (edge, a, b, lane, detour) => {
35
39
  const useConnectors = (flow, surface, cards, watching) => {
36
40
  const [ links, setLinks ] = useState([])
37
41
  const [ extent, setExtent ] = useState({ width: "100%", height: "100%" })
42
+ const [ boxes, setBoxes ] = useState([])
38
43
 
39
44
  useLayoutEffect(() => {
40
45
  const measure = () => {
@@ -43,13 +48,24 @@ const useConnectors = (flow, surface, cards, watching) => {
43
48
 
44
49
  setExtent({ width: surface.current.scrollWidth, height: surface.current.scrollHeight })
45
50
 
51
+ const measuredBoxes = flow.nodes.filter((node) => node.holds && !node.loose && cards.current[node.id]).map((node) => {
52
+ const header = cards.current[node.id]
53
+ const headerBox = header.getBoundingClientRect()
54
+ const held = node.holds.flatMap((id) => (cards.current[id] ? [ cards.current[id].getBoundingClientRect() ] : []))
55
+ const measured = [ { left: headerBox.left, top: headerBox.top, width: Math.max(headerBox.width, header.scrollWidth), height: headerBox.height }, ...held ]
56
+
57
+ return { id: node.id, bounds: boxAround(measured, frame, surface.current) }
58
+ })
59
+ setBoxes(measuredBoxes)
60
+
46
61
  setLinks(flow.edges.flatMap((edge) => {
47
62
  const fromBox = cards.current[edge.source]?.getBoundingClientRect()
48
63
  const toBox = cards.current[edge.target]?.getBoundingClientRect()
49
64
  if (!fromBox || !toBox) return []
50
65
 
51
66
  const a = anchor(fromBox, edge.leaves, frame, surface.current)
52
- const b = shy(anchor(toBox, edge.enters, frame, surface.current), edge.enters)
67
+ const box = measuredBoxes.find((measured) => measured.id === edge.target)?.bounds
68
+ const b = shy(entering(anchor(toBox, edge.enters, frame, surface.current), edge.enters, box), edge.enters)
53
69
  const lane = (anchor(fromBox, "bottom", frame, surface.current).y + anchor(toBox, "top", frame, surface.current).y) / 2
54
70
  const detour = edge.leaves === "left" ? Math.min(a.x, b.x) - 28 : Math.max(a.x, b.x) + 28
55
71
 
@@ -69,7 +85,7 @@ const useConnectors = (flow, surface, cards, watching) => {
69
85
  }
70
86
  }, watching)
71
87
 
72
- return { links, extent }
88
+ return { links, extent, boxes }
73
89
  }
74
90
 
75
91
  export default useConnectors
@@ -22,7 +22,7 @@ module EasyFlow
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),
24
24
  "config" => node.config.merge(kept_values(node)), "ports" => [], "ends_here" => ends_here?(node), "begins_here" => begins_here?(node),
25
- "starts_a_flow" => starts_a_flow?(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] }
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
 
28
28
  def picture_url(node)
@@ -227,6 +227,10 @@ module EasyFlow
227
227
  step_type_for(node)&.starts_a_flow? || false
228
228
  end
229
229
 
230
+ def holds(node)
231
+ Array(node.config["holds"]) if step_type_for(node)&.holds_steps?
232
+ end
233
+
230
234
  def opens(node)
231
235
  named = ChosenFlow.of(node).flow_id
232
236
  @flow_path.call(named) if @flow_path && starts_a_flow?(node) && named
@@ -87,6 +87,7 @@ module EasyFlow
87
87
 
88
88
  live_version&.update!(status: :superseded)
89
89
  version.update!(status: :live)
90
+ EasyFlow.host_named(host).published(self)
90
91
  end
91
92
 
92
93
  def available?
@@ -25,6 +25,10 @@ module EasyFlow
25
25
  @registry.registered?(node.type) && @registry.fetch(node.type).begins_here?
26
26
  end
27
27
 
28
+ def holds_steps?(node)
29
+ node.present? && @registry.registered?(node.type) && @registry.fetch(node.type).holds_steps?
30
+ end
31
+
28
32
  def node(id)
29
33
  nodes.find { |node| node.id == id }
30
34
  end
@@ -82,17 +86,27 @@ module EasyFlow
82
86
  step = raw_nodes.find { |node| node["id"] == id }
83
87
  return self unless step
84
88
 
85
- remove(id).insert(step, on: on, leaving: leaving)
89
+ detach(id, raw_nodes).insert(step, on: on, leaving: leaving)
86
90
  end
87
91
 
88
92
  def configure(id, config)
89
93
  reconfigured = raw_nodes.map do |node|
90
- node["id"] == id ? node.slice("id", "type").merge(config) : node
94
+ node["id"] == id ? node.slice("id", "type", "holds").merge(config.except("holds")) : node
91
95
  end
92
96
 
93
97
  with(nodes: reconfigured, edges: raw_edges)
94
98
  end
95
99
 
100
+ def group(id, into:)
101
+ raise InvalidEdit, "#{into} cannot hold steps" if into && (into == id || !holds_steps?(node(into)))
102
+
103
+ regrouped = released(id).map do |node|
104
+ node["id"] == into ? node.merge("holds" => Array(node["holds"]) + [ id ]) : node
105
+ end
106
+
107
+ with(nodes: regrouped, edges: raw_edges)
108
+ end
109
+
96
110
  def rewire(from:, to:, target:)
97
111
  rewritten = raw_edges.map do |edge|
98
112
  edge["from"] == from && edge["to"] == to ? edge.merge("to" => target) : edge
@@ -102,11 +116,7 @@ module EasyFlow
102
116
  end
103
117
 
104
118
  def remove(id)
105
- incoming = raw_edges.select { |edge| edge["to"] == id }
106
- outgoing = raw_edges.select { |edge| edge["from"] == id }
107
-
108
- with(nodes: raw_nodes.reject { |node| node["id"] == id },
109
- edges: (raw_edges - incoming - outgoing) + bridges(incoming, outgoing))
119
+ detach(id, released(id))
110
120
  end
111
121
 
112
122
  def without(ids)
@@ -116,6 +126,18 @@ module EasyFlow
116
126
 
117
127
  private
118
128
 
129
+ def detach(id, nodes)
130
+ incoming = raw_edges.select { |edge| edge["to"] == id }
131
+ outgoing = raw_edges.select { |edge| edge["from"] == id }
132
+
133
+ with(nodes: nodes.reject { |node| node["id"] == id },
134
+ edges: (raw_edges - incoming - outgoing) + bridges(incoming, outgoing))
135
+ end
136
+
137
+ def released(id)
138
+ raw_nodes.map { |node| node.key?("holds") ? node.merge("holds" => node["holds"] - [ id ]) : node }
139
+ end
140
+
119
141
  def bridges(incoming, outgoing)
120
142
  incoming.product(outgoing).map do |arriving, leaving|
121
143
  { "from" => arriving["from"], "to" => leaving["to"], "on" => arriving["on"] }.compact
@@ -27,6 +27,7 @@ module EasyFlow
27
27
  @begins_here = false
28
28
  @starts_a_flow = false
29
29
  @plays_the_picked_flow = false
30
+ @holds_steps = false
30
31
  end
31
32
 
32
33
  def output(name, type: :string, label: nil, values: nil, from: nil)
@@ -97,6 +98,10 @@ module EasyFlow
97
98
  @plays_the_picked_flow = true
98
99
  end
99
100
 
101
+ def holds_steps
102
+ @holds_steps = true
103
+ end
104
+
100
105
  def chooses_flow_from_run(&chooser)
101
106
  @run_chooser = chooser
102
107
  end
@@ -157,7 +162,7 @@ module EasyFlow
157
162
 
158
163
  def to_step_type
159
164
  StepType.new(id: @id, step_name: @step_name, settings: settings, awaits_input: @awaits_input,
160
- ends_here: @ends_here, begins_here: @begins_here, starts_a_flow: @starts_a_flow, plays_the_picked_flow: @plays_the_picked_flow, flow_chooser: @flow_chooser, run_chooser: @run_chooser, behaviour: @behaviour, routing: @routing,
165
+ 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,
161
166
  display: @display, drawn_by: @drawn_by, naming_field: @naming_field, naming: @naming,
162
167
  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)
163
168
  end
@@ -11,7 +11,7 @@ module EasyFlow
11
11
  attr_reader :id, :step_name, :settings, :naming_field, :naming, :outputs, :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, 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, flow_chooser: nil, run_chooser: nil, display: nil, drawn_by: nil,
15
15
  naming_field: nil, naming: 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
@@ -21,6 +21,7 @@ module EasyFlow
21
21
  @begins_here = begins_here
22
22
  @starts_a_flow = starts_a_flow
23
23
  @plays_the_picked_flow = plays_the_picked_flow
24
+ @holds_steps = holds_steps
24
25
  @flow_chooser = flow_chooser
25
26
  @run_chooser = run_chooser
26
27
  @behaviour = behaviour
@@ -114,6 +115,10 @@ module EasyFlow
114
115
  @plays_the_picked_flow
115
116
  end
116
117
 
118
+ def holds_steps?
119
+ @holds_steps
120
+ end
121
+
117
122
  def chooses_flow_from_run?
118
123
  !@run_chooser.nil?
119
124
  end
data/config/routes.rb CHANGED
@@ -14,6 +14,7 @@ EasyFlow::Engine.routes.draw do
14
14
  patch "steps/:step", action: :configure_step
15
15
  delete "steps/:step", action: :remove_step
16
16
  patch "steps/:step/move", action: :move_step
17
+ patch "steps/:step/group", action: :group_step
17
18
  post "versions", action: :create
18
19
  post "publish", action: :publish
19
20
  patch "details", action: :details
@@ -3,7 +3,7 @@ module EasyFlow
3
3
  BackLink = Data.define(:label, :address)
4
4
 
5
5
  attr_reader :name, :back_link
6
- attr_writer :layout, :admin_layout, :offers, :allowed_answers, :always_show_insert_buttons, :hide_step_type_codes, :marks_ends
6
+ attr_writer :layout, :admin_layout, :offers, :allowed_answers, :always_show_insert_buttons, :hide_step_type_codes, :marks_ends, :on_publish
7
7
  attr_accessor :admin_authentication_method, :visitor_authorization_method, :refusal_method, :owner_method, :finds_flows_across_owners, :publish_note
8
8
 
9
9
  def initialize(name)
@@ -61,6 +61,10 @@ module EasyFlow
61
61
  @setting_explanations.to_h.dig(step_type.to_s, setting.to_s).presence
62
62
  end
63
63
 
64
+ def published(flow)
65
+ @on_publish&.call(flow)
66
+ end
67
+
64
68
  def offers?(step_type)
65
69
  @offers.nil? || @offers.map(&:to_s).include?(step_type.to_s)
66
70
  end
@@ -1,3 +1,3 @@
1
1
  module EasyFlow
2
- VERSION = "0.39.0"
2
+ VERSION = "0.41.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), 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 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 — 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 or answer lookups.
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 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 — 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 or answer lookups.
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
  ---
@@ -178,6 +178,28 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
178
178
  ```
179
179
 
180
180
  Here `PlanFlow.for_customer` is the app's own lookup, returning `{ flow: <id>, version: <number> }` or `nil`.
181
+ - `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.
182
+ - 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.
183
+ - Clicking the header opens the step's settings. The header shows none of the warnings a step card shows, and has none of a card's buttons for starting a connection.
184
+ - 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, 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.
185
+ - 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.
186
+ - The type must not declare a setting named `holds`, since a value saved under that name is dropped.
187
+ - 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.
188
+
189
+ ```ruby
190
+ module FlowSteps
191
+ class ForEach
192
+ include EasyFlow::Step
193
+
194
+ step_name "For each"
195
+
196
+ holds_steps
197
+
198
+ setting :list, type: :string
199
+ setting :on_item_failure, type: :select, options: %w[continue stop]
200
+ end
201
+ end
202
+ ```
181
203
  - `displays_by { |node| ... }` or `displays_by { |node, run| ... }` — builds the object handed to the step's partial as the local `step`. Without it the partial receives the node itself. A block that takes two arguments is also given the visitor's stored `EasyFlow::Run`, which is `nil` when the flow keeps no stored run at this point and in an admin's preview, so the block must handle `nil`. The block is also called with a `nil` run once for each step already answered every time a step page is shown, to count progress, so it must not be slow and must not change anything.
182
204
  - `drawn_by "<partial>"` — the partial that draws this type for a visitor. Without it the host's default drawing is used, which draws one answer to pick and expects `step.id`, `step.text` and `step.choices`, each choice answering `value`, `label`, `hint` and `info`, so a type with its own display shape needs its own partial.
183
205
  6. For a type that computes or routes, define instance methods on the class (or `process { |node, state| ... }` / `route { |node, state| ... }` in the block form):
@@ -278,7 +300,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
278
300
  - The page does not reload itself. Ask the developer how the run should move on when what it waits for happens:
279
301
  - The visitor reloads the page, or presses `Check again` in a flow that keeps no stored run. This needs nothing more, and works whether or not the flow keeps a stored run.
280
302
  - The app calls `run.advance` where the event is handled, such as a webhook or a job. See "Read a run and its answers". This needs a stored run, so it only applies to a flow the admin set to save each step.
281
- 9. Restart the server, open a flow on the canvas of each host that should offer the type, and check the type is in the palette, its settings show, and a preview walks through it. On a host that names a list of offered step types without the type's id, check the type is not in the palette. For a type that declares `starts_a_flow`, check the step is marked `Runs a flow`, that once a flow is picked in its settings clicking the step goes to that flow's page, that the `Back to` button on that page returns to the flow the step is in, and that its `Settings` button opens its settings. Also check that the step warns it `is missing a flow` while no flow is picked, `names a version that cannot run` while the version number names no live or replaced version, `leads back to the flow it sits in` while it names the flow it sits in, and that publishing is refused until each is fixed. For a type that declares `chooses_flow`, set the settings the block reads and check that clicking the step goes to the flow the block names, that a type with no `names_by` is named on the canvas by that flow's title and version, and that a run stopping at the step starts a run of that flow on that version. For a type that declares `chooses_flow_from_run`, start a stored run whose owner or answers the block reads, walk it to the step, and check `run.waiting_on` is a run of the flow and version the block names, and that a run for which the block names no flow raises `EasyFlow::InnerFlowError`.
303
+ 9. Restart the server, open a flow on the canvas of each host that should offer the type, and check the type is in the palette, its settings show, and a preview walks through it. On a host that names a list of offered step types without the type's id, check the type is not in the palette. For a type that declares `starts_a_flow`, check the step is marked `Runs a flow`, that once a flow is picked in its settings clicking the step goes to that flow's page, that the `Back to` button on that page returns to the flow the step is in, and that its `Settings` button opens its settings. Also check that the step warns it `is missing a flow` while no flow is picked, `names a version that cannot run` while the version number names no live or replaced version, `leads back to the flow it sits in` while it names the flow it sits in, and that publishing is refused until each is fixed. For a type that declares `chooses_flow`, set the settings the block reads and check that clicking the step goes to the flow the block names, that a type with no `names_by` is named on the canvas by that flow's title and version, and that a run stopping at the step starts a run of that flow on that version. For a type that declares `chooses_flow_from_run`, start a stored run whose owner or answers the block reads, walk it to the step, and check `run.waiting_on` is a run of the flow and version the block names, and that a run for which the block names no flow raises `EasyFlow::InnerFlowError`. For a type that declares `holds_steps`, add a step of the type, check it is drawn as a dashed box with its header line, that clicking the header opens its settings, that dragging a step onto the box puts it in the box and dragging it out takes it out, and that the step's connections are unchanged after each move.
282
304
 
283
305
  ### Take named inputs at a step type of the app's own
284
306
 
@@ -587,6 +609,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
587
609
  - 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.
588
610
  - 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`.
589
611
  - A type that routes declares the values its output takes, or the canvas offers no connections to label.
612
+ - 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.
590
613
  - 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.
591
614
  - A run starts only on a version its own flow has published and not retired or withdrawn, and any other version raises `ActiveRecord::RecordInvalid`.
592
615
  - 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.
@@ -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, and the settings an admin fills in, including picks whose options come from the app's data 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, and the settings an admin fills in, including picks whose options come from the app's data 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
  ---
@@ -18,7 +18,7 @@ Reach for it when an app needs a questionnaire, an intake form, or any decision
18
18
  easy_flow declares no commands of its own for this local. Its surface is split between the other two:
19
19
 
20
20
  - **easy_flow-install** owns putting the engine into an app: its migrations, mounting it, choosing the controller it inherits from, naming hosts and the step types each one offers, choosing the default step drawing, setting the file store that keeps uploaded files, the flow checks, and the admin pages.
21
- - **easy_flow-develop** owns building on it: declaring and registering step types, including ones that read an answer back under a label of their own, ones whose outputs are named by the entries an admin lists in one of their settings, ones that wait, ones whose waiting or routing rule reads the times steps were completed, ones that start another flow, and ones with settings kept on the app's own records, narrowing the answers a host allows a step in a run, moving a run on once what it waits for has happened, serving a host's flows from the app's own controllers and routes, and starting a run on a chosen published version, reading a visitor's run, its answers, the times its steps were completed, the inner run it is waiting on, the time a Wait step is holding it until, the output its flow ended with, whether it ended at an End step, and the step a loop came back to when it stopped the run.
21
+ - **easy_flow-develop** owns building on it: declaring and registering step types, including ones that read an answer back under a label of their own, ones whose outputs are named by the entries an admin lists in one of their settings, ones that wait, ones whose waiting or routing rule reads the times steps were completed, ones that start another flow, ones that hold other steps in a box on the canvas, and ones with settings kept on the app's own records, narrowing the answers a host allows a step in a run, moving a run on once what it waits for has happened, serving a host's flows from the app's own controllers and routes, and starting a run on a chosen published version, reading a visitor's run, its answers, the times its steps were completed, the inner run it is waiting on, the time a Wait step is holding it until, the output its flow ended with, whether it ended at an End step, and the step a loop came back to when it stopped the run.
22
22
 
23
23
  ## How to use it
24
24
 
@@ -36,6 +36,7 @@ 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
40
  - 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.
40
41
  - 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.
41
42
  - If the question is only what a word below means, this page is the answer.
@@ -94,6 +95,8 @@ easy_flow declares no commands of its own for this local. Its surface is split b
94
95
  - **Handing back** — what happens when an inner run ends. Its flow output is recorded in the run that started it, as that run's answer at the Flow step, and a background job then moves that run on along the connection labelled with the output. The inner run's visitor is taken back to the run that started it, whose page moves it on without waiting for the job and shows its next step. An inner run that ended with no output records nothing in the run that started it, and the background job then fails with an error naming the Flow step, so that run does not move on. An inner run that a loop stopped hands nothing back and starts no background job, so the run that started it stays stopped at the Flow step and still names that inner run as the one it is waiting on. An output is handed back only once, so an inner run moved on again after it ended changes nothing. Because the move otherwise happens in a background job, the app must run its jobs for a run nobody is visiting to go past a Flow step.
95
96
  - **Waiting step** — a step whose type carries a rule saying whether what it waits for has happened, such as a payment clearing or a document being signed. A run that reaches it stops there, and the visitor sees "Waiting for" followed by the step's name, with no form to submit. Once the rule says it has happened, the run moves past the step the next time the visitor's page is loaded or the app moves the run on, and the step is recorded as `true`.
96
97
  - **Check again** — a button a visitor sees under the "Waiting for" line in a flow that carries its answers in the page. It loads the step page again with the answers and their completion times, so the run moves past a waiting step whose rule now says it has happened, such as a Wait step whose time has come. A stored run shows no such button, since loading its page again does the same.
98
+ - **Group step** — a step whose type is declared as holding steps, such as an app's own "for each" step. The canvas draws it as a dashed box with a header line at the top and the steps it holds inside. The header line is the step type's code followed by each filled-in setting as `name: value`, or `name value` for a number setting, joined by ` · `. It sits right above the first step the box holds, and the connection from the group step to a step it holds is not drawn. A host that hides step type codes shows the type's name and the settings' labels instead. Clicking the header opens the step's settings, and a connection drawn into a group step ends at the top of its box.
99
+ - **Holding a step** — an admin puts a step in a group step by dragging it onto the group's box, and takes it out by dragging it onto the canvas outside the box. Moving a step in or out changes only which steps the group holds and leaves every connection as it was. The group step lists the ids of the steps it holds under `holds` in the flow's document. Removing a step takes it out of the group that held it, and a step cannot be put in itself or in a step whose type does not hold steps. A run reaching a group step passes straight on along its connection, and the steps it holds run once like any other steps.
97
100
  - **Registry** — the list of step types the app has registered, alongside the built-in ones. A step whose type is not registered is not shown or run as that type, and its answers are not checked.
98
101
  - **Host** — a named part of the app that owns a set of flows. A host sets the visitor layout and the admin layout, how admins are authenticated, how visitors are authorized, how a refusal is answered, and optionally which step types it offers and which answers it allows a step in a run. Flows are always looked up through a host, so one host never sees another's flows.
99
102
  - **Offered step types** — the list of step types a host names for its admins to add. A host that names no list offers every registered step type. The list only narrows the palette.
@@ -102,6 +105,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
102
105
  - **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.
103
106
  - **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.
104
107
  - **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 button with that label and address in its builder header 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 header shows `All flows`.
108
+ - **On publish** — a setting a host may set, `on_publish`, holding a callable that takes a flow. easy_flow calls it each time a new version of one of that host's flows goes live, from the canvas's Publish button or from the app calling publish. Publishing a version that is already live does not call it. With none set, nothing is called.
105
109
  - **Host setting explanations** — a setting a host may set, `setting_explanations`, giving its own explanation for one setting of one step type, including a setting inside a list. It shows in place of the step type's own. A setting it gives none for shows the step type's own, and with none set nothing changes.
106
110
  - **Flow panel** — the panel the `This flow` button opens on the canvas, on every host. It shows Create version and Publish above its lists of problems and changes. Each problem is a sentence naming the step by its name, or by its step type's name when it has none, never by its id, and saying what to do to clear it. Several saves to the same step in a row show as one line in the changes list, named by the step's latest name. A save, a move and any other change each keep their own line, and the history of versions still lists every change a version captured.
107
111
  - **Picture mark** — the words `Has a picture` on the box of a step with a picture on the canvas, on every host.
@@ -63,6 +63,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
63
63
  - `marks_ends` — set to `true` to have this host's admins mark each End step as success or failure. The End step's settings then show a Mark with those two choices, and publishing one of this host's flows with an End left unmarked is refused, the refusal shown on that End's card. With none set, End steps show no mark and publish as they do. Ask the developer whether this host's runs need to say if they ended well.
64
64
  - `publish_note` — a sentence shown directly under the Publish button in this host's flow panel. It is shown as plain text. With none set, the panel shows no note.
65
65
  - `back_link` — a hash with a `label` and an `address`, such as `{ label: "Games", address: "/admin/games" }`, that shows a button with that label and address in this host's builder header in place of `All flows`. The header then has no `All flows` button. A hash missing either key raises `ArgumentError` when the host is declared, and a blank value is not refused. The address is used as written and is not checked, so it comes from the app's own configuration and never from a request. It may instead be a callable that takes the flow being shown and returns that hash, such as `->(flow) { { label: "Funnel", address: "/funnels/#{flow.owner_id}" } }`, so each flow's canvas links to a page of its own, such as its owner record's page. A returned hash missing either key raises `ArgumentError` when that flow's canvas is opened. With none set, the header shows `All flows`.
66
+ - `on_publish` — a callable that takes a flow, such as `->(flow) { RecountJob.perform_later(flow.id) }`, that easy_flow calls each time a new version of one of this host's flows goes live, whether an admin pressed Publish on the canvas or the app called `publish` on the flow. It runs inside the publish request, so slow work belongs in a job it starts. Publishing a version that is already live does not call it. With none set, nothing is called. Ask the developer what the app must do when a flow goes live.
66
67
  - `setting_explanations` — this host's own explanations for step type settings, as a hash of step type name to setting name to a sentence, such as `{ multiple_select: { category: "The round this question counts toward.", "answers.weight" => "Points this answer adds to the score." } }`. A setting inside a list is named by the list and the setting joined with a dot, and a list setting's own explanation is named by the list alone. The sentence is shown as plain text under the setting in the step's settings, in place of the step type's own. A setting with none, or with a blank one, shows the step type's own, if it has one. A step type or setting name that matches nothing is ignored. A value that is not text, such as a nested hash, raises `ArgumentError` when the host is declared. With none set, every setting shows the step type's own explanation.
67
68
 
68
69
  Each method named here must exist on the base controller. Ask the developer to point at it or write it. Do not invent its logic.
@@ -149,8 +150,8 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
149
150
  - After install, check that a Flow step whose chosen flow exists but whose version is not set, does not exist, or was never published or has been retired or withdrawn shows a warning in red that it names a version that cannot run on its canvas card, and that saving a version or publishing is refused until it names a live or superseded version. This check is always on and is not turned on with `EasyFlow.check`.
150
151
  - After install, check that a Flow step whose chosen flow is the flow it sits in, or whose chosen flow leads back to it through the Flow steps of other flows, shows a warning in red that it leads back to the flow it sits in on its canvas card, and that saving a version or publishing is refused until it is fixed. This check is always on and is not turned on with `EasyFlow.check`.
151
152
  - When a stored run reaches a Flow step, the engine starts a run of the chosen flow and records the run it was started from. That record needs the migration that adds a parent run to the runs table, so an app upgrading from a version without it runs `bin/rails easy_flow:install:migrations` and `bin/rails db:migrate` before publishing a flow with a Flow step.
152
- - After publishing a flow with a Flow step, check that when a visitor finishes the chosen flow, the run that holds the Flow step moves on along the connection named after the output that flow ended with. If it stays at the Flow step, check the queue adapter from step 12.
153
- - When a chosen flow ends at an End step with no output filled in, the engine records nothing at the Flow step, and the job queued on `default` fails with `EasyFlow::InnerFlowError` naming the Flow step. The run that holds the Flow step stays at it. Check that the queue adapter from step 12 keeps or reports failed jobs, and that every End step of a flow chosen on a Flow step has an output.
153
+ - After publishing a flow with a Flow step, check that when a visitor finishes the chosen flow, the run that holds the Flow step moves on along the connection named after the output that flow ended with. If it stays at the Flow step, check the queue adapter from step 13.
154
+ - When a chosen flow ends at an End step with no output filled in, the engine records nothing at the Flow step, and the job queued on `default` fails with `EasyFlow::InnerFlowError` naming the Flow step. The run that holds the Flow step stays at it. Check that the queue adapter from step 13 keeps or reports failed jobs, and that every End step of a flow chosen on a Flow step has an output.
154
155
  - When a loop stops a run started by a Flow step, or by a step type of the app's own that starts a flow, the engine records nothing at the step that started it and queues no job. A loop stops a run when it comes back to a step with no answer given since the last visit to that step. The run that holds the starting step stays at it and no error is raised. This holds for a step type of the app's own that chooses the flow from the run as well, so it records no `ended` answer either. Check that every loop in a flow chosen on a Flow step passes a step that waits for the visitor's answer.
155
156
  - When a run reaches a Flow step whose chosen version was retired or withdrawn after the flow was published, the engine raises `EasyFlow::InnerFlowError` naming the Flow step and starts no run. The engine does not turn this error into a refusal, so the visitor gets the app's error page. Check that the app's error reporting captures it.
156
157
  - After install, check that removing a flow from `<mount path>/manage/flows` shows "Flow removed." and takes the flow off the list. Removing a flow deletes its versions and its runs, and needs no setting in the initializer.
@@ -158,6 +159,9 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
158
159
  - 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`.
159
160
  - 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`.
160
161
  - 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.
162
+ - 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.
163
+ - 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.
164
+ - 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.
161
165
  - Every stored run keeps each step's value together with the time the step was completed. An app upgrading from a version that kept values alone runs `bin/rails easy_flow:install:migrations` and `bin/rails db:migrate` before any stored run takes an answer. The migration wraps each value its existing runs already hold, and those values carry no completion time. Running the migration back drops every completion time.
162
166
  - After install, check that a Compare step, a Compare two values step, or a comparison of an All of or Any of step, once its earlier step is picked, offers "Hour completed", "Weekday completed" and "Minutes since 1970 when completed" beside that step's own outputs. They need no setting in the initializer.
163
167
  - After install, check that a Wait step placed on the canvas asks for the earlier step it counts from, minutes after it, a time of day as HH:MM and a date as YYYY-MM-DD. It needs no migration beyond the one that keeps each step's completion time with its value and no setting in the initializer beyond being listed in a host's `offers` when that host sets `offers`.
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.39.0
4
+ version: 0.41.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -82,6 +82,8 @@ files:
82
82
  - app/javascript/easy_flow/canvas/ConnectorLayer.jsx
83
83
  - app/javascript/easy_flow/canvas/Control.jsx
84
84
  - app/javascript/easy_flow/canvas/Explanation.jsx
85
+ - app/javascript/easy_flow/canvas/GroupBox.jsx
86
+ - app/javascript/easy_flow/canvas/GroupHeader.jsx
85
87
  - app/javascript/easy_flow/canvas/Inspector.jsx
86
88
  - app/javascript/easy_flow/canvas/Panel.jsx
87
89
  - app/javascript/easy_flow/canvas/Placeholder.jsx
@@ -94,6 +96,7 @@ files:
94
96
  - app/javascript/easy_flow/canvas/choices.js
95
97
  - app/javascript/easy_flow/canvas/flow.js
96
98
  - app/javascript/easy_flow/canvas/flowSender.js
99
+ - app/javascript/easy_flow/canvas/group.js
97
100
  - app/javascript/easy_flow/canvas/ids.js
98
101
  - app/javascript/easy_flow/canvas/rows.js
99
102
  - app/javascript/easy_flow/canvas/styles.js