easy_flow 0.42.0 → 0.44.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: 2d36455573d90407cd82e50cbd207343db83e038c573c6feb905b92f71a93889
4
- data.tar.gz: d633b6fa18c7eac6f583d853850222237c47d069555e22a2e1687dd5d0b8926f
3
+ metadata.gz: 064f8dfb5ca6d7730825965a3626d67305d3587076b4fb17f588fceab3d9bd19
4
+ data.tar.gz: a5e3f50c22bfd721eae1f6ed3d244f5f82f7d0c71ef7215250c66342da58bccc
5
5
  SHA512:
6
- metadata.gz: b29d4f237c0dffd18999a58db1fa3a5594f58e2262f99c085b28cb58659ef3ef3f30b3855ac13d00fa1df643fa37c56ded5228ecf49e279f386e2996b2aaacb9
7
- data.tar.gz: 1df6e3ca7b4c8ecc0a85afdc8464c46c3219a7a2440264949e03d489086a8bb5c686d6787d8e024a8415322d2b1f7eff205f96b16844ec3cb5aafb5c94356bde
6
+ metadata.gz: afb0b6791154182b1b08a1089e9c06bd79f3a75c3d47c52e03032e41fefcde84e6e690f0bbd7776302309c67591ed7c0aa3a098c4da941695d5bec66d506f3ce
7
+ data.tar.gz: e77630969b101a2a9b566e6d379becd8f7c1059ee63e0f70b6e9be581317b48fe29b724488dd54a823d28fda38f4167911d6aadc36b5bd5c4adfe736e227e7b6
@@ -1 +1 @@
1
- (()=>{var ge=globalThis.ReactDOM;var{createPortal:Do,createRoot:at,flushSync:Oo,hydrateRoot:Ao,preconnect:Po,prefetchDNS:$o,preinit:Lo,preinitModule:Io,preload:Mo,preloadModule:Ho,requestFormReset:jo,unstable_batchedUpdates:Wo,useFormState:Fo,useFormStatus:Vo,version:Yo}=ge;var it=globalThis.React,o=it,{Children:Xo,Component:Go,Fragment:Jo,PureComponent:qo,StrictMode:Ko,Suspense:Zo,cloneElement:Qo,createContext:Ro,createElement:tr,createRef:er,forwardRef:or,isValidElement:rr,lazy:nr,memo:sr,startTransition:ar,useCallback:ir,useContext:lr,useDebugValue:dr,useDeferredValue:cr,useEffect:$,useId:pr,useImperativeHandle:ur,useLayoutEffect:lt,useMemo:L,useReducer:mr,useRef:K,useState:S,useSyncExternalStore:fr,useTransition:gr}=it;var dt=new Map,F=new Map,ct=(t,e)=>dt.set(t,e),pt=()=>{F.forEach(t=>t.unmount()),F.clear()},ut=(t,e)=>t.querySelectorAll("[data-react-ui]").forEach(n=>{if(F.has(n))return;let r=dt.get(n.dataset.reactUi),a=e(n);F.set(n,a),a.render(o.createElement(r,JSON.parse(n.dataset.props)))});var mt=(t,e)=>{let n=()=>ut(t,e);t.addEventListener("turbo:load",n),t.addEventListener("turbo:frame-load",n),t.addEventListener("turbo:before-cache",pt),t.readyState==="loading"?t.addEventListener("DOMContentLoaded",n):n()};var T=(...t)=>t.filter(Boolean).join(" ");var he={primary:"ks-button-primary",secondary:"ks-button-secondary",danger:"ks-button-danger"},ye={sm:"ks-button-sm",md:"ks-button-md",lg:"ks-button-lg"},xe=({variant:t="primary",size:e="md",className:n,children:r,...a})=>{let l=a.href?"a":"button";return o.createElement(l,{...a,className:T("ks-button",he[t],ye[e],n)},r)},w=xe;var be="border border-amber-500 bg-white text-amber-700 dark:bg-zinc-900 dark:text-amber-400",ve="border border-gray-300 bg-white text-gray-500 dark:border-zinc-600 dark:bg-zinc-900 dark:text-gray-400",we="border border-accent-600 bg-accent-600 text-white",ke=({name:t,connected:e,armed:n,onArm:r,connecting:a})=>o.createElement("button",{onClick:l=>{a||(l.stopPropagation(),r(l))},title:n?"Now choose a step to connect to":"Connect this branch",className:n?we:e?ve:be,style:{padding:"1px 8px",marginRight:4,borderRadius:999,fontSize:11,cursor:"pointer"}},t||"next"),ft=ke;var Ce={width:240,boxSizing:"border-box",borderRadius:8},Se={minWidth:120,boxSizing:"border-box",borderRadius:6},Ne={padding:"8px 14px",textAlign:"center",fontWeight:600},ze={fontWeight:600,lineHeight:1.3},Be={fontSize:12,fontWeight:500,lineHeight:1.3},_e=(t,e,n)=>{let r=n?"ring-4 ring-accent-600/15":"shadow-sm";return t||n&&!e?`border-accent-600 ${r}`:e?`border-red-600 ${r}`:"border-gray-300 shadow-sm dark:border-zinc-700"},Te=(t,e)=>e&&t.label===t.id&&t.type_name||t.label,Ee=(t,e,n)=>n?e===t.type_name?null:t.type_name:t.type,De=({node:t,selected:e,armed:n,connecting:r,onSelect:a,onOpen:l,onArm:u,onDragEnd:i,onDragStart:p,hideStepTypeCodes:y,branches:b=[],compact:m=!1})=>{let f=t.begins_here||t.ends_here,g=t.begins_here,c=t.ends_here?[]:t.ports,k=r&&!g,v=Te(t,y),C=Ee(t,v,y);return o.createElement("div",{ref:t.ref,"data-step":t.id,draggable:!g,onDragStart:x=>{x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("text/plain",t.id),p()},onDragEnd:i,onClick:t.opens&&!r?()=>l(t.opens):a,className:`bg-white ${m&&!e?"border":"border-2"} dark:bg-zinc-900 ${_e(k,t.violations.length>0,e)}`,style:{...m?Se:Ce,padding:f?0:m?"8px 10px":"12px 14px",cursor:g?"default":r?"crosshair":"grab"}},!f&&m&&C&&o.createElement("div",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},C),f&&o.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:Ne},v),!f&&o.createElement("div",{style:m?Be:ze},v),!f&&!m&&C&&o.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginTop:2}},C),t.picture_url&&o.createElement("div",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:11,marginTop:2}},"Has a picture"),t.starts_a_flow&&o.createElement("div",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:11,marginTop:2}},"Runs a flow"),t.opens&&o.createElement(w,{variant:"secondary",size:"sm",className:"mt-2",onClick:x=>{x.stopPropagation(),a()}},"Settings"),b.map(x=>o.createElement("div",{key:x,className:"text-gray-500 dark:text-gray-400",style:{fontSize:10}},x)),t.violations.map(x=>o.createElement("div",{key:x.problem+x.detail,className:"text-red-600 dark:text-red-400",style:{fontSize:11,padding:"0 14px 6px"}},x.sentence)),c.length>0&&o.createElement("div",{style:{padding:t.begins_here?"0 14px 8px":"10px 0 0"}},c.map(x=>o.createElement(ft,{key:x,name:x,connected:t.connected.includes(x),connecting:r,armed:n===x,onArm:N=>u(x,N)}))))},Z=De;var gt={position:"relative",zIndex:2,width:240,fontSize:11,whiteSpace:"nowrap",cursor:"pointer"},Oe={...gt,width:"auto",whiteSpace:"normal",overflowWrap:"anywhere"},Ae=({node:t,header:e,onSelect:n,compact:r=!1})=>o.createElement("div",{ref:t.ref,"data-group-header":t.id,onClick:n,className:"font-mono text-gray-500 dark:text-gray-400",style:r?Oe:gt},e),ht=Ae;var Pe=({id:t,bounds:e,onDrop:n})=>o.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",...e}}),yt=Pe;var $e=t=>t!=null&&t!==""&&typeof t!="object",Le=["integer","float"],Ie=(t,e,n)=>n&&e.labels?.[t]||t,xt=(t,e,n)=>{let r=Object.keys(e?.fields||{}).filter(a=>$e(t.config[a])).map(a=>`${Ie(a,e,n)}${Le.includes(e.fields[a])?"":":"} ${t.config[a]}`);return[n&&t.type_name||t.type,...r].join(" \xB7 ")};var bt=(t,e,n)=>{let r=Math.min(...t.map(i=>i.left))-e.left+n.scrollLeft-12,a=Math.min(...t.map(i=>i.top))-e.top+n.scrollTop-10,l=Math.max(...t.map(i=>i.left+i.width))-e.left+n.scrollLeft+12,u=Math.max(...t.map(i=>i.top+i.height))-e.top+n.scrollTop+10;return{left:r,top:a,width:l-r,height:u-a}},Me=({left:t,top:e,width:n,height:r},a)=>a.x>=t&&a.x<=t+n&&a.y>=e&&a.y<=e+r,vt=(t,e)=>t.find(n=>Me(n.bounds,e))?.id||null,wt=(t,e)=>t.filter(n=>!e.some(r=>r.id===n.source&&r.holds?.includes(n.target))),kt=(t,e)=>e.some(n=>n.holds?.includes(t.id)&&!n.loose&&n.row===t.row-1);var Q=(t,e)=>t.includes(e)?t.filter(n=>n!==e):[...t,e],Ct=(t,e)=>({...e?.choices||{},...t?.choices||{}});var He=({as:t="input",disabled:e,className:n,...r})=>o.createElement(t,{...r,disabled:e,className:T("ks-input",e&&"ks-input-disabled",n)}),A=He;var je=t=>o.createElement(A,{...t,as:"select"}),St=je;var We=({className:t,...e})=>o.createElement("input",{type:"checkbox",...e,className:T("ks-checkbox",t)}),V=We;var Nt=t=>(t||[]).map(e=>typeof e=="object"?e:{value:e,label:e}),Fe=({type:t,value:e,choices:n,onChange:r,onSettle:a,onPick:l,pictureUrl:u})=>{if(t==="picture")return o.createElement("div",{className:"mb-3"},e&&u&&o.createElement("img",{src:u,alt:"The step's picture",style:{maxWidth:"100%"}}),e&&o.createElement("button",{type:"button","data-remove-picture":!0,className:"ks-button ks-button-secondary ks-button-sm",onClick:()=>a("")},"Remove picture"),o.createElement("input",{type:"file",accept:"image/*",onChange:i=>i.target.files[0]&&l(i.target.files[0])}));if(t==="boolean")return o.createElement(V,{checked:!!e,onChange:i=>a(i.target.checked)});if(t==="select"||t==="previous_step"||t==="from_step"||t==="flow")return o.createElement(St,{className:"mb-3",value:e??"",onChange:i=>a(i.target.value)},o.createElement("option",{value:""}),Nt(n).map(i=>o.createElement("option",{key:i.value,value:i.value},i.label)));if(t==="multi_select"){let i=Array.isArray(e)?e:[],p=y=>a(Q(i,y));return o.createElement("div",{style:{display:"flex",flexWrap:"wrap",gap:8}},(n||[]).map(y=>o.createElement("label",{key:y,style:{display:"inline-flex",alignItems:"center",gap:4}},o.createElement(V,{checked:i.includes(y),onChange:()=>p(y)}),o.createElement("span",null,y))))}if(t==="flows"){let i=Array.isArray(e)?e:[];return o.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4},className:"mb-3"},Nt(n).map(p=>o.createElement("label",{key:p.value,style:{display:"inline-flex",alignItems:"center",gap:4}},o.createElement(V,{checked:i.includes(p.value),onChange:()=>a(Q(i,p.value))}),o.createElement("span",null,p.label))))}return t==="integer"||t==="float"?o.createElement(A,{className:"mb-3",type:"number",step:t==="integer"?"1":"any",value:e??"",onChange:i=>r(i.target.value),onBlur:i=>a(i.target.value)}):o.createElement(A,{className:"mb-3",type:"text",value:e??"",onChange:i=>r(i.target.value),onBlur:i=>a(i.target.value)})},Y=Fe;var zt=(t,e,n,r)=>t.map((a,l)=>l===e?{...a,[n]:r}:a);var Ve=({text:t})=>o.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),U=Ve;var Ye=(t,e,n,r)=>{let a=(t||{})[n],l=(e||{})[n];return l?(a||{})[r[l]]:a},Ue=({holds:t,labels:e,explanations:n,rows:r,choices:a,outputsOf:l,onChange:u,onSettle:i})=>{let p=Array.isArray(r)?r:[],y=(b,m,f,g)=>{let c=zt(p,b,m,f);g?i(c):u(c)};return o.createElement("div",{style:{marginBottom:12}},p.map((b,m)=>o.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(([f,g])=>o.createElement("label",{key:f,style:{display:"block"}},o.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{display:"block",marginBottom:2,fontSize:11}},(e||{})[f]||f),o.createElement(Y,{type:g,value:b[f],choices:Ye(a,l,f,b),onChange:c=>y(m,f,c,!1),onSettle:c=>y(m,f,c,!0)}),(n||{})[f]&&o.createElement(U,{text:n[f]}))),o.createElement(w,{variant:"secondary",size:"sm",className:"mb-1.5",onClick:()=>i(p.filter((f,g)=>g!==m))},"Remove"))),o.createElement(w,{variant:"secondary",size:"sm",className:"w-full",onClick:()=>i([...p,{}])},"Add"))},Bt=Ue;var Xe=({as:t="div",className:e,children:n,...r})=>o.createElement(t,{...r,className:T("ks-panel",e)},n),I=Xe;var X=(t,e)=>({className:n,children:r,...a})=>o.createElement(t,{...a,className:T(e,n)},r),W=X("label","ks-label"),hn=X("p","ks-hint"),yn=X("p","ks-error"),xn=X("span","ks-required");var Ge={width:280,padding:20,overflowY:"auto"},Je=({node:t,fields:e,holds:n,labels:r,explanations:a,recordLabels:l,recordExplanations:u,recordChoices:i,recordOutputsOf:p,choices:y,onSave:b,onDelete:m,onClose:f,onPickPicture:g,refusal:c})=>{let[k,v]=S(t.config),[C,x]=S(t.picture_url);$(()=>x(t.picture_url),[t.id,t.picture_url]),$(()=>v(t.config),[t.id,t.config]);let N=h=>{v(h),JSON.stringify(h)!==JSON.stringify(t.config)&&b(h)};return o.createElement(I,{as:"aside",style:Ge,"data-inspector":!0},o.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8}},o.createElement("h2",{style:{fontWeight:600,marginBottom:2}},t.label),o.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")),o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginBottom:16}},t.id," \xB7 ",t.type),c&&o.createElement("p",{className:"text-red-800 dark:text-red-400",style:{fontWeight:600,marginBottom:12},"data-refusal":!0},c),Object.entries(e).map(([h,z])=>o.createElement(W,{key:h},o.createElement("span",{style:{display:"block",marginBottom:3}},r[h]||h),z==="list"?o.createElement(Bt,{holds:n[h]||{},labels:l[h]||{},explanations:(u||{})[h],rows:k[h],choices:{...(i||{})[h],...(t.record_choices||{})[h]},outputsOf:(p||{})[h],onChange:_=>v({...k,[h]:_}),onSettle:_=>N({...k,[h]:_})}):o.createElement(Y,{type:z,value:k[h],choices:y[h],pictureUrl:C,onChange:_=>v({...k,[h]:_}),onSettle:_=>N({...k,[h]:_}),onPick:async _=>{let M=await g(_);M&&(x(M.url),N({...k,[h]:M.reference}))}}),(a||{})[h]&&o.createElement(U,{text:a[h]}))),o.createElement(w,{variant:"danger",size:"sm",className:"w-full",onClick:m},"Delete step"))},_t=Je;var qe={width:240,boxSizing:"border-box",padding:"10px 14px",borderRadius:8,textAlign:"center",fontSize:12,cursor:"pointer"},Ke={minWidth:120,boxSizing:"border-box",padding:"8px 10px",borderRadius:6,textAlign:"center",fontSize:12,cursor:"pointer"},Ze="border-2 border-dashed border-amber-500 bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300",Qe="border-2 border-dashed border-accent-600 bg-accent-50 text-accent-800 dark:bg-accent-950 dark:text-accent-200",Re=({node:t,dragging:e,onFill:n,onDrop:r,compact:a=!1})=>o.createElement("div",{ref:t.ref,"data-placeholder":t.id,title:`Choose the step \u201C${t.label}\u201D should lead to`,onClick:n,onDragOver:l=>{e&&(l.preventDefault(),l.dataTransfer.dropEffect="move")},onDrop:l=>{l.preventDefault(),r()},className:e?Qe:Ze,style:a?Ke:qe},o.createElement("div",{style:{fontWeight:600}},t.label),o.createElement("div",{style:{fontSize:11}},e?"drop a step here":"leads nowhere yet \u2014 click to choose")),Tt=Re;var to=({entries:t,at:e,onPick:n,onConnect:r,onDismiss:a,hideStepTypeCodes:l})=>o.createElement(I,{className:"shadow-lg",style:{position:"absolute",zIndex:9,top:e.y,left:e.x,width:210,padding:8,borderRadius:8}},o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{margin:"0 0 6px",fontSize:11}},"Add a step"),t.map(u=>o.createElement(w,{key:u.type,variant:"secondary",size:"sm",className:"w-full mb-1.5 flex-col",onClick:()=>n(u)},u.label,!l&&o.createElement("span",{className:"opacity-75",style:{display:"block",fontSize:11}},u.type))),r&&o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:r},"Connect to a step already here"),o.createElement(w,{variant:"secondary",size:"sm",className:"w-full",onClick:a},"Cancel")),Et=to;var eo={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},Dt=({label:t,title:e,idle:n,enabled:r,onUse:a})=>o.createElement(w,{variant:"secondary",size:"sm",title:r?e:n,disabled:!r,onClick:a,style:{opacity:r?1:.4,cursor:r?"pointer":"default"}},t),oo=({undoable:t,redoable:e,onAdd:n,onUndo:r,onRedo:a})=>o.createElement("div",{style:{position:"absolute",top:16,left:16,zIndex:5,display:"flex",gap:8}},o.createElement(w,{variant:"secondary",className:"rounded-full",style:eo,title:"Add a step",onClick:n},"+"),o.createElement(Dt,{label:"\u21B6 Undo",title:"Undo the last change",idle:"Nothing to undo",enabled:t,onUse:r}),o.createElement(Dt,{label:"\u21B7 Redo",title:"Redo the change you undid",idle:"Nothing to redo",enabled:e,onUse:a})),Ot=oo;var ro=({type:t="info",title:e,message:n,onDismiss:r,className:a})=>o.createElement("div",{className:T("ks-alert",`ks-alert-${t}`,a),role:"alert"},o.createElement("div",{className:"ks-alert-body"},o.createElement("div",{className:"ks-alert-content"},e&&o.createElement("p",{className:"ks-alert-title"},e),o.createElement("p",{className:e?"ks-alert-message-titled":"ks-alert-message"},n)),r&&o.createElement("button",{type:"button",className:"ks-alert-dismiss","aria-label":"Dismiss",onClick:r},"\xD7"))),At=ro;var Pt=t=>{let e=t.map(n=>`\u201C${n.name}\u201D`).join(", ");return t.length===1?`${e} is not connected to the flow and will be removed. Remove it to go on, or cancel and connect it first.`:`${e} are not connected to the flow and will be removed. Remove them to go on, or cancel and connect them first.`};var $t=({version:t,published:e})=>t?e?e===t?`Version ${t} \xB7 live`:`Version ${t} \xB7 visitors still on ${e}`:`Version ${t} \xB7 never published`:"No version yet";var no={width:280,padding:20,overflowY:"auto"},R={fontWeight:600,marginBottom:6,marginTop:14},G={fontSize:12,marginBottom:4,lineHeight:1.4},Lt={display:"block",marginBottom:3},It=(t,e,n)=>r=>{r.target.value!==(t[e]??"")&&n({[e]:r.target.value})},so=({flow:t,changes:e,problems:n,refusal:r,notice:a,publishNote:l,warning:u,onCreate:i,onPublish:p,onAccept:y,onDecline:b,onSaveDetails:m,onClose:f})=>o.createElement(I,{as:"aside",style:no,"data-builder-panel":!0},o.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8}},o.createElement("h2",{style:{fontWeight:600},"data-flow-name":!0},t.title||t.slug),o.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")),o.createElement("a",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:12,display:"block"},href:t.history_url,"data-history":!0},$t(t)),u?o.createElement("div",{style:{marginTop:14},"data-unconnected-warning":!0},o.createElement(At,{type:"warning",className:"mb-1.5",message:Pt(u.steps)}),o.createElement(w,{size:"sm",className:"w-full mb-1.5",onClick:y,"data-accept-removal":!0},u.path==="/publish"?"Remove and publish":"Remove and create version"),o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:b,"data-decline-removal":!0},"Cancel")):o.createElement("div",{style:{marginTop:14}},o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:i,"data-create-version":!0},"Create version"),o.createElement(w,{size:"sm",className:"w-full mb-1.5",onClick:p,"data-publish":!0},"Publish"),l&&o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12,lineHeight:1.4},"data-publish-note":!0},l)),o.createElement("h2",{style:R},"Problems"),r&&o.createElement("p",{className:"text-red-800 dark:text-red-400",style:{...G,fontWeight:600},"data-refusal":!0},r),a&&!r&&o.createElement("p",{className:"text-emerald-800 dark:text-emerald-400",style:{...G,fontWeight:600},"data-notice":!0},a),n.length===0&&!r?o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12}},"Nothing wrong with this flow."):n.map(g=>o.createElement("p",{key:`${g.node}-${g.problem}`,className:"text-amber-700 dark:text-amber-400",style:G,"data-problem":!0},"\u26A0 ",g.sentence)),o.createElement("h2",{style:R},"Changes since the last version"),e.length===0?o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12}},"Nothing has changed."):e.map((g,c)=>o.createElement("p",{key:c,style:G,"data-change":!0},g)),o.createElement("h2",{style:R},"Details"),o.createElement(W,null,o.createElement("span",{style:Lt},"Title"),o.createElement(A,{className:"mb-3",defaultValue:t.title??"",onBlur:It(t,"title",m),"data-flow-title":!0})),o.createElement(W,null,o.createElement("span",{style:Lt},"Start label"),o.createElement(A,{className:"mb-3",defaultValue:t.start_label??"",onBlur:It(t,"start_label",m),"data-flow-start-label":!0})),o.createElement("div",{style:{marginTop:16}},o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.definition_url,"data-definition":!0},"Definition"),o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.details_url,"data-details":!0},"Edit details"))),Mt=so;var Ht={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},jt=t=>({opacity:t?1:0,transition:"opacity .12s"}),ao=({link:t,onInsert:e,onRemove:n,onDrop:r,dragging:a,alwaysShowInsertButtons:l})=>{let[u,i]=S(!1),p=u||a;return o.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()}},o.createElement("div",{style:{display:"flex",gap:4,justifyContent:"center",alignItems:"center",height:"100%"}},o.createElement(w,{variant:"secondary",title:a?"Move the step here":"Insert a step here",onClick:e,className:"rounded-full data-[over=true]:ring-2 data-[over=true]:ring-accent-600","data-over":!!(a&&u),style:{...Ht,...jt(p||l)}},"+"),!a&&o.createElement(w,{variant:"danger",title:"Remove this connection",onClick:n,className:"rounded-full",style:{...Ht,...jt(p)}},"\xD7")))},Wt=ao;var io=({links:t,extent:e,dragging:n,onInsert:r,onRemove:a,onDrop:l,alwaysShowInsertButtons:u})=>o.createElement(o.Fragment,null,o.createElement("svg",{width:e.width,height:e.height,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:1}},o.createElement("defs",null,o.createElement("marker",{id:"easy_flow-arrow",viewBox:"0 0 10 10",refX:"8",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto"},o.createElement("path",{d:"M 0 0 L 10 5 L 0 10 z",className:"fill-gray-400 dark:fill-zinc-500"}))),t.map(i=>o.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=>o.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=>o.createElement(Wt,{key:i.id,link:i,dragging:!!n,alwaysShowInsertButtons:u,onInsert:()=>r(i),onRemove:()=>a(i),onDrop:()=>l(i)}))),Ft=io;var Vt={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},Yt="opacity-0 transition-opacity group-data-[over=true]:opacity-100",lo=({link:t,onInsert:e,onRemove:n,onDrop:r,alwaysShowInsertButtons:a})=>o.createElement("div",{"data-joint":t?.id,className:"group relative h-7 w-full sm:h-auto sm:w-7 sm:self-stretch",onMouseEnter:l=>{l.currentTarget.dataset.over="true"},onMouseLeave:l=>{delete l.currentTarget.dataset.over},onDragOver:l=>{t&&(l.preventDefault(),l.dataTransfer.dropEffect="move")},onDrop:l=>{t&&(l.preventDefault(),r(t))}},t&&o.createElement("div",{className:"absolute left-1/2 top-0 h-full w-px bg-gray-400 sm:left-0 sm:top-1/2 sm:h-px sm:w-full dark:bg-zinc-500"}),t&&o.createElement("div",{className:"absolute inset-0 flex items-center justify-center gap-1 sm:flex-col",style:{zIndex:4}},o.createElement(w,{variant:"secondary",title:"Insert a step here",onClick:l=>e(t,l),className:`rounded-full ${a?"opacity-100":Yt}`,style:Vt},"+"),o.createElement(w,{variant:"danger",title:"Remove this connection",onClick:()=>n(t),className:`rounded-full ${Yt}`,style:Vt},"\xD7"))),Ut=lo;var co=(t,e)=>t.row-e.row||t.column-e.column,Xt=t=>{let e=[...t].sort(co),n=e.filter(r=>t.some(a=>a.holds?.includes(r.id)));return e.filter(r=>!n.includes(r)).flatMap(r=>[r,...n.filter(a=>r.holds?.includes(a.id))])},Gt=t=>{let e=Xt(t),n=r=>e.some(a=>a.holds?.includes(r.id));return e.filter(r=>!n(r)).reduce((r,a)=>{if(a.holds)return[...r,{group:a,steps:e.filter(u=>a.holds.includes(u.id))}];let l=r[r.length-1];return l&&!l.group?[...r.slice(0,-1),{steps:[...l.steps,a]}]:[...r,{steps:[a]}]},[])},po=(t,e)=>t[t.findIndex(n=>n.id===e.id)+1]?.id,Jt=(t,e,n)=>{let r=po(Xt(n),t);return e.filter(a=>a.source===t.id&&(a.label||a.target!==r))},uo=t=>t?.placeholder?"nowhere yet":t?.label,qt=(t,e)=>[t.label,"\u2192",uo(e.find(n=>n.id===t.target))].filter(Boolean).join(" "),Kt=(t,e,n)=>t.find(r=>r.source===e.id&&r.target===n.id);var mo={display:"flex",flexDirection:"column",gap:14,padding:"64px 24px 24px"},Zt=({steps:t,edges:e,draw:n,joints:r})=>o.createElement("div",{"data-flow-row":!0,className:"flex flex-col sm:flex-row sm:flex-wrap sm:items-center sm:gap-y-3.5"},t.map((a,l)=>o.createElement("div",{key:a.id,className:"flex flex-col sm:flex-row sm:items-center"},l>0&&o.createElement(Ut,{link:Kt(e,t[l-1],a),...r}),n(a)))),fo={display:"flex",flexDirection:"column",gap:8,padding:"10px 12px",borderRadius:8},go=({group:t,steps:e,edges:n,draw:r,joints:a})=>o.createElement("div",{"data-group-box":t.id,className:"border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60",style:fo},r(t),o.createElement(Zt,{steps:e,edges:n,draw:r,joints:a})),ho=({nodes:t,edges:e,draw:n,joints:r,children:a})=>o.createElement("div",{"data-flow-rows":!0,style:mo},a,Gt(t).map(l=>l.group?o.createElement(go,{key:l.group.id,group:l.group,steps:l.steps,edges:e,draw:n,joints:r}):o.createElement(Zt,{key:l.steps[0].id,steps:l.steps,edges:e,draw:n,joints:r}))),Qt=ho;var Rt="Your change was not saved because the server could not be reached.",te=({base:t,token:e,fetch:n,onFlow:r,onError:a,onNotice:l,onWarning:u=()=>{}})=>async(i,p,y)=>{let b=await n(t+i,{method:p,headers:{"Content-Type":"application/json","X-CSRF-Token":e},body:y&&JSON.stringify(y)}).catch(()=>null);if(!b)return l(null),a(Rt);let m=await b.json().catch(()=>({}));if(m.unconnected)return l(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 l(null),a(m.error||"That change was refused");a(null),l(m.notice||null),r(await(await n(t+".json",{headers:{Accept:"application/json"}})).json())},ee=({base:t,token:e,fetch:n,onError:r})=>async a=>{let l=new FormData;l.append("picture",a);let u=await n(t+"/pictures",{method:"POST",headers:{"X-CSRF-Token":e},body:l}).catch(()=>null);if(!u)return r(Rt),null;let i=await u.json().catch(()=>({}));return u.ok?(r(null),i):(r(i.error||"That picture was refused"),null)};var yo=(t,e,n)=>{let[r,a]=S(n),[l,u]=S(null),[i,p]=S(null),[y,b]=S(null),m=L(()=>te({base:t,token:e,fetch:(...g)=>window.fetch(...g),onFlow:a,onError:u,onNotice:p,onWarning:b}),[t,e]),f=L(()=>ee({base:t,token:e,fetch:(...g)=>window.fetch(...g),onError:u}),[t,e]);return{flow:r,error:l,notice:i,warning:y,setWarning:b,send:m,pickPicture:f}},oe=yo;var J=(t,e,n,r)=>{let a=t.left-n.left+r.scrollLeft,l=t.top-n.top+r.scrollTop;return e==="left"?{x:a,y:l+t.height/2}:e==="right"?{x:a+t.width,y:l+t.height/2}:e==="top"?{x:a+t.width/2,y:l}:{x:a+t.width/2,y:l+t.height}},xo=(t,e,n)=>n&&e==="top"?{x:t.x,y:n.top}:t,bo=(t,e)=>e==="top"?{x:t.x,y:t.y-3}:e==="left"?{x:t.x-3,y:t.y}:e==="right"?{x:t.x+3,y:t.y}:{x:t.x,y:t.y+3},vo=(t,e,n,r,a)=>{let l={straight:`M ${e.x} ${e.y} L ${n.x} ${n.y}`,turn:`M ${e.x} ${e.y} H ${n.x} V ${n.y}`,lane:`M ${e.x} ${e.y} V ${r} H ${n.x} V ${n.y}`,detour:`M ${e.x} ${e.y} H ${a} V ${n.y} H ${n.x}`}[t.route];return{...t,path:l,midX:t.route==="detour"?a:(e.x+n.x)/2,midY:t.route==="lane"?r:(e.y+n.y)/2}},wo=(t,e,n,r)=>{let[a,l]=S([]),[u,i]=S({width:"100%",height:"100%"}),[p,y]=S([]);return lt(()=>{let b=()=>{let f=e.current?.getBoundingClientRect();if(!f)return;i({width:e.current.scrollWidth,height:e.current.scrollHeight});let g=t.nodes.filter(c=>c.holds&&!c.loose&&n.current[c.id]).map(c=>{let k=n.current[c.id],v=k.getBoundingClientRect(),C=c.holds.flatMap(N=>n.current[N]?[n.current[N].getBoundingClientRect()]:[]),x=[{left:v.left,top:v.top,width:Math.max(v.width,k.scrollWidth),height:v.height},...C];return{id:c.id,bounds:bt(x,f,e.current)}});y(g),l(t.edges.flatMap(c=>{let k=n.current[c.source]?.getBoundingClientRect(),v=n.current[c.target]?.getBoundingClientRect();if(!k||!v)return[];let C=J(k,c.leaves,f,e.current),x=g.find(_=>_.id===c.target)?.bounds,N=bo(xo(J(v,c.enters,f,e.current),c.enters,x),c.enters),h=(J(k,"bottom",f,e.current).y+J(v,"top",f,e.current).y)/2,z=c.leaves==="left"?Math.min(C.x,N.x)-28:Math.max(C.x,N.x)+28;return[vo(c,C,N,h,z)]}))};b(),window.addEventListener("resize",b);let m=new ResizeObserver(b);return e.current&&m.observe(e.current),()=>{window.removeEventListener("resize",b),m.disconnect()}},r),{links:a,extent:u,boxes:p}},re=wo;var ne=(t,e)=>{let n=new Set(e),r=t,a=2;for(;n.has(r);)r=`${t}_${a++}`;return r};var Co=8,So={display:"flex",height:"100%",minHeight:0,fontSize:13},No={flex:1,overflow:"auto",position:"relative"},ae={position:"absolute",top:56,left:16,zIndex:5,width:264,padding:12,borderRadius:8},zo={...ae,position:"static",alignSelf:"flex-start"},Bo={display:"grid",rowGap:64,columnGap:0,padding:40,justifyContent:"center",position:"relative"},_o={position:"sticky",zIndex:8,top:8,margin:"8px auto 0",width:"fit-content",padding:"6px 12px",borderRadius:6,fontSize:12},To=({port:t,onCancel:e})=>o.createElement("div",{className:"bg-accent-100 text-accent-800 dark:bg-accent-900 dark:text-accent-100",style:_o},"Choose the step \u201C",t||"next","\u201D should lead to \u2014 ",o.createElement("button",{onClick:e,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:e,initial:n})=>{let{flow:r,error:a,notice:l,warning:u,setWarning:i,send:p,pickPicture:y}=oe(t,e,n),[b,m]=S(null),[f,g]=S(null),[c,k]=S(null),[v,C]=S(null),[x,N]=S(!1),h=K({}),z=K(null);$(()=>{let s=()=>{m(null),N(!0)};return document.addEventListener("easy_flow:open-flow",s),()=>document.removeEventListener("easy_flow:open-flow",s)},[]),$(()=>{if(!x){i(null);return}let s=d=>{d.target.isConnected&&!d.target.closest("[data-builder-panel], [data-open-panel]")&&N(!1)};return document.addEventListener("click",s),()=>document.removeEventListener("click",s)},[x]),$(()=>{document.dispatchEvent(new CustomEvent("easy_flow:flow-named",{detail:r.flow?.title||r.flow?.slug}))},[r.flow?.title,r.flow?.slug]);let _=L(()=>Object.fromEntries(r.nodes.map(s=>[s.id,s])),[r.nodes]),{links:M,extent:le,boxes:tt}=re(r,z,h,[r,b,_]),et=L(()=>{let s={};return r.violations.forEach(d=>{var B;return(s[B=d.node]||(s[B]=[])).push(d)}),s},[r.violations]),E=r.direction==="left_to_right",H=r.nodes.filter(s=>!s.loose),ot=r.nodes.filter(s=>s.loose),de=Math.max(0,...H.map(s=>s.row))+1,ce=Math.max(0,...H.map(s=>s.column))+1,q=s=>{if(!c)return;let[d,B]=c;k(null),d!==s&&p("/edges","POST",{from:d,to:s,on:B||null})},pe=s=>{if(s.isDefaultPrevented()||!v)return;s.preventDefault();let d=v;C(null);let B=z.current.getBoundingClientRect(),j=vt(tt,{x:s.clientX-B.left+z.current.scrollLeft,y:s.clientY-B.top+z.current.scrollTop}),me=r.nodes.find(fe=>fe.holds?.includes(d))?.id||null;j!==me&&p(`/steps/${d}/group`,"PATCH",{group:j})},rt=s=>[...r.palette,...r.unoffered||[]].find(d=>d.type===s?.type),P=r.nodes.find(s=>s.id===b),D=rt(P),ue=s=>{let d=z.current.getBoundingClientRect();return{x:s.clientX-d.left+z.current.scrollLeft+8,y:s.clientY-d.top+z.current.scrollTop+8}},nt=s=>o.createElement(o.Fragment,null,s.placeholder&&o.createElement(Tt,{node:{...s,ref:d=>{h.current[s.id]=d}},dragging:!!v,compact:E,onFill:()=>g({from:s.from,on:s.on,at:{x:16,y:52}}),onDrop:()=>{let d=v;C(null),d&&p("/edges","POST",{from:s.from,to:d,on:s.on})}}),s.holds&&o.createElement(ht,{node:{...s,ref:d=>{h.current[s.id]=d}},header:xt(s,rt(s),r.hide_step_type_codes),compact:E,onSelect:()=>c?q(s.id):m(s.id)}),!s.placeholder&&!s.holds&&o.createElement(Z,{node:{...s,ref:d=>{h.current[s.id]=d},violations:et[s.id]||[],connected:r.edges.filter(d=>d.source===s.id).map(d=>d.label||null)},selected:s.id===b,armed:c&&c[0]===s.id?c[1]:null,connecting:!!c&&c[0]!==s.id,onSelect:()=>c?q(s.id):m(s.id),onOpen:d=>window.location.assign(d),onArm:(d,B)=>{let j=z.current.getBoundingClientRect();g({from:s.id,on:d,at:{x:B.clientX-j.left+z.current.scrollLeft+8,y:B.clientY-j.top+z.current.scrollTop+8}})},onDragEnd:()=>C(null),onDragStart:()=>C(s.id),hideStepTypeCodes:r.hide_step_type_codes,compact:E,branches:E?Jt(s,r.edges,H).map(d=>qt(d,r.nodes)):[]})),st=ot.length>0&&o.createElement("div",{"data-loose":!0,className:"border border-dashed border-gray-300 bg-gray-50 dark:border-zinc-700 dark:bg-zinc-900",style:E?zo:ae},o.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"),ot.map(s=>o.createElement("div",{key:s.id,style:{marginBottom:8}},o.createElement(Z,{node:{...s,ref:d=>{h.current[s.id]=d},violations:et[s.id]||[],connected:[]},selected:b===s.id,armed:c&&c[0]===s.id?c[1]:null,connecting:!!c,onSelect:()=>c?q(s.id):m(s.id),onOpen:d=>window.location.assign(d),onArm:(d,B)=>{B.stopPropagation(),k([s.id,d])},onDragStart:()=>C(s.id),onDragEnd:()=>C(null),hideStepTypeCodes:r.hide_step_type_codes}))));return o.createElement("div",{className:"text-gray-900 dark:text-gray-100",style:So,onMouseUp:()=>C(null),onKeyDown:s=>{s.key==="Escape"&&(m(null),k(null),g(null))},tabIndex:-1},o.createElement("div",{ref:z,className:"bg-surface-50 dark:bg-surface-950",style:No,onClick:s=>{s.target===z.current&&(m(null),k(null),N(!1))},onDragOver:s=>{v&&s.preventDefault()},onDrop:pe},c&&o.createElement(To,{port:c[1],onCancel:()=>k(null)}),o.createElement(Ot,{undoable:r.undoable,redoable:r.redoable,onAdd:()=>g({at:{x:16,y:52}}),onUndo:()=>{m(null),p("/undo","POST")},onRedo:()=>{m(null),p("/redo","POST")}}),!E&&tt.map(s=>o.createElement(yt,{key:s.id,id:s.id,bounds:s.bounds,onDrop:()=>{let d=v;C(null),d&&p(`/steps/${d}/group`,"PATCH",{group:s.id})}})),!E&&o.createElement(Ft,{links:wt(M,r.nodes),extent:le,dragging:v,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=>{m(null),p("/edges","DELETE",{from:s.source,to:s.target})},onDrop:s=>{let d=v;C(null),p("/steps/"+d+"/move","PATCH",{from:s.source,to:s.target})}}),!E&&st,E&&o.createElement(Qt,{nodes:H,edges:r.edges,draw:nt,joints:{alwaysShowInsertButtons:r.always_show_insert_buttons,onInsert:(s,d)=>g({from:s.source,to:s.target,at:ue(d)}),onRemove:s=>{m(null),p("/edges","DELETE",{from:s.source,to:s.target})},onDrop:s=>{let d=v;C(null),d&&p("/steps/"+d+"/move","PATCH",{from:s.source,to:s.target})}}},st),!E&&o.createElement("div",{style:{...Bo,gridTemplateColumns:`repeat(${ce+1}, ${280/2}px)`,gridTemplateRows:`repeat(${de}, auto)`}},H.map(s=>o.createElement("div",{key:s.id,style:{gridRow:s.row+1,gridColumn:`${s.column+1} / span 2`,zIndex:2,marginTop:kt(s,r.nodes)?Co-64:0}},nt(s)))),f&&o.createElement(Et,{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 d=f;g(null),p("/steps","POST",{id:ne(s.type,r.nodes.map(B=>B.id)),type:s.type,from:d.from,to:d.to,on:d.on})}})),x&&!P&&o.createElement(Mt,{flow:r.flow||{},changes:r.changes||[],problems:r.violations,refusal:a,notice:l,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})}),P&&o.createElement(_t,{node:P,fields:D?.fields||{},holds:D?.records||{},labels:D?.labels||{},explanations:D?.explanations||{},recordLabels:D?.record_labels||{},recordExplanations:D?.record_explanations||{},recordChoices:D?.record_choices||{},recordOutputsOf:D?.record_outputs_of||{},choices:Ct(P,D),onClose:()=>m(null),onSave:s=>p(`/steps/${P.id}`,"PATCH",{config:s}),onPickPicture:y,refusal:a,onDelete:()=>{m(null),p(`/steps/${P.id}`,"DELETE")}}))},ie=Eo;ct("easy_flow/flow-editor",ie);document.addEventListener("easy_flow:flow-named",t=>{let e=document.querySelector("[data-flow-heading]");e&&(e.textContent=t.detail)});mt(document,at);})();
1
+ (()=>{var Ce=globalThis.ReactDOM;var{createPortal:Zo,createRoot:mt,flushSync:Ro,hydrateRoot:tr,preconnect:er,prefetchDNS:or,preinit:rr,preinitModule:nr,preload:sr,preloadModule:ar,requestFormReset:ir,unstable_batchedUpdates:lr,useFormState:dr,useFormStatus:cr,version:pr}=Ce;var ft=globalThis.React,o=ft,{Children:mr,Component:fr,Fragment:gr,PureComponent:yr,StrictMode:hr,Suspense:xr,cloneElement:br,createContext:vr,createElement:wr,createRef:kr,forwardRef:Sr,isValidElement:Cr,lazy:Nr,memo:zr,startTransition:Br,useCallback:Tr,useContext:_r,useDebugValue:Er,useDeferredValue:Dr,useEffect:I,useId:Or,useImperativeHandle:Ar,useLayoutEffect:gt,useMemo:M,useReducer:Pr,useRef:tt,useState:S,useSyncExternalStore:Lr,useTransition:$r}=ft;var yt=new Map,F=new Map,et=(t,e)=>yt.set(t,e),ht=()=>{F.forEach(t=>t.unmount()),F.clear()},xt=(t,e)=>t.querySelectorAll("[data-react-ui]").forEach(n=>{if(F.has(n))return;let r=yt.get(n.dataset.reactUi),a=e(n);F.set(n,a),a.render(o.createElement(r,JSON.parse(n.dataset.props)))});var bt=(t,e)=>{let n=()=>xt(t,e);t.addEventListener("turbo:load",n),t.addEventListener("turbo:frame-load",n),t.addEventListener("turbo:before-cache",ht),t.readyState==="loading"?t.addEventListener("DOMContentLoaded",n):n()};var _=(...t)=>t.filter(Boolean).join(" ");var Ne={primary:"ks-button-primary",secondary:"ks-button-secondary",danger:"ks-button-danger"},ze={sm:"ks-button-sm",md:"ks-button-md",lg:"ks-button-lg"},Be=({variant:t="primary",size:e="md",className:n,children:r,...a})=>{let l=a.href?"a":"button";return o.createElement(l,{...a,className:_("ks-button",Ne[t],ze[e],n)},r)},w=Be;var Te="border border-amber-500 bg-white text-amber-700 dark:bg-zinc-900 dark:text-amber-400",_e="border border-gray-300 bg-white text-gray-500 dark:border-zinc-600 dark:bg-zinc-900 dark:text-gray-400",Ee="border border-accent-600 bg-accent-600 text-white",De=({name:t,connected:e,armed:n,onArm:r,connecting:a})=>o.createElement("button",{onClick:l=>{a||(l.stopPropagation(),r(l))},title:n?"Now choose a step to connect to":"Connect this branch",className:n?Ee:e?_e:Te,style:{padding:"1px 8px",marginRight:4,borderRadius:999,fontSize:11,cursor:"pointer"}},t||"next"),vt=De;var Oe={width:240,boxSizing:"border-box",borderRadius:8},Ae={minWidth:120,boxSizing:"border-box",borderRadius:6},Pe={padding:"8px 14px",textAlign:"center",fontWeight:600},Le={fontWeight:600,lineHeight:1.3},$e={fontSize:12,fontWeight:500,lineHeight:1.3},Ie=(t,e,n)=>{let r=n?"ring-4 ring-accent-600/15":"shadow-sm";return t||n&&!e?`border-accent-600 ${r}`:e?`border-red-600 ${r}`:"border-gray-300 shadow-sm dark:border-zinc-700"},Me=(t,e)=>e&&t.label===t.id&&t.type_name||t.label,je=(t,e,n)=>n?e===t.type_name?null:t.type_name:t.type,He=({node:t,selected:e,armed:n,connecting:r,onSelect:a,onOpen:l,onArm:d,onDragEnd:i,onDragStart:p,hideStepTypeCodes:y,branches:b=[],compact:m=!1})=>{let f=t.begins_here||t.ends_here,g=t.begins_here,u=t.ends_here?[]:t.ports,k=r&&!g,v=Me(t,y),C=je(t,v,y);return o.createElement("div",{ref:t.ref,"data-step":t.id,draggable:!g,onDragStart:x=>{x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("text/plain",t.id),p()},onDragEnd:i,onClick:t.opens&&!r?()=>l(t.opens):a,className:`bg-white ${m&&!e?"border":"border-2"} dark:bg-zinc-900 ${Ie(k,t.violations.length>0,e)}`,style:{...m?Ae:Oe,padding:f?0:m?"8px 10px":"12px 14px",cursor:g?"default":r?"crosshair":"grab"}},!f&&m&&C&&o.createElement("div",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},C),f&&o.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:Pe},v),!f&&o.createElement("div",{style:m?$e:Le},v),!f&&!m&&C&&o.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginTop:2}},C),t.picture_url&&o.createElement("div",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:11,marginTop:2}},"Has a picture"),t.starts_a_flow&&o.createElement("div",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:11,marginTop:2}},"Runs a flow"),t.opens&&o.createElement(w,{variant:"secondary",size:"sm",className:"mt-2",onClick:x=>{x.stopPropagation(),a()}},"Settings"),b.map(x=>o.createElement("div",{key:x,className:"text-gray-500 dark:text-gray-400",style:{fontSize:10}},x)),t.violations.map(x=>o.createElement("div",{key:x.problem+x.detail,className:"text-red-600 dark:text-red-400",style:{fontSize:11,padding:"0 14px 6px"}},x.sentence)),u.length>0&&o.createElement("div",{style:{padding:t.begins_here?"0 14px 8px":"10px 0 0"}},u.map(x=>o.createElement(vt,{key:x,name:x,connected:t.connected.includes(x),connecting:r,armed:n===x,onArm:B=>d(x,B)}))))},ot=He;var wt={position:"relative",zIndex:2,width:240,fontSize:11,whiteSpace:"nowrap",cursor:"pointer"},We={...wt,width:"auto",whiteSpace:"normal",overflowWrap:"anywhere"},Fe=({node:t,header:e,onSelect:n,compact:r=!1})=>o.createElement("div",{ref:t.ref,"data-group-header":t.id,onClick:n,className:"font-mono text-gray-500 dark:text-gray-400",style:{...r?We:wt,...n?{}:{cursor:"default"}}},e),V=Fe;var Ve=({id:t,bounds:e,onDrop:n})=>o.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",...e}}),kt=Ve;var Ye=t=>t!=null&&t!==""&&typeof t!="object",Ue=["integer","float"],Ge=(t,e,n)=>n&&e.labels?.[t]||t,Y=(t,e,n)=>{let r=Object.keys(e?.fields||{}).filter(a=>Ye(t.config[a])).map(a=>`${Ge(a,e,n)}${Ue.includes(e.fields[a])?"":":"} ${t.config[a]}`);return[n&&t.type_name||t.type,...r].join(" \xB7 ")};var St=(t,e,n)=>{let r=Math.min(...t.map(i=>i.left))-e.left+n.scrollLeft-12,a=Math.min(...t.map(i=>i.top))-e.top+n.scrollTop-10,l=Math.max(...t.map(i=>i.left+i.width))-e.left+n.scrollLeft+12,d=Math.max(...t.map(i=>i.top+i.height))-e.top+n.scrollTop+10;return{left:r,top:a,width:l-r,height:d-a}},Xe=({left:t,top:e,width:n,height:r},a)=>a.x>=t&&a.x<=t+n&&a.y>=e&&a.y<=e+r,Ct=(t,e)=>t.find(n=>Xe(n.bounds,e))?.id||null,Nt=(t,e)=>t.filter(n=>!e.some(r=>r.id===n.source&&r.holds?.includes(n.target))),zt=(t,e)=>e.some(n=>n.holds?.includes(t.id)&&!n.loose&&n.row===t.row-1);var rt=(t,e)=>t.includes(e)?t.filter(n=>n!==e):[...t,e],Bt=(t,e)=>({...e?.choices||{},...t?.choices||{}});var qe=({as:t="input",disabled:e,className:n,...r})=>o.createElement(t,{...r,disabled:e,className:_("ks-input",e&&"ks-input-disabled",n)}),D=qe;var Je=t=>o.createElement(D,{...t,as:"select"}),Tt=Je;var Ke=({className:t,...e})=>o.createElement("input",{type:"checkbox",...e,className:_("ks-checkbox",t)}),U=Ke;var _t=t=>(t||[]).map(e=>typeof e=="object"?e:{value:e,label:e}),Qe=({type:t,value:e,choices:n,onChange:r,onSettle:a,onPick:l,pictureUrl:d})=>{if(t==="picture")return o.createElement("div",{className:"mb-3"},e&&d&&o.createElement("img",{src:d,alt:"The step's picture",style:{maxWidth:"100%"}}),e&&o.createElement("button",{type:"button","data-remove-picture":!0,className:"ks-button ks-button-secondary ks-button-sm",onClick:()=>a("")},"Remove picture"),o.createElement("input",{type:"file",accept:"image/*",onChange:i=>i.target.files[0]&&l(i.target.files[0])}));if(t==="boolean")return o.createElement(U,{checked:!!e,onChange:i=>a(i.target.checked)});if(t==="select"||t==="previous_step"||t==="from_step"||t==="flow")return o.createElement(Tt,{className:"mb-3",value:e??"",onChange:i=>a(i.target.value)},o.createElement("option",{value:""}),_t(n).map(i=>o.createElement("option",{key:i.value,value:i.value},i.label)));if(t==="multi_select"){let i=Array.isArray(e)?e:[],p=y=>a(rt(i,y));return o.createElement("div",{style:{display:"flex",flexWrap:"wrap",gap:8}},(n||[]).map(y=>o.createElement("label",{key:y,style:{display:"inline-flex",alignItems:"center",gap:4}},o.createElement(U,{checked:i.includes(y),onChange:()=>p(y)}),o.createElement("span",null,y))))}if(t==="flows"){let i=Array.isArray(e)?e:[];return o.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4},className:"mb-3"},_t(n).map(p=>o.createElement("label",{key:p.value,style:{display:"inline-flex",alignItems:"center",gap:4}},o.createElement(U,{checked:i.includes(p.value),onChange:()=>a(rt(i,p.value))}),o.createElement("span",null,p.label))))}return t==="integer"||t==="float"?o.createElement(D,{className:"mb-3",type:"number",step:t==="integer"?"1":"any",value:e??"",onChange:i=>r(i.target.value),onBlur:i=>a(i.target.value)}):o.createElement(D,{className:"mb-3",type:"text",value:e??"",onChange:i=>r(i.target.value),onBlur:i=>a(i.target.value)})},G=Qe;var Et=(t,e,n,r)=>t.map((a,l)=>l===e?{...a,[n]:r}:a);var Ze=({text:t})=>o.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),X=Ze;var Re=(t,e,n,r)=>{let a=(t||{})[n],l=(e||{})[n];return l?(a||{})[r[l]]:a},to=({holds:t,labels:e,explanations:n,rows:r,choices:a,outputsOf:l,onChange:d,onSettle:i})=>{let p=Array.isArray(r)?r:[],y=(b,m,f,g)=>{let u=Et(p,b,m,f);g?i(u):d(u)};return o.createElement("div",{style:{marginBottom:12}},p.map((b,m)=>o.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(([f,g])=>o.createElement("label",{key:f,style:{display:"block"}},o.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{display:"block",marginBottom:2,fontSize:11}},(e||{})[f]||f),o.createElement(G,{type:g,value:b[f],choices:Re(a,l,f,b),onChange:u=>y(m,f,u,!1),onSettle:u=>y(m,f,u,!0)}),(n||{})[f]&&o.createElement(X,{text:n[f]}))),o.createElement(w,{variant:"secondary",size:"sm",className:"mb-1.5",onClick:()=>i(p.filter((f,g)=>g!==m))},"Remove"))),o.createElement(w,{variant:"secondary",size:"sm",className:"w-full",onClick:()=>i([...p,{}])},"Add"))},Dt=to;var eo=({as:t="div",className:e,children:n,...r})=>o.createElement(t,{...r,className:_("ks-panel",e)},n),P=eo;var q=(t,e)=>({className:n,children:r,...a})=>o.createElement(t,{...a,className:_(e,n)},r),W=q("label","ks-label"),In=q("p","ks-hint"),Mn=q("p","ks-error"),jn=q("span","ks-required");var oo={width:280,padding:20,overflowY:"auto"},ro=({node:t,fields:e,holds:n,labels:r,explanations:a,recordLabels:l,recordExplanations:d,recordChoices:i,recordOutputsOf:p,choices:y,onSave:b,onDelete:m,onClose:f,onPickPicture:g,refusal:u})=>{let[k,v]=S(t.config),[C,x]=S(t.picture_url);I(()=>x(t.picture_url),[t.id,t.picture_url]),I(()=>v(t.config),[t.id,t.config]);let B=h=>{v(h),JSON.stringify(h)!==JSON.stringify(t.config)&&b(h)};return o.createElement(P,{as:"aside",style:oo,"data-inspector":!0},o.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8}},o.createElement("h2",{style:{fontWeight:600,marginBottom:2}},t.label),o.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")),o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:11,marginBottom:16}},t.id," \xB7 ",t.type),u&&o.createElement("p",{className:"text-red-800 dark:text-red-400",style:{fontWeight:600,marginBottom:12},"data-refusal":!0},u),Object.entries(e).map(([h,O])=>o.createElement(W,{key:h},o.createElement("span",{style:{display:"block",marginBottom:3}},r[h]||h),O==="list"?o.createElement(Dt,{holds:n[h]||{},labels:l[h]||{},explanations:(d||{})[h],rows:k[h],choices:{...(i||{})[h],...(t.record_choices||{})[h]},outputsOf:(p||{})[h],onChange:N=>v({...k,[h]:N}),onSettle:N=>B({...k,[h]:N})}):o.createElement(G,{type:O,value:k[h],choices:y[h],pictureUrl:C,onChange:N=>v({...k,[h]:N}),onSettle:N=>B({...k,[h]:N}),onPick:async N=>{let T=await g(N);T&&(x(T.url),B({...k,[h]:T.reference}))}}),(a||{})[h]&&o.createElement(X,{text:a[h]}))),o.createElement(w,{variant:"danger",size:"sm",className:"w-full",onClick:m},"Delete step"))},Ot=ro;var no={width:240,boxSizing:"border-box",padding:"10px 14px",borderRadius:8,textAlign:"center",fontSize:12,cursor:"pointer"},so={minWidth:120,boxSizing:"border-box",padding:"8px 10px",borderRadius:6,textAlign:"center",fontSize:12,cursor:"pointer"},ao="border-2 border-dashed border-amber-500 bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300",io="border-2 border-dashed border-accent-600 bg-accent-50 text-accent-800 dark:bg-accent-950 dark:text-accent-200",lo=({node:t,dragging:e,onFill:n,onDrop:r,compact:a=!1})=>o.createElement("div",{ref:t.ref,"data-placeholder":t.id,title:`Choose the step \u201C${t.label}\u201D should lead to`,onClick:n,onDragOver:l=>{e&&(l.preventDefault(),l.dataTransfer.dropEffect="move")},onDrop:l=>{l.preventDefault(),r()},className:e?io:ao,style:a?so:no},o.createElement("div",{style:{fontWeight:600}},t.label),o.createElement("div",{style:{fontSize:11}},e?"drop a step here":"leads nowhere yet \u2014 click to choose")),At=lo;var co=({entries:t,at:e,onPick:n,onConnect:r,onDismiss:a,hideStepTypeCodes:l})=>o.createElement(P,{className:"shadow-lg",style:{position:"absolute",zIndex:9,top:e.y,left:e.x,width:210,padding:8,borderRadius:8}},o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{margin:"0 0 6px",fontSize:11}},"Add a step"),t.map(d=>o.createElement(w,{key:d.type,variant:"secondary",size:"sm",className:"w-full mb-1.5 flex-col",onClick:()=>n(d)},d.label,!l&&o.createElement("span",{className:"opacity-75",style:{display:"block",fontSize:11}},d.type))),r&&o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:r},"Connect to a step already here"),o.createElement(w,{variant:"secondary",size:"sm",className:"w-full",onClick:a},"Cancel")),Pt=co;var po=t=>e=>e.label.toLowerCase().includes(t.trim().toLowerCase()),uo=(t,e,n="")=>{let r=Object.values(e).flat(),a=Object.entries(e).map(([l,d])=>({heading:l,entries:d.map(i=>t.find(p=>p.type===i)).filter(Boolean)}));return[{heading:null,entries:t.filter(l=>!r.includes(l.type))},...a].map(l=>({...l,entries:l.entries.filter(po(n))})).filter(l=>l.entries.length>0)},mo={width:200,flex:"none",boxSizing:"border-box",padding:"14px 12px",gap:6,fontSize:12,overflowY:"auto",borderWidth:"0 1px 0 0"},fo={fontSize:11,textTransform:"uppercase",letterSpacing:".04em",padding:"8px 4px 2px"},go={textAlign:"left",padding:"7px 9px",borderRadius:6,fontSize:12,cursor:"grab"},yo=({entries:t,groups:e,onPick:n,onCarry:r,onDrop:a})=>{let[l,d]=S("");return o.createElement(P,{as:"aside","aria-label":"Steps","data-step-list":!0,className:"hidden flex-col sm:flex",style:mo},o.createElement(D,{type:"search","aria-label":"Search steps",placeholder:"Search steps",value:l,onChange:i=>d(i.target.value),style:{marginBottom:6,fontSize:12}}),uo(t,e,l).map(i=>o.createElement(o.Fragment,{key:i.heading||""},i.heading&&o.createElement("div",{className:"text-gray-500 dark:text-gray-400",style:fo},i.heading),i.entries.map(p=>o.createElement(P,{as:"button",type:"button",key:p.type,"data-step-type":p.type,className:"bg-surface-50 dark:bg-surface-950",style:go,draggable:!0,onClick:()=>n(p),onDragStart:y=>{y.dataTransfer.effectAllowed="copyMove",y.dataTransfer.setData("text/plain",p.type),r(p)},onDragEnd:a},p.label)))))},Lt=yo;var ho={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},$t=({label:t,title:e,idle:n,enabled:r,onUse:a})=>o.createElement(w,{variant:"secondary",size:"sm",title:r?e:n,disabled:!r,onClick:a,style:{opacity:r?1:.4,cursor:r?"pointer":"default"}},t),xo=({undoable:t,redoable:e,onAdd:n,onUndo:r,onRedo:a})=>o.createElement("div",{style:{position:"absolute",top:16,left:16,zIndex:5,display:"flex",gap:8}},o.createElement(w,{variant:"secondary",className:"rounded-full",style:ho,title:"Add a step",onClick:n},"+"),o.createElement($t,{label:"\u21B6 Undo",title:"Undo the last change",idle:"Nothing to undo",enabled:t,onUse:r}),o.createElement($t,{label:"\u21B7 Redo",title:"Redo the change you undid",idle:"Nothing to redo",enabled:e,onUse:a})),It=xo;var bo=({type:t="info",title:e,message:n,onDismiss:r,className:a})=>o.createElement("div",{className:_("ks-alert",`ks-alert-${t}`,a),role:"alert"},o.createElement("div",{className:"ks-alert-body"},o.createElement("div",{className:"ks-alert-content"},e&&o.createElement("p",{className:"ks-alert-title"},e),o.createElement("p",{className:e?"ks-alert-message-titled":"ks-alert-message"},n)),r&&o.createElement("button",{type:"button",className:"ks-alert-dismiss","aria-label":"Dismiss",onClick:r},"\xD7"))),Mt=bo;var jt=t=>{let e=t.map(n=>`\u201C${n.name}\u201D`).join(", ");return t.length===1?`${e} is not connected to the flow and will be removed. Remove it to go on, or cancel and connect it first.`:`${e} are not connected to the flow and will be removed. Remove them to go on, or cancel and connect them first.`};var Ht=({version:t,published:e})=>t?e?e===t?`Version ${t} \xB7 live`:`Version ${t} \xB7 visitors still on ${e}`:`Version ${t} \xB7 never published`:"No version yet";var vo={width:280,padding:20,overflowY:"auto"},nt={fontWeight:600,marginBottom:6,marginTop:14},J={fontSize:12,marginBottom:4,lineHeight:1.4},Wt={display:"block",marginBottom:3},Ft=(t,e,n)=>r=>{r.target.value!==(t[e]??"")&&n({[e]:r.target.value})},wo=({flow:t,changes:e,problems:n,refusal:r,notice:a,publishNote:l,warning:d,onCreate:i,onPublish:p,onAccept:y,onDecline:b,onSaveDetails:m,onClose:f})=>o.createElement(P,{as:"aside",style:vo,"data-builder-panel":!0},o.createElement("div",{style:{display:"flex",alignItems:"start",justifyContent:"space-between",gap:8}},o.createElement("h2",{style:{fontWeight:600},"data-flow-name":!0},t.title||t.slug),o.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")),o.createElement("a",{className:"text-accent-600 dark:text-accent-400",style:{fontSize:12,display:"block"},href:t.history_url,"data-history":!0},Ht(t)),d?o.createElement("div",{style:{marginTop:14},"data-unconnected-warning":!0},o.createElement(Mt,{type:"warning",className:"mb-1.5",message:jt(d.steps)}),o.createElement(w,{size:"sm",className:"w-full mb-1.5",onClick:y,"data-accept-removal":!0},d.path==="/publish"?"Remove and publish":"Remove and create version"),o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:b,"data-decline-removal":!0},"Cancel")):o.createElement("div",{style:{marginTop:14}},o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",onClick:i,"data-create-version":!0},"Create version"),o.createElement(w,{size:"sm",className:"w-full mb-1.5",onClick:p,"data-publish":!0},"Publish"),l&&o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12,lineHeight:1.4},"data-publish-note":!0},l)),o.createElement("h2",{style:nt},"Problems"),r&&o.createElement("p",{className:"text-red-800 dark:text-red-400",style:{...J,fontWeight:600},"data-refusal":!0},r),a&&!r&&o.createElement("p",{className:"text-emerald-800 dark:text-emerald-400",style:{...J,fontWeight:600},"data-notice":!0},a),n.length===0&&!r?o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12}},"Nothing wrong with this flow."):n.map(g=>o.createElement("p",{key:`${g.node}-${g.problem}`,className:"text-amber-700 dark:text-amber-400",style:J,"data-problem":!0},"\u26A0 ",g.sentence)),o.createElement("h2",{style:nt},"Changes since the last version"),e.length===0?o.createElement("p",{className:"text-gray-500 dark:text-gray-400",style:{fontSize:12}},"Nothing has changed."):e.map((g,u)=>o.createElement("p",{key:u,style:J,"data-change":!0},g)),o.createElement("h2",{style:nt},"Details"),o.createElement(W,null,o.createElement("span",{style:Wt},"Title"),o.createElement(D,{className:"mb-3",defaultValue:t.title??"",onBlur:Ft(t,"title",m),"data-flow-title":!0})),o.createElement(W,null,o.createElement("span",{style:Wt},"Start label"),o.createElement(D,{className:"mb-3",defaultValue:t.start_label??"",onBlur:Ft(t,"start_label",m),"data-flow-start-label":!0})),o.createElement("div",{style:{marginTop:16}},o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.definition_url,"data-definition":!0},"Definition"),o.createElement(w,{variant:"secondary",size:"sm",className:"w-full mb-1.5",href:t.details_url,"data-details":!0},"Edit details"))),Vt=wo;var Yt={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},Ut=t=>({opacity:t?1:0,transition:"opacity .12s"}),ko=({link:t,onInsert:e,onRemove:n,onDrop:r,dragging:a,alwaysShowInsertButtons:l})=>{let[d,i]=S(!1),p=d||a;return o.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()}},o.createElement("div",{style:{display:"flex",gap:4,justifyContent:"center",alignItems:"center",height:"100%"}},o.createElement(w,{variant:"secondary",title:a?"Move the step here":"Insert a step here",onClick:e,className:"rounded-full data-[over=true]:ring-2 data-[over=true]:ring-accent-600","data-over":!!(a&&d),style:{...Yt,...Ut(p||l)}},"+"),!a&&o.createElement(w,{variant:"danger",title:"Remove this connection",onClick:n,className:"rounded-full",style:{...Yt,...Ut(p)}},"\xD7")))},Gt=ko;var So=({links:t,extent:e,dragging:n,onInsert:r,onRemove:a,onDrop:l,alwaysShowInsertButtons:d})=>o.createElement(o.Fragment,null,o.createElement("svg",{width:e.width,height:e.height,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:1}},o.createElement("defs",null,o.createElement("marker",{id:"easy_flow-arrow",viewBox:"0 0 10 10",refX:"8",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto"},o.createElement("path",{d:"M 0 0 L 10 5 L 0 10 z",className:"fill-gray-400 dark:fill-zinc-500"}))),t.map(i=>o.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=>o.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+(d?2:-10),top:i.midY-18,zIndex:3,fontSize:11,padding:"0 3px"}},i.label)),t.filter(i=>!i.placeholder).map(i=>o.createElement(Gt,{key:i.id,link:i,dragging:!!n,alwaysShowInsertButtons:d,onInsert:()=>r(i),onRemove:()=>a(i),onDrop:()=>l(i)}))),Xt=So;var st={width:24,height:24,padding:0,fontSize:15,lineHeight:"15px"},qt="opacity-0 transition-opacity group-data-[over=true]:opacity-100",Co=({link:t,onInsert:e,onRemove:n,onDrop:r,alwaysShowInsertButtons:a,dragging:l})=>o.createElement("div",{"data-joint":t?.id,className:"group relative h-7 w-full sm:h-auto sm:w-7 sm:self-stretch",onMouseEnter:d=>{d.currentTarget.dataset.over="true"},onMouseLeave:d=>{delete d.currentTarget.dataset.over},onDragOver:d=>{t&&r&&(d.preventDefault(),d.dataTransfer.dropEffect="move")},onDrop:d=>{t&&(d.preventDefault(),r(t))}},t&&o.createElement("div",{className:"absolute left-1/2 top-0 h-full w-px bg-gray-400 sm:left-0 sm:top-1/2 sm:h-px sm:w-full dark:bg-zinc-500"}),t&&e&&o.createElement("div",{className:"absolute inset-0 flex items-center justify-center gap-1 sm:flex-col",style:{zIndex:4}},o.createElement(w,{variant:"secondary",title:"Insert a step here",onClick:d=>e(t,d),className:`rounded-full ${a?"opacity-100":qt}`,style:l?{...st,opacity:1}:st},"+"),o.createElement(w,{variant:"danger",title:"Remove this connection",onClick:()=>n(t),className:`rounded-full ${qt}`,style:st},"\xD7"))),Jt=Co;var No=(t,e)=>t.row-e.row||t.column-e.column,Kt=t=>{let e=[...t].sort(No),n=e.filter(r=>t.some(a=>a.holds?.includes(r.id)));return e.filter(r=>!n.includes(r)).flatMap(r=>[r,...n.filter(a=>r.holds?.includes(a.id))])},Qt=t=>{let e=Kt(t),n=r=>e.some(a=>a.holds?.includes(r.id));return e.filter(r=>!n(r)).reduce((r,a)=>{if(a.holds)return[...r,{group:a,steps:e.filter(d=>a.holds.includes(d.id))}];let l=r[r.length-1];return l&&!l.group?[...r.slice(0,-1),{steps:[...l.steps,a]}]:[...r,{steps:[a]}]},[])},zo=(t,e)=>t[t.findIndex(n=>n.id===e.id)+1]?.id,Zt=(t,e,n)=>{let r=zo(Kt(n),t);return e.filter(a=>a.source===t.id&&(a.label||a.target!==r))},Bo=t=>t?.placeholder?"nowhere yet":t?.label,Rt=(t,e)=>[t.label,"\u2192",Bo(e.find(n=>n.id===t.target))].filter(Boolean).join(" "),te=(t,e,n)=>t.find(r=>r.source===e.id&&r.target===n.id);var To={display:"flex",flexDirection:"column",gap:14,padding:"64px 24px 24px"},ee=({steps:t,edges:e,draw:n,joints:r})=>o.createElement("div",{"data-flow-row":!0,className:"flex flex-col sm:flex-row sm:flex-wrap sm:items-center sm:gap-y-3.5"},t.map((a,l)=>o.createElement("div",{key:a.id,className:"flex flex-col sm:flex-row sm:items-center"},l>0&&o.createElement(Jt,{link:te(e,t[l-1],a),...r}),n(a)))),_o={display:"flex",flexDirection:"column",gap:8,padding:"10px 12px",borderRadius:8},Eo=({group:t,steps:e,edges:n,draw:r,joints:a})=>o.createElement("div",{"data-group-box":t.id,className:"border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60",style:_o},r(t),o.createElement(ee,{steps:e,edges:n,draw:r,joints:a})),Do=({nodes:t,edges:e,draw:n,joints:r,children:a,style:l})=>o.createElement("div",{"data-flow-rows":!0,style:{...To,...l}},a,Qt(t).map(d=>d.group?o.createElement(Eo,{key:d.group.id,group:d.group,steps:d.steps,edges:e,draw:n,joints:r}):o.createElement(ee,{key:d.steps[0].id,steps:d.steps,edges:e,draw:n,joints:r}))),K=Do;var oe="Your change was not saved because the server could not be reached.",re=({base:t,token:e,fetch:n,onFlow:r,onError:a,onNotice:l,onWarning:d=()=>{}})=>async(i,p,y)=>{let b=await n(t+i,{method:p,headers:{"Content-Type":"application/json","X-CSRF-Token":e},body:y&&JSON.stringify(y)}).catch(()=>null);if(!b)return l(null),a(oe);let m=await b.json().catch(()=>({}));if(m.unconnected)return l(null),a(null),d({path:i,steps:m.unconnected}),r(await(await n(t+".json",{headers:{Accept:"application/json"}})).json());if(d(null),!b.ok)return l(null),a(m.error||"That change was refused");a(null),l(m.notice||null),r(await(await n(t+".json",{headers:{Accept:"application/json"}})).json())},ne=({base:t,token:e,fetch:n,onError:r})=>async a=>{let l=new FormData;l.append("picture",a);let d=await n(t+"/pictures",{method:"POST",headers:{"X-CSRF-Token":e},body:l}).catch(()=>null);if(!d)return r(oe),null;let i=await d.json().catch(()=>({}));return d.ok?(r(null),i):(r(i.error||"That picture was refused"),null)};var Oo=(t,e,n)=>{let[r,a]=S(n),[l,d]=S(null),[i,p]=S(null),[y,b]=S(null),m=M(()=>re({base:t,token:e,fetch:(...g)=>window.fetch(...g),onFlow:a,onError:d,onNotice:p,onWarning:b}),[t,e]),f=M(()=>ne({base:t,token:e,fetch:(...g)=>window.fetch(...g),onError:d}),[t,e]);return{flow:r,error:l,notice:i,warning:y,setWarning:b,send:m,pickPicture:f}},se=Oo;var Q=(t,e,n,r)=>{let a=t.left-n.left+r.scrollLeft,l=t.top-n.top+r.scrollTop;return e==="left"?{x:a,y:l+t.height/2}:e==="right"?{x:a+t.width,y:l+t.height/2}:e==="top"?{x:a+t.width/2,y:l}:{x:a+t.width/2,y:l+t.height}},Ao=(t,e,n)=>n&&e==="top"?{x:t.x,y:n.top}:t,Po=(t,e)=>e==="top"?{x:t.x,y:t.y-3}:e==="left"?{x:t.x-3,y:t.y}:e==="right"?{x:t.x+3,y:t.y}:{x:t.x,y:t.y+3},Lo=(t,e,n,r,a)=>{let l={straight:`M ${e.x} ${e.y} L ${n.x} ${n.y}`,turn:`M ${e.x} ${e.y} H ${n.x} V ${n.y}`,lane:`M ${e.x} ${e.y} V ${r} H ${n.x} V ${n.y}`,detour:`M ${e.x} ${e.y} H ${a} V ${n.y} H ${n.x}`}[t.route];return{...t,path:l,midX:t.route==="detour"?a:(e.x+n.x)/2,midY:t.route==="lane"?r:(e.y+n.y)/2}},$o=(t,e,n,r)=>{let[a,l]=S([]),[d,i]=S({width:"100%",height:"100%"}),[p,y]=S([]);return gt(()=>{let b=()=>{let f=e.current?.getBoundingClientRect();if(!f)return;i({width:e.current.scrollWidth,height:e.current.scrollHeight});let g=t.nodes.filter(u=>u.holds&&!u.loose&&n.current[u.id]).map(u=>{let k=n.current[u.id],v=k.getBoundingClientRect(),C=u.holds.flatMap(B=>n.current[B]?[n.current[B].getBoundingClientRect()]:[]),x=[{left:v.left,top:v.top,width:Math.max(v.width,k.scrollWidth),height:v.height},...C];return{id:u.id,bounds:St(x,f,e.current)}});y(g),l(t.edges.flatMap(u=>{let k=n.current[u.source]?.getBoundingClientRect(),v=n.current[u.target]?.getBoundingClientRect();if(!k||!v)return[];let C=Q(k,u.leaves,f,e.current),x=g.find(N=>N.id===u.target)?.bounds,B=Po(Ao(Q(v,u.enters,f,e.current),u.enters,x),u.enters),h=(Q(k,"bottom",f,e.current).y+Q(v,"top",f,e.current).y)/2,O=u.leaves==="left"?Math.min(C.x,B.x)-28:Math.max(C.x,B.x)+28;return[Lo(u,C,B,h,O)]}))};b(),window.addEventListener("resize",b);let m=new ResizeObserver(b);return e.current&&m.observe(e.current),()=>{window.removeEventListener("resize",b),m.disconnect()}},r),{links:a,extent:d,boxes:p}},ae=$o;var ie=(t,e)=>{let n=new Set(e),r=t,a=2;for(;n.has(r);)r=`${t}_${a++}`;return r};var Mo=8,jo={display:"flex",height:"100%",minHeight:0,fontSize:13},Ho={flex:1,overflow:"auto",position:"relative"},de={position:"absolute",top:56,left:16,zIndex:5,width:264,padding:12,borderRadius:8},Wo={...de,position:"static",alignSelf:"flex-start"},Fo={display:"grid",rowGap:64,columnGap:0,padding:40,justifyContent:"center",position:"relative"},Vo={position:"sticky",zIndex:8,top:8,margin:"8px auto 0",width:"fit-content",padding:"6px 12px",borderRadius:6,fontSize:12},Yo=({port:t,onCancel:e})=>o.createElement("div",{className:"bg-accent-100 text-accent-800 dark:bg-accent-900 dark:text-accent-100",style:Vo},"Choose the step \u201C",t||"next","\u201D should lead to \u2014 ",o.createElement("button",{onClick:e,className:"text-accent-800 underline dark:text-accent-100",style:{border:"none",background:"none",cursor:"pointer",fontSize:12,padding:0}},"cancel")),Uo=({base:t,token:e,initial:n})=>{let{flow:r,error:a,notice:l,warning:d,setWarning:i,send:p,pickPicture:y}=se(t,e,n),[b,m]=S(null),[f,g]=S(null),[u,k]=S(null),[v,C]=S(null),[x,B]=S(null),[h,O]=S(!1),N=tt({}),T=tt(null);I(()=>{let s=()=>{m(null),O(!0)};return document.addEventListener("easy_flow:open-flow",s),()=>document.removeEventListener("easy_flow:open-flow",s)},[]),I(()=>{if(!h){i(null);return}let s=c=>{c.target.isConnected&&!c.target.closest("[data-builder-panel], [data-open-panel]")&&O(!1)};return document.addEventListener("click",s),()=>document.removeEventListener("click",s)},[h]),I(()=>{document.dispatchEvent(new CustomEvent("easy_flow:flow-named",{detail:r.flow?.title||r.flow?.slug}))},[r.flow?.title,r.flow?.slug]);let ge=M(()=>Object.fromEntries(r.nodes.map(s=>[s.id,s])),[r.nodes]),{links:ye,extent:he,boxes:at}=ae(r,T,N,[r,b,ge]),it=M(()=>{let s={};return r.violations.forEach(c=>{var z;return(s[z=c.node]||(s[z]=[])).push(c)}),s},[r.violations]),E=r.direction==="left_to_right",j=r.nodes.filter(s=>!s.loose),lt=r.nodes.filter(s=>s.loose),xe=Math.max(0,...j.map(s=>s.row))+1,be=Math.max(0,...j.map(s=>s.column))+1,Z=s=>{if(!u)return;let[c,z]=u;k(null),c!==s&&p("/edges","POST",{from:c,to:s,on:z||null})},ve=s=>{if(s.isDefaultPrevented()||!v)return;s.preventDefault();let c=v;C(null);let z=T.current.getBoundingClientRect(),H=Ct(at,{x:s.clientX-z.left+T.current.scrollLeft,y:s.clientY-z.top+T.current.scrollTop}),ke=r.nodes.find(Se=>Se.holds?.includes(c))?.id||null;H!==ke&&p(`/steps/${c}/group`,"PATCH",{group:H})},dt=s=>[...r.palette,...r.unoffered||[]].find(c=>c.type===s?.type),$=r.nodes.find(s=>s.id===b),A=dt($),R=(s,c={})=>p("/steps","POST",{id:ie(s.type,r.nodes.map(z=>z.id)),type:s.type,from:c.from,to:c.to,on:c.on}),ct=s=>{let[c,z]=[x,v];B(null),C(null),c?R(c,{from:s.source,to:s.target}):z&&p("/steps/"+z+"/move","PATCH",{from:s.source,to:s.target})},we=s=>{let c=T.current.getBoundingClientRect();return{x:s.clientX-c.left+T.current.scrollLeft+8,y:s.clientY-c.top+T.current.scrollTop+8}},pt=s=>o.createElement(o.Fragment,null,s.placeholder&&o.createElement(At,{node:{...s,ref:c=>{N.current[s.id]=c}},dragging:!!v,compact:E,onFill:()=>g({from:s.from,on:s.on,at:{x:16,y:52}}),onDrop:()=>{let c=v;C(null),c&&p("/edges","POST",{from:s.from,to:c,on:s.on})}}),s.holds&&o.createElement(V,{node:{...s,ref:c=>{N.current[s.id]=c}},header:Y(s,dt(s),r.hide_step_type_codes),compact:E,onSelect:()=>u?Z(s.id):m(s.id)}),!s.placeholder&&!s.holds&&o.createElement(ot,{node:{...s,ref:c=>{N.current[s.id]=c},violations:it[s.id]||[],connected:r.edges.filter(c=>c.source===s.id).map(c=>c.label||null)},selected:s.id===b,armed:u&&u[0]===s.id?u[1]:null,connecting:!!u&&u[0]!==s.id,onSelect:()=>u?Z(s.id):m(s.id),onOpen:c=>window.location.assign(c),onArm:(c,z)=>{let H=T.current.getBoundingClientRect();g({from:s.id,on:c,at:{x:z.clientX-H.left+T.current.scrollLeft+8,y:z.clientY-H.top+T.current.scrollTop+8}})},onDragEnd:()=>C(null),onDragStart:()=>C(s.id),hideStepTypeCodes:r.hide_step_type_codes,compact:E,branches:E?Zt(s,r.edges,j).map(c=>Rt(c,r.nodes)):[]})),ut=lt.length>0&&o.createElement("div",{"data-loose":!0,className:"border border-dashed border-gray-300 bg-gray-50 dark:border-zinc-700 dark:bg-zinc-900",style:E?Wo:de},o.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"),lt.map(s=>o.createElement("div",{key:s.id,style:{marginBottom:8}},o.createElement(ot,{node:{...s,ref:c=>{N.current[s.id]=c},violations:it[s.id]||[],connected:[]},selected:b===s.id,armed:u&&u[0]===s.id?u[1]:null,connecting:!!u,onSelect:()=>u?Z(s.id):m(s.id),onOpen:c=>window.location.assign(c),onArm:(c,z)=>{z.stopPropagation(),k([s.id,c])},onDragStart:()=>C(s.id),onDragEnd:()=>C(null),hideStepTypeCodes:r.hide_step_type_codes}))));return o.createElement("div",{className:"text-gray-900 dark:text-gray-100",style:jo,onMouseUp:()=>C(null),onKeyDown:s=>{s.key==="Escape"&&(m(null),k(null),g(null))},tabIndex:-1},o.createElement(Lt,{entries:r.palette,groups:r.step_groups||{},onPick:s=>R(s),onCarry:B,onDrop:()=>B(null)}),o.createElement("div",{ref:T,className:"bg-surface-50 dark:bg-surface-950",style:Ho,onClick:s=>{s.target===T.current&&(m(null),k(null),O(!1))},onDragOver:s=>{v&&s.preventDefault()},onDrop:ve},u&&o.createElement(Yo,{port:u[1],onCancel:()=>k(null)}),o.createElement(It,{undoable:r.undoable,redoable:r.redoable,onAdd:()=>g({at:{x:16,y:52}}),onUndo:()=>{m(null),p("/undo","POST")},onRedo:()=>{m(null),p("/redo","POST")}}),!E&&at.map(s=>o.createElement(kt,{key:s.id,id:s.id,bounds:s.bounds,onDrop:()=>{let c=v;C(null),c&&p(`/steps/${c}/group`,"PATCH",{group:s.id})}})),!E&&o.createElement(Xt,{links:Nt(ye,r.nodes),extent:he,dragging:v||x,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=>{m(null),p("/edges","DELETE",{from:s.source,to:s.target})},onDrop:ct}),!E&&ut,E&&o.createElement(K,{nodes:j,edges:r.edges,draw:pt,joints:{alwaysShowInsertButtons:r.always_show_insert_buttons,dragging:!!(v||x),onInsert:(s,c)=>g({from:s.source,to:s.target,at:we(c)}),onRemove:s=>{m(null),p("/edges","DELETE",{from:s.source,to:s.target})},onDrop:ct}},ut),!E&&o.createElement("div",{style:{...Fo,gridTemplateColumns:`repeat(${be+1}, ${280/2}px)`,gridTemplateRows:`repeat(${xe}, auto)`}},j.map(s=>o.createElement("div",{key:s.id,style:{gridRow:s.row+1,gridColumn:`${s.column+1} / span 2`,zIndex:2,marginTop:zt(s,r.nodes)?Mo-64:0}},pt(s)))),f&&o.createElement(Pt,{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 c=f;g(null),R(s,c)}})),h&&!$&&o.createElement(Vt,{flow:r.flow||{},changes:r.changes||[],problems:r.violations,refusal:a,notice:l,publishNote:r.publish_note,warning:d,onClose:()=>O(!1),onCreate:()=>p("/versions","POST"),onPublish:()=>p("/publish","POST"),onAccept:()=>p(d.path,"POST",{remove_unconnected:d.steps.map(s=>s.id)}),onDecline:()=>i(null),onSaveDetails:s=>p("/details","PATCH",{flow:s})}),$&&o.createElement(Ot,{node:$,fields:A?.fields||{},holds:A?.records||{},labels:A?.labels||{},explanations:A?.explanations||{},recordLabels:A?.record_labels||{},recordExplanations:A?.record_explanations||{},recordChoices:A?.record_choices||{},recordOutputsOf:A?.record_outputs_of||{},choices:Bt($,A),onClose:()=>m(null),onSave:s=>p(`/steps/${$.id}`,"PATCH",{config:s}),onPickPicture:y,refusal:a,onDelete:()=>{m(null),p(`/steps/${$.id}`,"DELETE")}}))},ce=Uo;var Go={display:"block",minWidth:118,boxSizing:"border-box",borderRadius:6,padding:"8px 10px",textDecoration:"none"},Xo={fontSize:12,fontWeight:500,lineHeight:1.3},pe={done:"border-green-600 bg-green-50 dark:border-green-500 dark:bg-green-950",paused:"border-amber-500 bg-amber-50 dark:border-amber-400 dark:bg-amber-950",pending:"border-gray-300 bg-white text-gray-500 dark:border-zinc-700 dark:bg-zinc-900 dark:text-gray-400",failed:"border-red-600 bg-red-50 dark:border-red-500 dark:bg-red-950"},ue={done:"text-green-700 dark:text-green-400",paused:"text-amber-800 dark:text-amber-300",pending:"text-gray-500 dark:text-gray-400",failed:"text-red-700 dark:text-red-400"},qo="ring-2 ring-accent-600 ring-offset-2 dark:ring-offset-zinc-950",Jo=({node:t,selected:e=!1})=>{let n=t.address?"a":"div";return o.createElement(n,{"data-step":t.id,href:t.address||void 0,className:`${t.state==="paused"?"border-2":"border"} ${pe[t.state]||pe.pending}${e?` ${qo}`:""}`,style:Go},o.createElement("div",{className:"font-mono text-gray-500 dark:text-gray-400",style:{fontSize:11}},t.type),o.createElement("div",{style:Xo},t.label,t.version&&o.createElement("span",{className:"text-gray-500 dark:text-gray-400",style:{fontWeight:400,marginLeft:4}},t.version)),t.status&&o.createElement("div",{className:ue[t.state]||ue.pending,style:{fontSize:11}},t.status))},me=Jo;var Ko={gap:12,padding:0},Qo=({nodes:t,edges:e,selected:n})=>o.createElement(K,{nodes:t,edges:e,joints:{},style:Ko,draw:r=>r.holds?o.createElement(V,{node:r,header:Y(r,r,!1),compact:!0}):o.createElement(me,{node:r,selected:r.id===n})}),fe=Qo;et("easy_flow/flow-editor",ce);et("easy_flow/run-view",fe);document.addEventListener("easy_flow:flow-named",t=>{let e=document.querySelector("[data-flow-heading]");e&&(e.textContent=t.detail)});bt(document,mt);})();
@@ -12,6 +12,7 @@ module EasyFlow
12
12
  "always_show_insert_buttons" => flow_host.always_show_insert_buttons?,
