CoreFiles by mySites.guru
workflow-graph-client.min.js23 lines, 12,301 bytes, from Joomla_6.2.0-beta2-Beta-Full_Package.zip
Raw History Compare with 6.2.0-beta1
md5
41dd8e0b2d774a4bb9275678ad0e8df7
sha1
c340fd5de9fdf5c4bbc292abe4b84353e6225111
sha256
2d3caa4381d340ce6a21160327a8ce00dac181c8f7973f781d48181231aedcf9
function _extends(){return _extends=Object.assign?Object.assign.bind():function($){for(var M=1;M<arguments.length;M++){var A=arguments[M];for(var b in A)({}).hasOwnProperty.call(A,b)&&($[b]=A[b])}return $},_extends.apply(null,arguments)}/**
 * @copyright (C) 2026 Open Source Matters
 * @license  GNU GPL v2 or later; see LICENSE.txt
 */Joomla=window.Joomla||{},(()=>{const e={workflow:null,stages:[],transitions:[],scale:1,panX:0,panY:0,isDraggingStage:!1,highlightedEdge:null},E=t=>Joomla.Text._(t),H=(t,...a)=>{const l=Joomla.Text._(t,t);let d=0;return l.replace(/%((%)|s|d)/g,n=>{let r=a[d];return n==="%d"&&(r=parseFloat(r),Number.isNaN(r)&&(r=0)),d+=1,r})},G=t=>`url(${window.location.href.split("#")[0]}#${t})`;function v(t,a){const l={};l[a]=[Joomla.Text._(t)],Joomla.renderMessages(l);{const d=document.querySelector("joomla-dialog");d&&d.close()}}async function T(t){try{const a=Joomla.getOptions("system.paths"),d=`${`${a?`${a.baseFull}index.php`:window.location.pathname}`}?option=com_workflow&extension=com_content&layout=modal&view=graph${t}`,n=await fetch(d,{credentials:"same-origin"});if(!n.ok){let u="COM_WORKFLOW_GRAPH_ERROR_UNKNOWN";throw n.status===401?u="COM_WORKFLOW_GRAPH_ERROR_NOT_AUTHENTICATED":n.status>=403?u="COM_WORKFLOW_GRAPH_ERROR_NO_PERMISSION":n.status!=200&&(u=H("COM_WORKFLOW_GRAPH_ERROR_REQUEST_FAILED",n.status)),new Error(u)}const r=await n.json();if(r.success===!1)throw new Error(r.message||"COM_WORKFLOW_GRAPH_ERROR_API_RETURNED_ERROR");return r}catch(a){return v(a.message,"error"),!1}}function D(t){const a=t.filter(i=>!i.position||isNaN(i.position.x)||isNaN(i.position.y));if(a.length===0)return t;const l=t.find(i=>i.id==="from_any"),d=t.filter(i=>i.id!=="from_any"),n=400,r=300,u=100,p=100,o=Math.min(4,Math.ceil(Math.sqrt(d.length)+1));return d.forEach((i,g)=>{if(a.some(s=>s.id===i.id)){const s=g%o,c=Math.floor(g/o);i.position={x:s*n+u,y:c*r+p}}}),l&&a.some(i=>i.id===l.id)&&(!l.position||isNaN(l.position.x)||isNaN(l.position.y))&&(l.position={x:600,y:-200}),t}function W(t){let a=`M ${t[0].x} ${t[0].y-50}`;for(let l=1;l<t.length-1;l++){const d=t[l-1],n=t[l],r=t[l+1],u=d.x-n.x,p=d.y-n.y,o=Math.sqrt(u*u+p*p),i=r.x-n.x,g=r.y-n.y,s=Math.sqrt(i*i+g*g);if(o<1||s<1){a+=` L ${n.x} ${n.y}`;continue}const c=Math.min(10,o/2,s/2),f=n.x+u/o*c,h=n.y+p/o*c,_=n.x+i/s*c,y=n.y+g/s*c;a+=` L ${f} ${h}`,a+=` Q ${n.x} ${n.y} ${_} ${y}`}return a+=` L ${t[t.length-1].x} ${t[t.length-1].y}`,a}function P(t,a,l,d,n){return[W([{x:t,y:a},{x:t,y:n},{x:l,y:n},{x:l,y:d}]),(t+l)/2,n]}function Y(t,a,l,d,n){const r=a+30,u=d-30;return[W([{x:t,y:a},{x:t,y:r},{x:n,y:r},{x:n,y:u},{x:l,y:u},{x:l,y:d}]),n,(r+u)/2]}function q(t,a){const l=new Map(a.map(n=>[n.id,n])),d={};return t.forEach(n=>{const r=n.from_stage_id===-1?"from_any":n.from_stage_id,u=n.to_stage_id,p=String(r),o=String(u),i=p<o?`${p}|${o}`:`${o}|${p}`;d[i]||(d[i]=[]),d[i].push(n)}),Object.values(d).forEach(n=>n.sort((r,u)=>r.id-u.id)),t.flatMap(n=>{const r=n.from_stage_id===-1?"from_any":n.from_stage_id,u=n.to_stage_id,p=l.get(r),o=l.get(u);if(!(p!=null&&p.position)||!(o!=null&&o.position))return[];const i=p.position.x+200/2,g=p.position.y+100,s=o.position.x+200/2,c=o.position.y,f=String(r),h=String(u),_=f<h?`${f}|${h}`:`${h}|${f}`,y=d[_]||[n];let x=y.findIndex(m=>m.id===n.id)-(y.length-1)/2;const w=40;let R,L,I,k=!1;const N=Math.abs(i-s);if(N<200&&c>g&&(k=a.some(m=>{if(m.id===r||m.id===u)return!1;const K=m.position.y,j=m.position.y+100,B=K>g&&j<c,U=m.position.x,z=m.position.x+200,C=i,Z=C>U-20&&C<z+20;return B&&Z})),c>g+50&&!k&&N>40){let m=(g+c)/2;m+=x*w,[R,L,I]=P(i,g,s,c,m),L+=x*60}else{let m=(i+s)/2;(N<200||k)&&(m=Math.max(i,s)+200/2+60),m+=x*w,[R,L,I]=Y(i,g,s,c,m),I+=x*35}return{id:`transition-${n.id}`,pathData:R,label:n.title,labelPosition:{x:L,y:I},fromId:r,toId:u}}).filter(Boolean)}function S(t){const a=t.querySelector("#graph"),l=t.querySelector("#stages"),d=t.querySelector("#connections");if(!a||!l||!d)return;l.querySelectorAll('[id^="stage-"]').forEach(o=>o.remove()),e.stages.forEach(o=>{let i=document.createElement("div");i.id=`stage-${o.id}`,i.addEventListener("mousedown",c=>{c.button===0&&X(c,o)});const g=o.id==="from_any";i.className=`stage ${o.default?"default":""} ${g?"virtual":""}`,i.style.left=`${o.position.x}px`,i.style.top=`${o.position.y}px`;let s=g?`<div class="stage-title text-truncate">${o.title}</div>
           <div class="d-flex justify-content-between align-items-center mt-2"><div class="badge bg-info rounded-pill p-1"></div></div>`:`<div class="stage-title text-truncate" title="${o.title}">${o.title}</div>
           <div class="d-flex align-items-center gap-2">
             ${o.description?`<div class="stage-description text-truncate small">${o.description}</div>`:""}
           </div>
           <div class="d-flex justify-content-between align-items-center mt-2">
             ${typeof o.published<"u"?`<div class="badge ${o.published=="1"?"bg-success":"bg-danger"} rounded-pill p-1">${o.published=="1"?E("COM_WORKFLOW_GRAPH_ENABLED"):E("COM_WORKFLOW_GRAPH_DISABLED")}</div>`:""}
             ${o.default?`<div class="badge bg-warning rounded-pill p-1">${E("COM_WORKFLOW_GRAPH_DEFAULT")}</div>`:""}
           </div>`;i.innerHTML=s,l.appendChild(i)});let n=d.querySelector("g.layers-paths"),r=d.querySelector("g.layers-labels");n||(n=document.createElementNS("http://www.w3.org/2000/svg","g"),n.classList.add("layers-paths"),d.appendChild(n)),r||(r=document.createElementNS("http://www.w3.org/2000/svg","g"),r.classList.add("layers-labels")),d.appendChild(r);const u=q(e.transitions,e.stages);n.querySelectorAll("path[data-edge-id]").forEach(o=>{u.find(i=>i.id===o.dataset.edgeId)||o.remove()}),r.querySelectorAll("foreignObject[data-edge-id]").forEach(o=>{u.find(i=>i.id===o.dataset.edgeId)||o.remove()}),u.forEach(o=>{let i=n.querySelector(`path[data-edge-id="${o.id}"]`);i||(i=document.createElementNS("http://www.w3.org/2000/svg","path"),i.dataset.edgeId=o.id,i.setAttribute("class","transition-path"),n.appendChild(i)),i.setAttribute("d",o.pathData),i.classList.toggle("highlighted",e.highlightedEdge===o.id),i.setAttribute("marker-end",G("arrowhead"));let g=r.querySelector(`foreignObject[data-edge-id="${o.id}"]`),s;g?s=g.querySelector("div"):(g=document.createElementNS("http://www.w3.org/2000/svg","foreignObject"),g.dataset.edgeId=o.id,g.style.overflow="visible",s=document.createElement("div"),s.className="transition-label-content",s.addEventListener("click",c=>{c.stopPropagation(),e.highlightedEdge=e.highlightedEdge===o.id?null:o.id,S(t)}),g.appendChild(s),r.appendChild(g)),s.textContent=o.label,s.classList.toggle("highlighted",e.highlightedEdge===o.id),a.style.transform=`translate(${e.panX}px, ${e.panY}px) scale(${e.scale})`,requestAnimationFrame(()=>{s.style.width="max-content";const c=s.getBoundingClientRect();if(c.width===0&&c.height===0)return;const f=c.width/e.scale,h=c.height/e.scale||24;g.setAttribute("width",f+4),g.setAttribute("height",h+4),g.setAttribute("x",o.labelPosition.x-f/2),g.setAttribute("y",o.labelPosition.y-h/2)})});const p=t.querySelector("#workflow-graph");if(p){const o=Math.max(.3,Math.min(1,e.scale)),i=20*e.scale;p.style.backgroundImage=`
        radial-gradient(circle,
          color-mix(in srgb, var(--body-color) 80%, transparent) 0px,
          color-mix(in srgb, var(--body-color) 60%, transparent) ${o}px,
          transparent ${o*2}px
        )
      `,p.style.backgroundSize=`${i}px ${i}px`,p.style.backgroundPosition=`${e.panX}px ${e.panY}px`}}function X(t,a){if(a.id==="from_any")return;const l=document.getElementById(`stage-${a.id}`);e.isDraggingStage=!0;const d={x:t.clientX,y:t.clientY,stageX:a.position.x,stageY:a.position.y};l.classList.add("dragging");const n=u=>{const p=d.stageX+(u.clientX-d.x)/e.scale,o=d.stageY+(u.clientY-d.y)/e.scale,i=e.stages.find(g=>g.id===a.id);i&&(i.position.x=p,i.position.y=o),S(document.querySelector("#workflow-graph"))},r=()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),l.classList.remove("dragging"),e.isDraggingStage=!1};document.addEventListener("mousemove",n),document.addEventListener("mouseup",r)}async function F(t){const a=t.querySelector("#workflow-graph"),l=t.querySelector("#graph");if(!a||a.dataset.initialized)return;a.dataset.initialized="true";const d=a.querySelector("#workflow-container"),n=parseInt(d.dataset.workflowId,10);if(!n)return v("COM_WORKFLOW_GRAPH_ERROR_INVALID_ID","error");t.querySelector("#connections").innerHTML=`<defs>
      <marker id="arrowhead" viewBox="0 0 10 10" refX="10" refY="5"
        markerWidth="6" markerHeight="6" orient="auto">
        <path d="M 0 0 L 10 5 L 0 10 z" fill="#2071c6" />
      </marker>
    </defs>`;try{const s=await T(`&task=graph.getWorkflow&workflow_id=${n}&format=json`);if(!s)return;const c=await T(`&task=graph.getStages&workflow_id=${n}&format=json`);if(!c)return;const f=await T(`&task=graph.getTransitions&workflow_id=${n}&format=json`);if(!f)return;e.workflow=s?.data||{};let h=c?.data||[];if(e.transitions=f?.data||[],!h.length)return v("COM_WORKFLOW_GRAPH_ERROR_STAGES_NOT_FOUND","error");e.transitions.some(w=>w.from_stage_id===-1)&&!h.some(w=>w.id==="from_any")&&h.unshift({id:"from_any",title:E("COM_WORKFLOW_GRAPH_FROM_ANY"),position:null}),e.stages=h.map(w=>_extends({},w,{position:w.position||{x:NaN,y:NaN}})),e.stages=D(e.stages),t.querySelector(".joomla-dialog-header h3").textContent=e.workflow.title||E("COM_WORKFLOW_GRAPH_WORKFLOW");const _=t.querySelector("#workflow-status-badge");_&&(_.textContent=e.workflow.published=="1"?E("COM_WORKFLOW_GRAPH_ENABLED"):E("COM_WORKFLOW_GRAPH_DISABLED"),_.classList.add(e.workflow.published=="1"?"bg-success":"bg-warning"));const y=e.stages.filter(w=>w.id!=="from_any").length,O=t.querySelector("#workflow-stage-count");O&&(O.textContent=`${y} ${E(y===1?"COM_WORKFLOW_GRAPH_STAGE":"COM_WORKFLOW_GRAPH_STAGES")}`);const x=t.querySelector("#workflow-transition-count");x&&(x.textContent=`${e.transitions.length} ${e.transitions.length===1?E("COM_WORKFLOW_GRAPH_TRANSITION"):E("COM_WORKFLOW_GRAPH_TRANSITIONS")}`),S(t),setTimeout(()=>g(t),150)}catch(s){v(s.message,"error");return}let r=!1,u={};a.addEventListener("mousedown",s=>{s.target.closest(".stage")||s.target.closest(".zoom-controls")||s.button!==0||(r=!0,u={x:s.clientX-e.panX,y:s.clientY-e.panY},l&&l.classList.add("dragging"))}),document.addEventListener("mousemove",s=>{r&&(e.panX=s.clientX-u.x,e.panY=s.clientY-u.y,S(t))});const p=()=>{r=!1,l&&l.classList.remove("dragging")};document.addEventListener("mouseup",p),a.addEventListener("mouseleave",p),a.addEventListener("wheel",s=>{s.preventDefault();const c=a.getBoundingClientRect(),f=s.clientX-c.left,h=s.clientY-c.top,_=e.scale,y=s.deltaY<0?1:-1;e.scale=Math.max(.5,Math.min(e.scale*(1+y*.1),2));const O=e.scale/_;e.panX=f-(f-e.panX)*O,e.panY=h-(h-e.panY)*O,S(t)});const o=a.querySelector(".zoom-controls");o.querySelector(".zoom-in").addEventListener("click",()=>i(1.2,t)),o.querySelector(".zoom-out").addEventListener("click",()=>i(1/1.2,t)),o.querySelector(".fit-screen").addEventListener("click",()=>g(t));function i(s,c){const f=c.querySelector("#workflow-graph").getBoundingClientRect(),h=f.width/2,_=f.height/2,y=e.scale;e.scale=Math.max(.5,Math.min(e.scale*s,2));const O=e.scale/y;e.panX=h-(h-e.panX)*O,e.panY=_-(_-e.panY)*O,S(c)}function g(s){if(!e.stages.length)return;let c=1/0,f=1/0,h=-1/0,_=-1/0;if(e.stages.forEach(R=>{R.position&&(c=Math.min(c,R.position.x),f=Math.min(f,R.position.y),h=Math.max(h,R.position.x+200),_=Math.max(_,R.position.y+100))}),c===1/0)return;const y=s.querySelector("#workflow-graph").getBoundingClientRect(),O=50,x=h-c,w=_-f;e.scale=Math.max(.5,Math.min((y.width-O)/x,(y.height-O)/w,2)),e.panX=(y.width-x*e.scale)/2-c*e.scale,e.panY=(y.height-w*e.scale)/2-f*e.scale,S(s)}document.addEventListener("keydown",s=>{if(["INPUT","TEXTAREA"].includes(document.activeElement.tagName))return;const c=30,f=1.1;switch(s.code){case"Equal":i(f,t);break;case"Minus":i(1/f,t);break;case"ArrowLeft":case"KeyA":e.panX+=c,S(t);break;case"ArrowRight":case"KeyD":e.panX-=c,S(t);break;case"ArrowUp":case"KeyW":e.panY+=c,S(t);break;case"ArrowDown":case"KeyS":e.panY-=c,S(t);break;case"Digit0":case"KeyF":g(t);break}})}document.addEventListener("joomla-dialog:open",t=>{const a=t.target;a.querySelector("#workflow-container")&&F(a)})})();

The same content is in 29 releases, Joomla 6.1.0-beta2 to 6.3.0-alpha1. See them all, or every version of this file.