13
13
  "hide_step_type_codes" => flow_host.hide_step_type_codes?,
14
14
  "direction" => flow_host.canvas_direction.to_s,
15
+ "step_groups" => flow_host.step_groups,
15
16
  "publish_note" => flow_host.publish_note)
16
17
  end
17
18
 
@@ -0,0 +1,12 @@
1
+ require "keystone_ui/react/mount_helper"
2
+
3
+ module EasyFlow
4
+ module RunViewHelper
5
+ include KeystoneUi::React::MountHelper
6
+
7
+ def easy_flow_run_view(version, steps:, selected: nil, **attributes)
8
+ react_ui("easy_flow/run-view", RunView.new(version, steps: steps, selected: selected).to_h,
9
+ data: { flow_run_view: true }, **attributes)
10
+ end
11
+ end
12
+ end
@@ -7,6 +7,7 @@ import Inspector from "./Inspector"
7
7
  import Placeholder from "./Placeholder"
8
8
  import { offeredTo } from "./choices"
9
9
  import TypePicker from "./TypePicker"
10
+ import StepList from "./StepList"
10
11
  import Toolbar from "./Toolbar"
11
12
  import Panel from "./Panel"
12
13
  import ConnectorLayer from "./ConnectorLayer"
@@ -40,6 +41,7 @@ const Canvas = ({ base, token, initial }) => {
40
41
  const [ adding, setAdding ] = useState(null)
41
42
  const [ armed, setArmed ] = useState(null)
42
43
  const [ dragging, setDragging ] = useState(null)
44
+ const [ carrying, setCarrying ] = useState(null)
43
45
  const [ showing, setShowing ] = useState(false)
44
46
  const cards = useRef({})
45
47
  const surface = useRef(null)
@@ -105,6 +107,17 @@ const Canvas = ({ base, token, initial }) => {
105
107
  const selectedNode = flow.nodes.find((node) => node.id === selected)
106
108
  const entryFor = entryOf(selectedNode)
107
109
 
110
+ const addStep = (entry, where = {}) =>
111
+ send("/steps", "POST", { id: nextId(entry.type, flow.nodes.map((node) => node.id)), type: entry.type, from: where.from, to: where.to, on: where.on })
112
+
113
+ const dropOnLink = (link) => {
114
+ const [ entry, held ] = [ carrying, dragging ]
115
+ setCarrying(null)
116
+ setDragging(null)
117
+ if (entry) addStep(entry, { from: link.source, to: link.target })
118
+ else if (held) send("/steps/" + held + "/move", "PATCH", { from: link.source, to: link.target })
119
+ }
120
+
108
121
  const pointed = (event) => {
109
122
  const frame = surface.current.getBoundingClientRect()
110
123
  return { x: event.clientX - frame.left + surface.current.scrollLeft + 8, y: event.clientY - frame.top + surface.current.scrollTop + 8 }
@@ -186,6 +199,8 @@ const Canvas = ({ base, token, initial }) => {
186
199
  <div className="text-gray-900 dark:text-gray-100" style={page} onMouseUp={() => setDragging(null)}
187
200
  onKeyDown={(event) => { if (event.key === "Escape") { setSelected(null); setArmed(null); setAdding(null) } }}
188
201
  tabIndex={-1}>
202
+ <StepList entries={flow.palette} groups={flow.step_groups || {}}
203
+ onPick={(entry) => addStep(entry)} onCarry={setCarrying} onDrop={() => setCarrying(null)} />
189
204
  <div ref={surface} className="bg-surface-50 dark:bg-surface-950" style={scroll}
190
205
  onClick={(event) => { if (event.target === surface.current) { setSelected(null); setArmed(null); setShowing(false) } }}
191
206
  onDragOver={(event) => { if (dragging) event.preventDefault() }}
@@ -203,18 +218,19 @@ const Canvas = ({ base, token, initial }) => {
203
218
  onDrop={() => { const held = dragging; setDragging(null); if (held) send(`/steps/${held}/group`, "PATCH", { group: box.id }) }} />
204
219
  ))}
205
220
 
206
- {!leftToRight && <ConnectorLayer links={linksOutside(links, flow.nodes)} extent={extent} dragging={dragging} alwaysShowInsertButtons={flow.always_show_insert_buttons}
221
+ {!leftToRight && <ConnectorLayer links={linksOutside(links, flow.nodes)} extent={extent} dragging={dragging || carrying} alwaysShowInsertButtons={flow.always_show_insert_buttons}
207
222
  onInsert={(link) => setAdding({ from: link.source, to: link.target, at: { x: link.midX + 30, y: link.midY } })}
208
223
  onRemove={(link) => { setSelected(null); send("/edges", "DELETE", { from: link.source, to: link.target }) }}
209
- onDrop={(link) => { const held = dragging; setDragging(null); send("/steps/" + held + "/move", "PATCH", { from: link.source, to: link.target }) }} />}
224
+ onDrop={dropOnLink} />}
210
225
 
211
226
  {!leftToRight && waitingSteps}
212
227
 
213
228
  {leftToRight && <LeftToRight nodes={attached} edges={flow.edges} draw={draw} joints={{
214
229
  alwaysShowInsertButtons: flow.always_show_insert_buttons,
230
+ dragging: Boolean(dragging || carrying),
215
231
  onInsert: (link, event) => setAdding({ from: link.source, to: link.target, at: pointed(event) }),
216
232
  onRemove: (link) => { setSelected(null); send("/edges", "DELETE", { from: link.source, to: link.target }) },
217
- onDrop: (link) => { const held = dragging; setDragging(null); if (held) send("/steps/" + held + "/move", "PATCH", { from: link.source, to: link.target }) }
233
+ onDrop: dropOnLink
218
234
  }}>{waitingSteps}</LeftToRight>}
219
235
 
220
236
  {!leftToRight && <div style={{ ...grid, gridTemplateColumns: `repeat(${columns + 1}, ${(CARD + GAP_X) / 2}px)`, gridTemplateRows: `repeat(${rows}, auto)` }}>
@@ -231,7 +247,7 @@ const Canvas = ({ base, token, initial }) => {
231
247
  onPick={(entry) => {
232
248
  const where = adding
233
249
  setAdding(null)
234
- send("/steps", "POST", { id: nextId(entry.type, flow.nodes.map((node) => node.id)), type: entry.type, from: where.from, to: where.to, on: where.on })
250
+ addStep(entry, where)
235
251
  }} />
236
252
  )}
237
253
  </div>
@@ -8,7 +8,7 @@ const compactLine = { ...line, width: "auto", whiteSpace: "normal", overflowWrap
8
8
  const GroupHeader = ({ node, header, onSelect, compact = false }) => (
9
9
  <div ref={node.ref} data-group-header={node.id} onClick={onSelect}
10
10
  className="font-mono text-gray-500 dark:text-gray-400"
11
- style={compact ? compactLine : line}>{header}</div>
11
+ style={{ ...(compact ? compactLine : line), ...(onSelect ? {} : { cursor: "default" }) }}>{header}</div>
12
12
  )
13
13
 
14
14
  export default GroupHeader
@@ -5,17 +5,17 @@ const round = { width: 24, height: 24, padding: 0, fontSize: 15, lineHeight: "15
5
5
 
6
6
  const shownOnHover = "opacity-0 transition-opacity group-data-[over=true]:opacity-100"
7
7
 
8
- const Joint = ({ link, onInsert, onRemove, onDrop, alwaysShowInsertButtons }) => (
8
+ const Joint = ({ link, onInsert, onRemove, onDrop, alwaysShowInsertButtons, dragging }) => (
9
9
  <div data-joint={link?.id} className="group relative h-7 w-full sm:h-auto sm:w-7 sm:self-stretch"
10
10
  onMouseEnter={(event) => { event.currentTarget.dataset.over = "true" }}
11
11
  onMouseLeave={(event) => { delete event.currentTarget.dataset.over }}
12
- onDragOver={(event) => { if (link) { event.preventDefault(); event.dataTransfer.dropEffect = "move" } }}
12
+ onDragOver={(event) => { if (link && onDrop) { event.preventDefault(); event.dataTransfer.dropEffect = "move" } }}
13
13
  onDrop={(event) => { if (!link) return; event.preventDefault(); onDrop(link) }}>
14
14
  {link && <div className="absolute left-1/2 top-0 h-full w-px bg-gray-400 sm:left-0 sm:top-1/2 sm:h-px sm:w-full dark:bg-zinc-500" />}
15
- {link && (
15
+ {link && onInsert && (
16
16
  <div className="absolute inset-0 flex items-center justify-center gap-1 sm:flex-col" style={{ zIndex: 4 }}>
17
17
  <Button variant="secondary" title="Insert a step here" onClick={(event) => onInsert(link, event)}
18
- className={`rounded-full ${alwaysShowInsertButtons ? "opacity-100" : shownOnHover}`} style={round}>+</Button>
18
+ className={`rounded-full ${alwaysShowInsertButtons ? "opacity-100" : shownOnHover}`} style={dragging ? { ...round, opacity: 1 } : round}>+</Button>
19
19
  <Button variant="danger" title="Remove this connection" onClick={() => onRemove(link)} className={`rounded-full ${shownOnHover}`} style={round}>×</Button>
20
20
  </div>
21
21
  )}
@@ -24,8 +24,8 @@ const Box = ({ group, steps, edges, draw, joints }) => (
24
24
  </div>
25
25
  )
26
26
 
27
- const LeftToRight = ({ nodes, edges, draw, joints, children }) => (
28
- <div data-flow-rows style={stack}>
27
+ const LeftToRight = ({ nodes, edges, draw, joints, children, style }) => (
28
+ <div data-flow-rows style={{ ...stack, ...style }}>
29
29
  {children}
30
30
  {blocksOf(nodes).map((block) => (block.group
31
31
  ? <Box key={block.group.id} group={block.group} steps={block.steps} edges={edges} draw={draw} joints={joints} />
@@ -0,0 +1,35 @@
1
+ import React from "react"
2
+
3
+ const card = { display: "block", minWidth: 118, boxSizing: "border-box", borderRadius: 6, padding: "8px 10px", textDecoration: "none" }
4
+
5
+ const named = { fontSize: 12, fontWeight: 500, lineHeight: 1.3 }
6
+
7
+ const STATES = {
8
+ done: "border-green-600 bg-green-50 dark:border-green-500 dark:bg-green-950",
9
+ paused: "border-amber-500 bg-amber-50 dark:border-amber-400 dark:bg-amber-950",
10
+ pending: "border-gray-300 bg-white text-gray-500 dark:border-zinc-700 dark:bg-zinc-900 dark:text-gray-400",
11
+ failed: "border-red-600 bg-red-50 dark:border-red-500 dark:bg-red-950"
12
+ }
13
+
14
+ const STATUS_LINES = {
15
+ done: "text-green-700 dark:text-green-400",
16
+ paused: "text-amber-800 dark:text-amber-300",
17
+ pending: "text-gray-500 dark:text-gray-400",
18
+ failed: "text-red-700 dark:text-red-400"
19
+ }
20
+
21
+ const marked = "ring-2 ring-accent-600 ring-offset-2 dark:ring-offset-zinc-950"
22
+
23
+ const RunCard = ({ node, selected = false }) => {
24
+ const Card = node.address ? "a" : "div"
25
+
26
+ return (
27
+ <Card data-step={node.id} href={node.address || undefined} className={`${node.state === "paused" ? "border-2" : "border"} ${STATES[node.state] || STATES.pending}${selected ? ` ${marked}` : ""}`} style={card}>
28
+ <div className="font-mono text-gray-500 dark:text-gray-400" style={{ fontSize: 11 }}>{node.type}</div>
29
+ <div style={named}>{node.label}{node.version && <span className="text-gray-500 dark:text-gray-400" style={{ fontWeight: 400, marginLeft: 4 }}>{node.version}</span>}</div>
30
+ {node.status && <div className={STATUS_LINES[node.state] || STATUS_LINES.pending} style={{ fontSize: 11 }}>{node.status}</div>}
31
+ </Card>
32
+ )
33
+ }
34
+
35
+ export default RunCard
@@ -0,0 +1,15 @@
1
+ import React from "react"
2
+ import LeftToRight from "./LeftToRight"
3
+ import GroupHeader from "./GroupHeader"
4
+ import RunCard from "./RunCard"
5
+ import { headerOf } from "./group"
6
+
7
+ const rows = { gap: 12, padding: 0 }
8
+
9
+ const RunView = ({ nodes, edges, selected }) => (
10
+ <LeftToRight nodes={nodes} edges={edges} joints={{}} style={rows} draw={(node) => (node.holds
11
+ ? <GroupHeader node={node} header={headerOf(node, node, false)} compact />
12
+ : <RunCard node={node} selected={node.id === selected} />)} />
13
+ )
14
+
15
+ export default RunView
@@ -0,0 +1,47 @@
1
+ import React, { useState } from "react"
2
+ import Panel from "keystone_ui-react/src/Panel.jsx"
3
+ import Input from "keystone_ui-react/src/Input.jsx"
4
+
5
+ const matching = (query) => (entry) => entry.label.toLowerCase().includes(query.trim().toLowerCase())
6
+
7
+ export const listed = (entries, groups, query = "") => {
8
+ const grouped = Object.values(groups).flat()
9
+ const sections = Object.entries(groups).map(([ heading, types ]) => ({
10
+ heading,
11
+ entries: types.map((type) => entries.find((entry) => entry.type === type)).filter(Boolean)
12
+ }))
13
+
14
+ return [ { heading: null, entries: entries.filter((entry) => !grouped.includes(entry.type)) }, ...sections ]
15
+ .map((section) => ({ ...section, entries: section.entries.filter(matching(query)) }))
16
+ .filter((section) => section.entries.length > 0)
17
+ }
18
+
19
+ const sidebar = { width: 200, flex: "none", boxSizing: "border-box", padding: "14px 12px", gap: 6, fontSize: 12, overflowY: "auto", borderWidth: "0 1px 0 0" }
20
+
21
+ const heading = { fontSize: 11, textTransform: "uppercase", letterSpacing: ".04em", padding: "8px 4px 2px" }
22
+
23
+ const item = { textAlign: "left", padding: "7px 9px", borderRadius: 6, fontSize: 12, cursor: "grab" }
24
+
25
+ const StepList = ({ entries, groups, onPick, onCarry, onDrop }) => {
26
+ const [ query, setQuery ] = useState("")
27
+
28
+ return (
29
+ <Panel as="aside" aria-label="Steps" data-step-list className="hidden flex-col sm:flex" style={sidebar}>
30
+ <Input type="search" aria-label="Search steps" placeholder="Search steps" value={query}
31
+ onChange={(event) => setQuery(event.target.value)} style={{ marginBottom: 6, fontSize: 12 }} />
32
+ {listed(entries, groups, query).map((section) => (
33
+ <React.Fragment key={section.heading || ""}>
34
+ {section.heading && <div className="text-gray-500 dark:text-gray-400" style={heading}>{section.heading}</div>}
35
+ {section.entries.map((entry) => (
36
+ <Panel as="button" type="button" key={entry.type} data-step-type={entry.type} className="bg-surface-50 dark:bg-surface-950" style={item} draggable
37
+ onClick={() => onPick(entry)}
38
+ onDragStart={(event) => { event.dataTransfer.effectAllowed = "copyMove"; event.dataTransfer.setData("text/plain", entry.type); onCarry(entry) }}
39
+ onDragEnd={onDrop}>{entry.label}</Panel>
40
+ ))}
41
+ </React.Fragment>
42
+ ))}
43
+ </Panel>
44
+ )
45
+ }
46
+
47
+ export default StepList
@@ -2,8 +2,10 @@ import { createRoot } from "react-dom/client"
2
2
  import { register } from "keystone_ui-react/src/registry.js"
3
3
  import { startMounting } from "keystone_ui-react/src/mounting.js"
4
4
  import Canvas from "./canvas/Canvas"
5
+ import RunView from "./canvas/RunView"
5
6
 
6
7
  register("easy_flow/flow-editor", Canvas)
8
+ register("easy_flow/run-view", RunView)
7
9
 
8
10
  document.addEventListener("easy_flow:flow-named", (event) => {
9
11
  const heading = document.querySelector("[data-flow-heading]")
@@ -0,0 +1,56 @@
1
+ module EasyFlow
2
+ class RunView
3
+ def initialize(version, steps: {}, selected: nil, registry: EasyFlow.registry)
4
+ @document = Document.new(version.definition || {}, registry: registry)
5
+ @steps = steps.to_h.transform_keys(&:to_s)
6
+ @selected = selected
7
+ @registry = registry
8
+ end
9
+
10
+ def to_h
11
+ { "nodes" => nodes, "edges" => edges, "selected" => @selected&.to_s }
12
+ end
13
+
14
+ private
15
+
16
+ def nodes
17
+ @document.nodes.reject { |node| bookend?(node) }.map { |node| drawn_step(node) }
18
+ end
19
+
20
+ def edges
21
+ @document.edges.each_with_index.map do |edge, index|
22
+ { "id" => "#{edge.from}-#{edge.to}-#{index}", "source" => edge.from, "target" => edge.to, "label" => edge.on&.to_s }
23
+ end
24
+ end
25
+
26
+ def placed
27
+ @placed ||= Layout.new(@document).positions
28
+ end
29
+
30
+ def bookend?(node)
31
+ step_type = step_type_for(node)
32
+ step_type.present? && (step_type.begins_here? || step_type.ends_here?)
33
+ end
34
+
35
+ def holds(node)
36
+ Array(node.config["holds"]) if step_type_for(node)&.holds_steps?
37
+ end
38
+
39
+ def step_type_for(node)
40
+ @registry.fetch(node.type) if @registry.registered?(node.type)
41
+ end
42
+
43
+ def drawn_step(node)
44
+ shown = @steps.fetch(node.id, {}).to_h.symbolize_keys
45
+
46
+ { "id" => node.id, "type" => node.type, "label" => Name.of(node, @registry), "state" => shown[:state]&.to_s, "status" => shown[:status], "address" => shown[:address], "version" => shown[:version],
47
+ "holds" => holds(node), **header_of(node), **placed.fetch(node.id, {}) }
48
+ end
49
+
50
+ def header_of(node)
51
+ return {} unless step_type_for(node)&.holds_steps?
52
+
53
+ { "config" => node.config, "fields" => step_type_for(node).settings.fields.transform_keys(&:to_s).transform_values(&:to_s) }
54
+ end
55
+ end
56
+ end
@@ -13,6 +13,10 @@ module EasyFlow
13
13
  KeystoneUi.configuration.tailwind_sources << root.join("app/assets/builds/easy_flow/*.js").to_s
14
14
  end
15
15
 
16
+ initializer "easy_flow.run_view_helper" do
17
+ ActiveSupport.on_load(:action_view) { include EasyFlow::RunViewHelper }
18
+ end
19
+
16
20
  initializer "easy_flow.step_types" do |app|
17
21
  app.config.to_prepare do
18
22
  EasyFlow::Start.register
@@ -61,6 +61,14 @@ module EasyFlow
61
61
  @hide_step_type_codes.present?
62
62
  end
63
63
 
64
+ def step_groups=(groups)
65
+ @step_groups = groups.to_h { |heading, step_types| [ heading.to_s, step_types.map(&:to_s) ] }
66
+ end
67
+
68
+ def step_groups
69
+ @step_groups || {}
70
+ end
71
+
64
72
  def explanation_for(step_type, setting)
65
73
  @setting_explanations.to_h.dig(step_type.to_s, setting.to_s).presence
66
74
  end
@@ -1,3 +1,3 @@
1
1
  module EasyFlow
2
- VERSION = "0.42.0"
2
+ VERSION = "0.44.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-develop
3
- description: Use PROACTIVELY for adding a step type to easy_flow flows (a step that asks the visitor something, takes several answers at once, computes a value from earlier answers, records several values under names an admin enters in the step's settings, counts how many times an earlier step was answered so a loop can give up after a number of tries, picks the next branch, or holds the visitor until something outside the flow has happened), adding a step type an admin draws as a box that holds other steps on the canvas, such as a "for each" step, branching on whether all or any of several comparisons of earlier answers hold, holding a run until a number of minutes after an earlier answer, the next time of day after it, or a date, branching on the hour, weekday or time an earlier step was completed or on the minutes between two completed steps, reading when each step was completed and when a waiting run will move on, showing a step differently depending on the visitor's stored run, branching on what a visitor ticked on a checklist, moving a paused run on once what it waits for has happened, refusing a blank or invalid answer to a step with a message, offering an admin a step setting whose options are read from the app's own records, letting an admin pick another flow of the same host in a step's settings, adding a step type that starts another flow and works out which flow and version to run from its own settings, adding a step type that starts another flow chosen from the visitor's run, such as its owner or its answers, offering a visitor only the answers to a step that their earlier answers allow, filling in a step that has only one possible answer without asking it, skipping a step that does not apply to a visitor, letting an admin edit a value stored on one of the app's own records from a step's settings on the canvas, serving a host's flows from the app's own controller and routes, starting a visitor's run on a published version of a flow other than the live one, acting when a visitor finishes a flow, acting on the output a visitor's flow ended with, telling whether a run ended at an End step or was stopped by a loop that came back with nothing new answered and at which step, keeping a flow from being published while a step that starts another flow names a flow or version that cannot run or leads back to the flow it sits in, finding the run of another flow that a Flow step started, the run a waiting run is waiting on, and the run that started it, sending a visitor back to the run that started a flow once that flow ends, handling a run whose starting run was removed with its flow, handling a Flow step that cannot start its flow, whose flow ended with no output, or whose flow was stopped by a loop, taking one file or several from a visitor at a step, showing a 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, and showing on the app's own page where a run stands, with each step's state, status line and link — MUST BE USED instead of hand-rolling questionnaire steps, checkbox lists, file upload steps, branching logic, answer lists filtered by earlier answers, skipped questions, number comparisons, comparisons of two earlier answers, and/or conditions over several comparisons, hard-coded setting options, copying a record's value into a flow and back, answer validation, retry counters, timers or scheduled delays, step completion timestamps, polling or "come back later" pages, flow controllers, answer lookups or hand-drawn run diagrams.
4
4
  tools: Read, Write, Edit, Grep
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -25,6 +25,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
25
25
  - `run_address` — private method a `FlowsController` subclass overrides to give the value put in a run's address in place of its id.
26
26
  - `find_run` — private method a `FlowsController` subclass overrides to find a run, among the host's own runs, from the value in its address.
27
27
  - `EasyFlow::Run` — the stored record of one visitor's pass through a flow, started with `EasyFlow::Run.start` on the live version or a chosen published one and pinned to that version, moved on past a waiting step with `advance`, read for the output its flow ended with by `output`, for the mark of the End it reached by `end_mark`, for whether it ended at an End step by `ended_at_end?`, for the step a loop stopped it at by `stopped_on_loop`, for when each step visit was completed by `completed_at` and for the time a Wait step holds it until by `held_until`, and linked to the runs its Flow steps started by `inner_runs`, to the one it is waiting on by `waiting_on`, and to the run that started it by `parent_run`.
28
+ - `easy_flow_run_view(version, steps:, selected: nil)` — a view helper every view in the app can call, drawing a read-only view of one flow version's steps with the state, status line, version and address the app supplies for each step.
28
29
  - `EasyFlow::QuestionRunner` — reads a flow document: its steps, the next step for a set of answers and the times their steps were completed, the answers on the path taken, and a question's text and an answer's label.
29
30
 
30
31
  ## How to use it
@@ -548,6 +549,35 @@ Use this when a visitor's run should stop until a set time has passed, such as a
548
549
  - In a flow set to save on finish or to save nothing, the waiting page also shows a `Check again` button, which loads the page again with the answers and the times their steps were completed, so the Wait moves on once its time has passed. Reloading the page in the browser instead takes the completion time of the step just submitted again, so a Wait counting minutes or a time of day from that step does not move on by reloading. Ask the developer whether such a flow needs to be set to save each step.
549
550
  4. Publish a flow set to save each step with a Wait step counting a few minutes from a question, walk it to the Wait step, check the page shows `Waiting for <minutes> minutes after <question id>.` and `run.held_until` is that many minutes after the answer, and check `run.advance` after that time moves the run on. In a flow set to save nothing, walk to the same Wait step, wait past the time, press `Check again`, and check the next step is shown.
550
551
 
552
+ ### Show where a run stands on the app's own page
553
+
554
+ 1. Put the two scripts the view needs in the page's head, the same ones the canvas uses:
555
+
556
+ ```erb
557
+ <% content_for :head do %>
558
+ <%= javascript_include_tag "keystone_ui/react", defer: true %>
559
+ <%= javascript_include_tag "easy_flow/canvas", defer: true %>
560
+ <% end %>
561
+ ```
562
+
563
+ 2. Call the helper with the flow version the run is on and one entry per step id:
564
+
565
+ ```erb
566
+ <%= easy_flow_run_view(run.definition_version,
567
+ steps: { "outline" => { state: :done, status: "8.2s · $0.04", version: "v9", address: run_step_path(run, "outline") },
568
+ "human_approve" => { state: :paused, status: "waiting · expires 46h", address: run_step_path(run, "human_approve") } },
569
+ selected: "outline") %>
570
+ ```
571
+
572
+ - `state` — `:done`, `:paused`, `:pending` or `:failed`, shown on the card's edge. A paused step's edge is thicker than the others. A step with no state or an unknown one is drawn as pending.
573
+ - `status` — one line of text under the step's name, written in the colour of its state. The app works it out; easy_flow does not.
574
+ - `version` — optional text written after the step's name, such as `v9`.
575
+ - `address` — optional. A card with one is a link to it, and a card without one is not a link.
576
+ - `selected` — the id of one step whose card is ringed in the accent colour, such as the step whose details the page shows.
577
+ - Any other keyword is passed to the wrapping element, such as `class:`.
578
+ 3. The view lays the steps out left to right whatever the host's `canvas_direction`, as compact cards in rows joined by short lines. A group step's box takes a row of its own with its header line and the steps it holds. On a screen narrower than 640 pixels each step sits on a row of its own. The Start and End steps are left out. It has no buttons and nothing on it changes the flow.
579
+ 4. Ask the developer what each step's status line says and where each card links. Do not pick.
580
+
551
581
  ### Read a run and its answers
552
582
 
553
583
  1. Find runs scoped to one host so one host never sees another's: `EasyFlow::Run.joins(:flow).where(easy_flow_definitions: { host: "intake" })`.
@@ -104,6 +104,8 @@ easy_flow declares no commands of its own for this local. Its surface is split b
104
104
  - **Always-visible insert buttons** — a setting a host may turn on, `always_show_insert_buttons`, that shows each connection's button for inserting a step on its canvas without the pointer over the connection, with the connection's label moved to the right of the line. It is off by default, and with it off the button shows only with the pointer over the connection.
105
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.
106
106
  - **Canvas direction** — a setting a host may set, `canvas_direction`, to `:left_to_right` to lay its canvas out left to right in place of top to bottom. Steps sit as compact cards in rows joined by short lines, a row that reaches the edge of the canvas goes on in a new row, each branch or loop that leads anywhere but the step beside it is written on its step's card with the step it leads to, a group step's box takes a row of its own, and a phone-width screen shows one step per row. Top to bottom is the default.
107
+ - **Step list** — a list beside the editing canvas, on screens 640 pixels and wider, of every step type the host offers, with a search field that keeps only the types whose name holds what was typed. A host may set `step_groups`, a hash of headings each with the step types listed under it, in the host's order, and the types it puts in no group are listed above the first heading. Clicking a type adds the step unconnected, as the add menu does, and dragging a type onto a connection inserts the step on that connection. On a phone the list is hidden and the add menu is the way to add steps.
108
+ - **Run view** — a read-only view of one flow version that an app draws on its own page with `easy_flow_run_view`, showing each step as a compact card with its type code, name, the version and status line the app supplies, and an edge coloured by the state the app supplies, done, paused, pending or failed. A paused step's edge is thicker, the step the app names as selected is ringed, a card the app gives an address is a link to it, and steps sit left to right as on a left-to-right canvas, with a group step's box holding its steps and one card per row on a phone. It has no editing controls.
107
109
  - **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.
108
110
  - **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`.
109
111
  - **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.
@@ -61,6 +61,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
61
61
  - `always_show_insert_buttons` — set to `true` to show each connection's button for inserting a step on this host's canvas without the pointer over the connection. A connection's label then sits to the right of the line so the button does not cover it. With none set, the button shows only with the pointer over the connection.
62
62
  - `hide_step_type_codes` — set to `true` to hide step type code names on this host's canvas. The add menu then lists each step type by its name alone, and a step's box shows its step type's name in place of the code name. With none set, the add menu and step boxes show the code names. The settings panel shows a step's id and code name either way.
63
63
  - `canvas_direction` — set to `:left_to_right` to lay this host's canvas out left to right. Steps then sit as compact cards in rows joined by short lines, and a row that reaches the edge of the canvas goes on in a new row below it. A step whose branch or loop leads anywhere other than the step beside it, or whose branch carries an answer, writes each such branch on its card as the answer, an arrow and the step it leads to. A group step's box takes a row of its own, with its steps in a row inside it under its header line. On a screen narrower than 640 pixels, each step sits on a row of its own. With none set, or with `:top_to_bottom`, the canvas is laid out top to bottom as before.
64
+ - `step_groups` — a hash of the headings this host's canvas step list shows, each with the step types listed under it by name, such as `{ "Agents" => [ :question, :checklist ], "Control" => [ :switch, :wait ] }`. Headings appear in the order given. Offered step types the hash leaves out are listed above the first heading, and a type the host does not offer is not listed. With none set, the list shows every offered step type under no heading. Ask the developer how each host's step types should be grouped.
64
65
  - `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.
65
66
  - `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.
66
67
  - `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`.
@@ -164,6 +165,8 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
164
165
  - 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.
165
166
  - 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.
166
167
  - After setting `canvas_direction` to `:left_to_right` on a host, check that its canvas shows the steps in rows joined by short lines, that a branch or loop to a step not beside it is written on its step's card, and that a phone-width screen shows one step per row.
168
+ - A page of the app that calls `easy_flow_run_view` needs the `keystone_ui/react` and `easy_flow/canvas` scripts in its head, the same two the canvas page loads. The helper needs no setting in the initializer, and it is available in every view of the app. After adding one, check that the page shows each step's card with the state and status line the app supplied, and that a phone-width screen shows one card per row.
169
+ - After setting `step_groups` on a host, check that its canvas shows the step list beside the canvas with each step type under its heading, that typing in its search field narrows the list, that clicking a type adds an unconnected step, that dragging a type onto a connection inserts it there, and that a phone-width screen shows no step list.
167
170
  - 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.
168
171
  - 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.
169
172
  - 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.42.0
4
+ version: 0.44.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -76,6 +76,7 @@ files:
76
76
  - app/controllers/easy_flow/manage/previews_controller.rb
77
77
  - app/controllers/easy_flow/manage/versions_controller.rb
78
78
  - app/helpers/easy_flow/app_routes_helper.rb
79
+ - app/helpers/easy_flow/run_view_helper.rb
79
80
  - app/javascript/easy_flow/canvas.jsx
80
81
  - app/javascript/easy_flow/canvas/Canvas.jsx
81
82
  - app/javascript/easy_flow/canvas/Connector.jsx
@@ -91,7 +92,10 @@ files:
91
92
  - app/javascript/easy_flow/canvas/Placeholder.jsx
92
93
  - app/javascript/easy_flow/canvas/Port.jsx
93
94
  - app/javascript/easy_flow/canvas/Records.jsx
95
+ - app/javascript/easy_flow/canvas/RunCard.jsx
96
+ - app/javascript/easy_flow/canvas/RunView.jsx
94
97
  - app/javascript/easy_flow/canvas/StepCard.jsx
98
+ - app/javascript/easy_flow/canvas/StepList.jsx
95
99
  - app/javascript/easy_flow/canvas/Toolbar.jsx
96
100
  - app/javascript/easy_flow/canvas/TypePicker.jsx
97
101
  - app/javascript/easy_flow/canvas/changes.js
@@ -140,6 +144,7 @@ files:
140
144
  - app/models/easy_flow/read_data.rb
141
145
  - app/models/easy_flow/registry.rb
142
146
  - app/models/easy_flow/run.rb
147
+ - app/models/easy_flow/run_view.rb
143
148
  - app/models/easy_flow/runner.rb
144
149
  - app/models/easy_flow/settings.rb
145
150
  - app/models/easy_flow/start.rb