@muonroi/ui-engine-rule-components 0.1.9 → 0.1.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"MuRuleFlowEditor.d.ts","sourceRoot":"","sources":["../../../src/components/rule-flow/MuRuleFlowEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAA4D,MAAM,OAAO,CAAC;AAqBjF,OAAO,KAAK,EAKV,cAAc,EAIf,MAAM,iBAAiB,CAAC;AAqDzB,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,cAAc,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC5D,aAAa,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,YAAY,CAAC;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACnD,iFAAiF;IACjF,UAAU,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;CACpC;AA0WD,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,aAAa,EACb,QAAgB,EAChB,KAAe,EACf,MAAY,EACZ,UAAU,EACV,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,aAA0B,EAC1B,UAAiB,EACjB,OAAc,EACd,eAAe,EACf,UAAU,EACX,EAAE,qBAAqB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAg8D3C;AAssBD,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"MuRuleFlowEditor.d.ts","sourceRoot":"","sources":["../../../src/components/rule-flow/MuRuleFlowEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAA4D,MAAM,OAAO,CAAC;AAqBjF,OAAO,KAAK,EAKV,cAAc,EAIf,MAAM,iBAAiB,CAAC;AAqDzB,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,cAAc,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC5D,aAAa,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,YAAY,CAAC;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACnD,iFAAiF;IACjF,UAAU,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;CACpC;AA0WD,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,aAAa,EACb,QAAgB,EAChB,KAAe,EACf,MAAY,EACZ,UAAU,EACV,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,aAA0B,EAC1B,UAAiB,EACjB,OAAc,EACd,eAAe,EACf,UAAU,EACX,EAAE,qBAAqB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAk8D3C;AAssBD,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"mu-rule-flow-designer.d.ts","sourceRoot":"","sources":["../../../src/components/rule-flow/mu-rule-flow-designer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAOlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAyBtD,qBACa,kBAAmB,SAAQ,UAAU;IAChD,MAAM,CAAC,MAAM,4BAAwD;IAGrE,KAAK,EAAE,cAAc,CAA+B;IAGpD,SAAS,SAAM;IAGf,QAAQ,UAAS;IAGjB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAW;IAGlC,UAAU,SAAM;IAGhB,cAAc,SAAM;IAGpB,MAAM,SAAO;IAGb,YAAY,SAAM;IAGlB,QAAQ,SAAM;IAGd,UAAU,UAAQ;IAGlB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE9B,OAAO,CAAC,KAAK,CAAC,CAAO;IACrB,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,mBAAmB,CAA6C;IACxE,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,cAAc,CAAwC;IAE9D,iBAAiB,IAAI,IAAI;IAgBzB,YAAY,IAAI,IAAI;IASpB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IA2B5C,oBAAoB,IAAI,IAAI;IAM5B,MAAM;IASN,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,0BAA0B;IAoBlC,OAAO,CAAC,aAAa;YA8DP,kBAAkB;YAqDlB,oBAAoB;YA6DpB,YAAY;YAqBZ,uBAAuB;CAmCtC"}
1
+ {"version":3,"file":"mu-rule-flow-designer.d.ts","sourceRoot":"","sources":["../../../src/components/rule-flow/mu-rule-flow-designer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAOlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAyBtD,qBACa,kBAAmB,SAAQ,UAAU;IAChD,MAAM,CAAC,MAAM,4BAAwD;IAGrE,KAAK,EAAE,cAAc,CAA+B;IAGpD,SAAS,SAAM;IAGf,QAAQ,UAAS;IAGjB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAW;IAGlC,UAAU,SAAM;IAGhB,cAAc,SAAM;IAGpB,MAAM,SAAO;IAGb,YAAY,SAAM;IAGlB,QAAQ,SAAM;IAGd,UAAU,UAAQ;IAGlB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE9B,OAAO,CAAC,KAAK,CAAC,CAAO;IACrB,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,mBAAmB,CAA6C;IACxE,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,cAAc,CAAwC;IAE9D,iBAAiB,IAAI,IAAI;IAgBzB,YAAY,IAAI,IAAI;IASpB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAkC5C,oBAAoB,IAAI,IAAI;IAM5B,MAAM;IASN,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,0BAA0B;IAoBlC,OAAO,CAAC,aAAa;YA8DP,kBAAkB;YAqDlB,oBAAoB;YA6DpB,YAAY;YAqBZ,uBAAuB;CAmCtC"}
@@ -359,7 +359,7 @@ React keys must be passed directly to JSX without using spread:
359
359
  0%, 100% { box-shadow: 0 0 8px var(--mu-color-interactive-subtle); }
360
360
  50% { box-shadow: 0 0 20px var(--mu-color-interactive-border), 0 0 40px var(--mu-color-interactive-subtle); }
361
361
  }
362
- `}),C.jsxs("div",{style:{flex:Co?`0 0 ${100-z}%`:"1 1 auto",position:"relative",overflow:"hidden"},children:[C.jsx("div",{style:{...lK,background:He.overlayBg,border:He.overlayBorder,boxShadow:He.overlayShadow},children:ul}),A.length===0&&!an?C.jsx(IG,{onAddTrigger:es}):null,C.jsxs(LV,{proOptions:{hideAttribution:!0},style:{width:"100%",height:"100%"},colorMode:r==="dark"?"dark":"light",nodes:A,edges:I,nodeTypes:hT,onMoveStart:()=>{Fe.current=!1},onNodeDragStart:()=>{Fe.current=!1},onNodesChange:B=>Un(B),onEdgesChange:B=>zn(B),onConnect:B=>{var We;if(t)return;const H=Rp(ur(Vt.current,zP({...B,label:"always",data:{edgeType:"always"}},qt.current)),{currentFlowContract:h?Ft.current.get(h):void 0,flowContractsByCode:Ft.current,nodeContractsById:Jt.current});if(!H.isValid){V({status:"error",message:((We=H.issues[0])==null?void 0:We.message)??"Cannot connect nodes because the new order violates dependencies."});return}const xe=`${B.source}-${B.target}-${qt.current.length+1}`;pe(xe),ee(""),Ji(pT(H.graph),{syncViewport:!0})},onNodeClick:(B,H)=>{ko(H.id)},onEdgeClick:(B,H)=>{pe(H.id),ee(""),W("basic-info")},onPaneClick:()=>{ee(""),pe(""),W("basic-info")},nodesConnectable:!an,nodesDraggable:!an,elementsSelectable:!0,children:[C.jsx(BG,{nodeIds:A.map(B=>B.id),syncToken:wn,hostElement:Fe.current?Li.current:null}),C.jsx(ZG,{}),C.jsx(c6,{}),C.jsx(GV,{}),C.jsx(VV,{})]}),Yr.length>0?C.jsxs("aside",{"data-testid":"rule-flow-dependency-overlay",style:{...gK,background:He.overlayBg,border:He.overlayBorder,boxShadow:He.overlayShadow},children:[C.jsxs("button",{type:"button",style:{...vK,cursor:"pointer",background:"transparent",border:"none",width:"100%",textAlign:"left",display:"flex",alignItems:"center",justifyContent:"space-between"},onClick:()=>Dn(B=>!B),"aria-expanded":lr,children:[C.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:4},children:[C.jsx("strong",{children:"Execution Order"}),C.jsx("span",{style:{fontSize:12,color:He.textMuted},children:"Prerequisites and downstream dependents."})]}),C.jsx("span",{style:{...rK(lr),width:22,height:22,fontSize:12},children:"▾"})]}),lr?C.jsx("div",{style:yK,children:Yr.map(B=>C.jsxs("button",{type:"button","data-testid":`dependency-overlay-${B.ruleCode}`,style:OK(B.nodeId===Z,He),onClick:()=>ko(B.nodeId),children:[C.jsxs("span",{style:{fontWeight:700,color:He.textPrimary},children:["#",B.order," ",B.label]}),C.jsx("span",{style:{fontSize:11,color:He.textSecondary},children:B.ruleCode}),C.jsxs("span",{style:{fontSize:11,color:He.textMuted},children:["Depends on: ",B.dependsOn.length>0?B.dependsOn.join(", "):"none"]}),C.jsxs("span",{style:{fontSize:11,color:He.textMuted},children:["Unlocks: ",B.dependents.length>0?B.dependents.join(", "):"none"]})]},B.nodeId))}):null]}):null]}),Co?C.jsxs(C.Fragment,{children:[C.jsx("div",{onPointerDown:dn,style:{height:4,cursor:"ns-resize",background:He.sidebarBorder.replace("1px solid ",""),transition:"background 150ms",flexShrink:0},onPointerEnter:B=>{B.currentTarget.style.background="var(--mu-color-interactive)"},onPointerLeave:B=>{B.currentTarget.style.background=He.sidebarBorder.replace("1px solid ","")}}),C.jsxs("div",{style:{flex:`0 0 ${z}%`,overflow:"auto",background:He.sidebarBg},children:[C.jsx(M9,{value:no,onChange:_s,onReset:()=>_s(ke()),tokens:He,editorRoot:E}),C.jsxs("div",{style:{display:"flex",gap:8,padding:"8px 12px",background:He.sidebarBg},children:[C.jsx("button",{type:"button",onClick:()=>{kt()},disabled:Jo||!s||!h,style:{padding:"6px 16px",borderRadius:6,border:"none",cursor:"pointer",background:"var(--mu-color-success)",color:"var(--mu-text-on-accent)",fontWeight:600,fontSize:12,opacity:Jo?.6:1},children:Jo?"Executing...":"Execute"}),C.jsx("button",{type:"button",onClick:Kt,style:{padding:"6px 16px",borderRadius:6,cursor:"pointer",background:"transparent",border:He.actionSecondaryBorder,color:He.textSecondary,fontWeight:500,fontSize:12},children:"Cancel"})]}),fl||Jo||hl?C.jsx(A9,{result:fl,loading:Jo,error:hl,onClose:Kt,onSelectNode:B=>{const H=Vt.current.find(xe=>xe.data.ruleCode===B||xe.data.label===B);H&&ko(H.id)},tokens:He}):null]})]}):null]}),Ye||vi?C.jsxs("aside",{"data-testid":"rule-flow-right-panel",style:{...sK,background:He.sidebarBg,border:He.sidebarBorder},children:[C.jsxs("div",{style:{padding:"12px 14px 8px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[C.jsx("strong",{style:{fontSize:13,color:He.textPrimary},children:"Inspector"}),C.jsx("button",{type:"button",style:{background:"transparent",border:"none",cursor:"pointer",color:He.textMuted,fontSize:14,padding:2},onClick:()=>{ee(""),pe("")},title:"Close inspector",children:"✕"})]}),Ku]}):null]}),Ze?C.jsx(HG,{warnings:Ze.warnings,onCancel:()=>rt(null),onConfirm:()=>{(async()=>{var B;try{V({status:"loading"}),await(m==null?void 0:m(Ze.graph)),rt(null),V({status:"ready",title:"Published"}),Me(0),mn(0,!1);const H=E instanceof ShadowRoot?E.host:null,xe=(B=H==null?void 0:H.getAttribute)==null?void 0:B.call(H,"data-last-publish-status");(xe==null?void 0:xe.toLowerCase())==="pendingapproval"||(xe==null?void 0:xe.toLowerCase())==="draft"?ut("Rule saved and submitted for approval."):ut("Rule published and activated successfully.")}catch(H){rt(null),V({status:"error",message:H.message||"Rule Studio publish failed."}),Mt(`Publish failed: ${H.message||"Unknown error"}`)}})()}}):null,C.jsx(k6,{open:Pd,onClose:()=>ji(!1),versions:Qr,activeVersion:Dt,initialLeftVersion:(Dt==null?void 0:Dt.version)??null,initialRightVersion:x??null,apiBaseUrl:s??"",workflowCode:h??"",tenantId:c,tokens:He})]});function Un(B){if(t)return;const H=E$(B,Vt.current);if(ht.current){L(H);return}const xe=H.filter(jn=>jn.selected).map(jn=>jn.id);ee(xe[0]??Z);const We=B.some(jn=>jn.type==="add"||jn.type==="remove"||jn.type==="replace"),ze=B.filter(jn=>jn.type==="position"),Pt=ze.some(jn=>jn.dragging),Wt=ze.length>0&&!Pt;if(!We&&!Wt){L(H);return}Wt&&(Fe.current=!1),Ji(ur(H,qt.current))}function zn(B){if(t)return;const H=_$(B,qt.current);if(ht.current){j(Q(H));return}const xe=H.filter(ze=>ze.selected).map(ze=>ze.id);if(pe(xe[0]??ie),!B.some(ze=>ze.type==="add"||ze.type==="remove"||ze.type==="replace")){j(Q(H));return}Ji(ur(Vt.current,H))}function Yt(B,H,xe){t||(B.dataTransfer.setData(fT,H),B.dataTransfer.setData("text/plain",H),xe&&B.dataTransfer.setData(CL,JSON.stringify(xe)),B.dataTransfer.effectAllowed="move")}function Nn(B){t||!B.dataTransfer.types.includes(fT)||(B.preventDefault(),B.dataTransfer.dropEffect="move")}function ir(B){if(t)return;const H=B.dataTransfer.getData(fT),xe=B.dataTransfer.getData(CL);if(!JC(H))return;B.preventDefault();const We=B.currentTarget.getBoundingClientRect(),ze={x:Math.max(32,B.clientX-We.left-84),y:Math.max(32,B.clientY-We.top-24)};if(xe)try{const Pt=JSON.parse(xe);if(Pt.code){ll(Pt,ze);return}}catch{}eo(H,ze)}}async function _L(n,e,t){if(e.has(t))return e.get(t)??null;try{const r=await n.MGetFlowContract(t);return e.set(t,r),r}catch{return null}}async function RL(n,e,t){try{return await n.MGetNodeAuthoringContract(e,t)}catch{return null}}async function VG(n,e,t){var s;const r=await RL(n,e,t.id);if(r)return r;const i=t.ruleCode?WD(t.type,t.ruleCode,t.data.contractRef):t.data.contractRef;if(!((s=i==null?void 0:i.sourceCode)!=null&&s.trim()))return null;try{const l=await n.MGetByReference(i);return{flowCode:e,nodeId:t.id,nodeType:t.type,ruleCode:t.ruleCode,order:t.data.order,dependsOn:t.data.dependsOn??[],requestScope:l.requestContract,responseDelta:l.responseContract}}catch{return null}}function FG(n){const e=nu(n.data);return{id:n.id,type:eT(n.type),label:n.data.label,ruleCode:n.data.ruleCode,feelExpression:e.language==="feel"?e.body:void 0,position:{x:n.position.x,y:n.position.y},data:qC(n.data)}}function XG(n){var e;return{id:n.id,source:n.source,target:n.target,label:typeof n.label=="string"?n.label:void 0,edgeType:Zx((e=n.data)==null?void 0:e.edgeType)}}function pT(n){const e=Ai(n);if(e.nodes.length===0)return e;const t=new Map;for(const h of e.nodes)t.set(h.id,[]);for(const h of e.edges){const m=t.get(h.target)??[];m.push(h.source),t.set(h.target,m)}const r=new Map,i=new Set,s=h=>{const m=r.get(h);if(m!==void 0)return m;if(i.has(h))return 0;i.add(h);const v=t.get(h)??[],y=v.length===0?0:Math.max(...v.map(x=>s(x)))+1;return i.delete(h),r.set(h,y),y},l=new Map;for(const h of e.nodes){const m=h.type==="trigger"?0:s(h.id),v=l.get(m)??[];v.push(h),l.set(m,v)}const c=e.nodes.map(h=>({...h}));for(const[h,m]of l)m.sort((v,y)=>{const x=v.data.order??Number.MAX_SAFE_INTEGER,S=y.data.order??Number.MAX_SAFE_INTEGER;return x!==S?x-S:(v.label??"").localeCompare(y.label??"")}).forEach((v,y)=>{const x=c.find(S=>S.id===v.id);x&&(x.position={x:80+h*260,y:120+y*150})});return{...e,nodes:c}}function WG(n){const e=n.nodes.filter(i=>i.type!=="trigger"&&i.type!=="end"&&(i.ruleCode??"").trim().length>0),t=new Map(e.map(i=>[i.ruleCode??i.id,i])),r=new Map;for(const i of e)for(const s of i.data.dependsOn??[]){const l=r.get(s)??[];l.push(i.ruleCode??i.id),r.set(s,l)}return e.map(i=>{const s=i.ruleCode??i.id,l=(r.get(s)??[]).filter(c=>t.has(c)).sort((c,h)=>c.localeCompare(h));return{nodeId:i.id,label:i.label,ruleCode:s,order:i.data.order??0,dependsOn:[...i.data.dependsOn??[]].sort((c,h)=>c.localeCompare(h)),dependents:l}}).sort((i,s)=>i.order!==s.order?i.order-s.order:(i.label??"").localeCompare(s.label??""))}function PL(n,e){const t=e==="input"?n.inputColumns:n.outputColumns;return{contractName:`${n.id}_${e}`,title:e==="input"?"Decision Table Inputs":"Decision Table Outputs",description:n.description,rootType:"object",fields:t.map(r=>({path:r.name,label:r.label,dataType:r.dataType,required:e==="input",runtimeWritten:e==="output",description:`${e==="input"?"Input":"Output"} column from decision table '${n.name}'.`}))}}function HG({warnings:n,onCancel:e,onConfirm:t}){return C.jsx("div",{style:xK,children:C.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"rule-flow-publish-confirm-title",style:bK,children:[C.jsxs("div",{style:$L,children:[C.jsx("strong",{id:"rule-flow-publish-confirm-title",children:"Confirm Publish"}),C.jsx("span",{children:n.length>0?"This flow can publish, but warnings still exist. Review them before continuing.":"This will hand the current validated graph to the host publish handler."})]}),n.length>0?C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:n.map((r,i)=>C.jsxs("div",{style:oG,children:[C.jsx("strong",{children:r.code})," ",r.message]},`${r.code}-${r.message}-${i}`))}):null,C.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--mu-space-sm)"},children:[C.jsx("button",{type:"button",style:xa(!1),onClick:e,children:"Cancel"}),C.jsx("button",{type:"button",style:xa(!0),onClick:t,children:n.length>0?"Publish With Warnings":"Confirm Publish"})]})]})})}function YG(n,e){const t=D9(n),r=new Blob([t],{type:"application/json"}),i=URL.createObjectURL(r),s=document.createElement("a");s.style.display="none",s.href=i,s.download=`${e??"rule-flow"}.json`,document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(i),100)}function qG({selectedEdge:n,readOnly:e,onUpdateEdgeType:t,onDeleteEdge:r}){var s;if(!n)return C.jsx("div",{style:{color:"var(--mu-text-muted)",fontSize:13,lineHeight:1.5},children:"Select a node or edge to edit it. Use edge routing to decide whether downstream nodes run `always`, `on pass`, `on fail`, or `on error`."});const i=Zx((s=n.data)==null?void 0:s.edgeType);return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14,minHeight:0},children:[C.jsxs("div",{style:$L,children:[C.jsx("strong",{children:"Edge Routing"}),C.jsxs("span",{children:[n.source," → ",n.target]})]}),C.jsxs("label",{style:dK,children:["Edge Type",C.jsx("select",{style:hK,value:i,disabled:e,onChange:l=>t(Zx(l.target.value)),children:["always","on-true","on-false","on-error"].map(l=>C.jsx("option",{value:l,children:dT[l]},l))})]}),C.jsxs("div",{style:pK,children:[C.jsx("strong",{children:dT[i]}),C.jsx("span",{children:DG[i]})]}),e?null:C.jsx("button",{type:"button",style:mK,onClick:r,children:"Delete Edge"})]})}const GG={display:"grid",gap:"var(--mu-space-sm)",minHeight:0,height:"100%",width:"100%",minWidth:0,overflow:"auto"},KG={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},JG={display:"flex",flex:"1 1 auto",minHeight:0},eK={position:"relative",minWidth:0,borderRadius:24,overflow:"hidden",border:"1px solid var(--mu-border-subtle)"},$L={display:"flex",flexDirection:"column",gap:4,fontSize:13,color:"var(--mu-text-muted)"},tK={display:"flex",flexDirection:"column",gap:6,padding:20,borderRadius:18,border:"1px solid var(--mu-color-warning-border)",background:"var(--mu-color-warning-bg)",color:"var(--mu-color-warning-text)"},nK=n=>({display:"flex",flexDirection:"column",gap:4,padding:"10px 12px",borderRadius:14,border:n?"1px solid var(--mu-color-error-border)":"1px solid var(--mu-color-warning-border)",background:n?"var(--mu-color-error-bg)":"var(--mu-color-warning-bg)",color:n?"var(--mu-color-error-text)":"var(--mu-color-warning-text)",fontSize:12}),ML={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",minHeight:0,height:"100%",overflow:"auto",paddingRight:4};function rK(n){return{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:999,background:"var(--mu-border-subtle)",color:"var(--mu-text-secondary)",fontSize:14,transform:n?"rotate(180deg)":"rotate(0deg)",transition:"transform 160ms ease"}}function iK(n,e){const t=(e==null?void 0:e.paletteBtnBorderAlpha)??"22",r=(e==null?void 0:e.paletteBtnBgAlpha)??"10";return{display:"flex",flexDirection:"column",gap:4,borderRadius:14,border:`1px solid ${Av[n]}${t}`,background:`${Av[n]}${r}`,color:(e==null?void 0:e.textPrimary)??"var(--mu-text-primary)",padding:"11px 12px",textAlign:"left",fontWeight:600,cursor:"grab"}}function oK(n,e,t=280,r=!1){if(n)return{gridTemplateColumns:"minmax(0, 1fr)",alignContent:"start"};const i=r?"48px":`${t}px`;return{gridTemplateColumns:e?`${i} minmax(0, 1fr) minmax(320px, 420px)`:`${i} minmax(0, 1fr)`,alignContent:"stretch"}}const aK={display:"flex",flexDirection:"column",gap:0,borderRadius:18,minHeight:0,overflow:"auto"},sK={display:"flex",flexDirection:"column",gap:0,borderRadius:18,minHeight:0,overflow:"auto"};function mT(n){return{background:"transparent",border:"none",cursor:"pointer",fontSize:11,color:n.textMuted,padding:"2px 4px",borderRadius:4,whiteSpace:"nowrap"}}const gT={display:"block",width:"100%",textAlign:"left",padding:"8px 14px",background:"transparent",border:"none",cursor:"pointer",fontSize:13,borderRadius:0},lK={position:"absolute",top:12,left:12,zIndex:3,borderRadius:14,padding:"8px 12px",maxWidth:"calc(100% - 24px)"};function uK(n){return{minHeight:n?420:640,order:n?-1:0}}function cK(n){return{}}function fK(n){return{}}const dK={display:"flex",flexDirection:"column",gap:6,fontSize:12,color:"var(--mu-text-secondary)",fontWeight:600},hK={width:"100%",borderRadius:12,border:"1px solid var(--mu-border-input)",background:"var(--mu-surface-input)",color:"var(--mu-text-primary)",minHeight:42,padding:"10px 12px",fontSize:14},pK={display:"flex",flexDirection:"column",gap:6,padding:"12px 14px",borderRadius:14,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-raised)",color:"var(--mu-text-label)",fontSize:12,lineHeight:1.5},mK={borderRadius:14,border:"1px solid var(--mu-color-error-border)",background:"var(--mu-color-error-bg)",color:"var(--mu-color-error-text)",padding:"11px 14px",fontWeight:700},gK={position:"absolute",top:16,right:16,zIndex:2,display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",width:"min(320px, calc(100% - 32px))",maxHeight:"calc(100% - 32px)",padding:14,borderRadius:18,overflow:"auto"},vK={display:"flex",flexDirection:"column",gap:4,fontSize:12,color:"var(--mu-text-muted)"},yK={display:"flex",flexDirection:"column",gap:8};function OK(n,e){return{display:"flex",flexDirection:"column",gap:4,width:"100%",textAlign:"left",padding:"10px 12px",borderRadius:14,border:n?(e==null?void 0:e.overlayItemSelectedBorder)??"1px solid var(--mu-color-interactive-border)":(e==null?void 0:e.overlayItemBorder)??"1px solid var(--mu-border-subtle)",background:n?(e==null?void 0:e.overlayItemSelectedBg)??"var(--mu-color-selected-bg)":(e==null?void 0:e.overlayItemBg)??"var(--mu-surface-raised)",color:(e==null?void 0:e.textPrimary)??"var(--mu-text-primary)",cursor:"pointer"}}const xK={position:"fixed",inset:0,zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--mu-surface-backdrop)"},bK={display:"flex",flexDirection:"column",gap:16,width:"min(560px, 100%)",padding:20,borderRadius:22,border:"1px solid var(--mu-border-default)",background:"var(--mu-surface-dialog)",boxShadow:"var(--mu-shadow-dialog)"},wK={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 16px",borderRadius:"18px 18px 0 0",minHeight:42},qu={display:"inline-flex",alignItems:"center",padding:"2px 10px",borderRadius:8,fontSize:12,fontWeight:600,letterSpacing:"0.02em"},SK={position:"absolute",top:"calc(100% + 4px)",right:0,zIndex:10,display:"flex",flexDirection:"column",gap:6,padding:"10px 14px",borderRadius:12,minWidth:200,maxWidth:360},AL={nodes:[zv("trigger",{x:80,y:180},{label:"Start"}),zv("end",{x:760,y:180},{label:"End"})],edges:[{id:"edge-trigger-end",source:"trigger-1",target:"end-1",edgeType:"always"}],metadata:{version:1}};class QL{static fromRuleSet(e){const t=iu(e),r=t.flowGraph;if(EK(r)){const v=vT({...r,metadata:{...r.metadata,workflowName:Rd(t.workflowName)??r.metadata.workflowName}}),y=r.nodes??[];return v.nodes=v.nodes.map((x,S)=>{const E=iu(y[S]),k=E.expressionLanguage,R=iu(E.data),P=R.connectorConfig,Q=typeof R.connectorType=="string"?R.connectorType:void 0;let A;if(P&&typeof P=="object"){const L=P;L.connectorConfig&&typeof L.connectorConfig=="object"?A={connectorType:typeof L.connectorType=="string"?L.connectorType:Q,connectorConfig:L.connectorConfig,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}:"url"in L||"method"in L||"body"in L||"operation"in L||"webhookUrl"in L||"to"in L||"key"in L?A={connectorType:typeof L.connectorType=="string"?L.connectorType:Q,connectorConfig:L,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}:A={connectorType:typeof L.connectorType=="string"?L.connectorType:Q,connectorConfig:void 0,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}}return{...x,expressionLanguage:k==="feel"||k==="javascript"?k:void 0,data:{...x.data,connectorConfig:A}}}),v}const i=Rd(t.workflowName)??Rd(t.WorkflowName)??"wf.new",s=CK(t);if(s.length===0)return{...AL,metadata:{...AL.metadata,workflowName:i}};const l=[zv("trigger",{x:80,y:180},{label:"Start"})],c=[];let h="trigger-1";for(let v=0;v<s.length;v+=1){const y=s[v],x=zv("condition",{x:220+v*220,y:180},{label:y,ruleCode:y,nodeId:y});l.push(x),c.push({id:`edge-${h}-${x.id}`,source:h,target:x.id,edgeType:"always"}),h=x.id}const m=zv("end",{x:220+s.length*220,y:180},{label:"End"});return l.push(m),c.push({id:`edge-${h}-${m.id}`,source:h,target:m.id,edgeType:"always"}),{nodes:l,edges:c,metadata:{version:1,workflowName:i}}}static toRuleSet(e,t){const r=iu(t),i=vT(e),s=kK(i),l=e.metadata.workflowName??e.metadata.ruleSetCode??Rd(r.workflowName)??Rd(r.WorkflowName)??"wf.new",c={...i,nodes:i.nodes.map(h=>{var v;const m={...h};return h.expressionLanguage&&(m.expressionLanguage=h.expressionLanguage),(v=h.data)!=null&&v.connectorConfig&&(m.data={...m.data,connectorConfig:h.data.connectorConfig}),m})};return{...r,workflowName:l,rules:s,flowGraph:c}}static serialize(e){return JSON.stringify(vT(e),null,2)}}function kK(n){var l,c,h;const e=new Map(n.nodes.map(m=>[m.id,m])),t=new Map;for(const m of n.edges){const v=t.get(m.source)??[];v.push(m),t.set(m.source,v)}const r=new Set,i=[];let s=((l=n.nodes.find(m=>m.type==="trigger"))==null?void 0:l.id)??((c=n.nodes[0])==null?void 0:c.id);for(;s&&!r.has(s);){r.add(s);const m=e.get(s);if(m&&m.type!=="trigger"&&m.type!=="end"){const y=((h=m.ruleCode)==null?void 0:h.trim())||m.label.trim();y.length>0&&!i.includes(y)&&i.push(y)}const v=(t.get(s)??[]).slice().sort((y,x)=>(y.target??"").localeCompare(x.target??""))[0];s=v==null?void 0:v.target}return i.length>0?i:n.nodes.filter(m=>m.type!=="trigger"&&m.type!=="end").map(m=>{var v;return((v=m.ruleCode)==null?void 0:v.trim())||m.label.trim()}).filter(m=>m.length>0)}function CK(n){return(Array.isArray(n.rules)?n.rules:Array.isArray(n.Rules)?n.Rules:[]).map(t=>typeof t=="string"?t:iu(t).RuleName&&typeof iu(t).RuleName=="string"?iu(t).RuleName:Rd(iu(t).ruleCode)??Rd(iu(t).code)??"").map(t=>t.trim()).filter(t=>t.length>0)}function vT(n){var e,t,r;return{nodes:n.nodes.map((i,s)=>{var l,c,h,m,v;return{...i,id:i.id||`${i.type}-${s+1}`,label:i.label.trim()||`${TK(i.type)} ${s+1}`,expressionLanguage:i.expressionLanguage==="feel"||i.expressionLanguage==="javascript"?i.expressionLanguage:void 0,position:{x:Number.isFinite((l=i.position)==null?void 0:l.x)?i.position.x:s*220,y:Number.isFinite((c=i.position)==null?void 0:c.y)?i.position.y:180},data:{...i.data??{},outputFields:i.type==="condition"?(()=>{var E,k,R;const y=(((k=(E=i.data)==null?void 0:E.contractOverride)==null?void 0:k.responseFields)??[]).filter(P=>!P.isResultPayload&&typeof P.valueExpression=="string"&&P.valueExpression.trim().length>0).map(P=>({path:P.path,valueExpression:P.valueExpression,dataType:P.dataType,runtimeWritten:!0})),x=(Array.isArray((R=i.data)==null?void 0:R.outputFields)?i.data.outputFields:[]).filter(P=>typeof(P==null?void 0:P.path)=="string"&&P.path.trim().length>0&&(!P.valueExpression||!P.valueExpression.trim())).map(P=>({path:P.path,valueExpression:P.valueExpression??"",dataType:P.dataType??"string",runtimeWritten:!0})),S=new Set(y.map(P=>P.path));return[...y,...x.filter(P=>!S.has(P.path))]})():(h=i.data)==null?void 0:h.outputFields,connectorConfig:(m=i.data)==null?void 0:m.connectorConfig,contractRef:i.type!=="trigger"&&i.type!=="end"&&i.ruleCode?{sourceType:i.type==="decision-table"?"decision-table":i.type==="sub-flow"?"flow":i.type==="connector"?"api":"rule",sourceCode:i.ruleCode}:((v=i.data)==null?void 0:v.contractRef)??void 0}}}),edges:n.edges.map((i,s)=>({...i,id:i.id||`edge-${s+1}`,edgeType:i.edgeType??"always"})),metadata:{version:((e=n.metadata)==null?void 0:e.version)??1,workflowName:((t=n.metadata)==null?void 0:t.workflowName)??((r=n.metadata)==null?void 0:r.ruleSetCode)}}}function zv(n,e,t){var i;const r=n==="trigger"||n==="end"?"1":`${Math.abs(e.x)}`;return{id:((i=t.nodeId)==null?void 0:i.trim())||`${n}-${r}`,type:n,label:t.label,ruleCode:t.ruleCode,position:e,data:t.ruleCode?{contractRef:{sourceType:"rule",sourceCode:t.ruleCode}}:{}}}function TK(n){return n.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function Rd(n){return typeof n=="string"&&n.trim().length>0?n.trim():void 0}function iu(n){return n!==null&&typeof n=="object"?n:{}}function EK(n){const e=iu(n);return Array.isArray(e.nodes)&&Array.isArray(e.edges)&&e.metadata!==void 0}var _K=Object.defineProperty,RK=Object.getOwnPropertyDescriptor,ks=(n,e,t,r)=>{for(var i=r>1?void 0:r?RK(e,t):e,s=n.length-1,l;s>=0;s--)(l=n[s])&&(i=(r?l(e,t,i):l(i))||i);return r&&i&&_K(e,t,i),i};const DL="rule-flow-designer";let ba=class extends ed{constructor(){super(...arguments),this.graph=FO(),this.graphJson="",this.readOnly=!1,this.theme="light",this.apiBaseUrl="",this.catalogApiBase="",this.height=640,this.workflowCode="",this.tenantId="",this.showHeader=!0,this.version=null,this.mInternalGraphUpdate=!1,this.mLastGraphSignature=Qi(this.graph),this.mWorkflowLoadVersion=0,this.mLoadedRuleSet=null}connectedCallback(){super.connectedCallback(),this.MUpgradeProperty("graph"),this.MUpgradeProperty("graphJson"),this.MUpgradeProperty("readOnly"),this.MUpgradeProperty("theme"),this.MUpgradeProperty("apiBaseUrl"),this.MUpgradeProperty("catalogApiBase"),this.MUpgradeProperty("height"),this.MUpgradeProperty("workflowCode"),this.MUpgradeProperty("tenantId"),this.MUpgradeProperty("showHeader"),this.MUpgradeProperty("version"),this.MSyncGraphFromJson()}firstUpdated(){queueMicrotask(()=>{this.MRenderEditor(),this.graphJson.trim()||this.MLoadWorkflowGraphAsync()})}updated(n){if(n.has("graphJson")&&!this.mInternalGraphUpdate&&this.MSyncGraphFromJsonIfNeeded()){this.MRenderEditor();return}!this.mInternalGraphUpdate&&(n.has("graph")||n.has("graphJson")||n.has("readOnly")||n.has("theme")||n.has("apiBaseUrl")||n.has("catalogApiBase")||n.has("height")||n.has("tenantId")||n.has("showHeader")||n.has("version"))&&this.MRenderEditor(),n.has("version")&&this.graphJson.trim()&&(this.mInternalGraphUpdate=!0,this.graphJson="",this.graph=FO(),this.mLastGraphSignature=Qi(this.graph)),(n.has("workflowCode")||n.has("apiBaseUrl")||n.has("tenantId")||n.has("version"))&&!this.graphJson.trim()&&this.MLoadWorkflowGraphAsync(),this.mInternalGraphUpdate&&(n.has("graphJson")||n.has("graph"))&&(this.mInternalGraphUpdate=!1,this.MRenderEditor())}disconnectedCallback(){var n;(n=this.mRoot)==null||n.unmount(),this.mRoot=void 0,super.disconnectedCallback()}render(){const n=v2(DL);return n||xr`<section id="editor-host" class="block h-full min-h-[640px] w-full"></section>`}MUpgradeProperty(n){if(!Object.prototype.hasOwnProperty.call(this,n))return;const e=Reflect.get(this,n);Reflect.deleteProperty(this,n),Reflect.set(this,n,e)}MSyncGraphFromJson(){if(!this.graphJson.trim()){this.graph=Ai(this.graph),this.mLastGraphSignature=Qi(this.graph);return}try{this.graph=Ai(JSON.parse(this.graphJson)),this.mLastGraphSignature=Qi(this.graph)}catch{this.graph=FO(),this.mLastGraphSignature=Qi(this.graph)}}MSyncGraphFromJsonIfNeeded(){if(!this.graphJson.trim())return!1;try{const n=Ai(JSON.parse(this.graphJson)),e=Qi(n);return e===this.mLastGraphSignature?!1:(this.graph=n,this.mLastGraphSignature=e,!0)}catch{return!1}}MRenderEditor(){var t,r;if(v2(DL)){(t=this.mRoot)==null||t.unmount(),this.mRoot=void 0;return}const e=(r=this.renderRoot)==null?void 0:r.querySelector("#editor-host");e&&(this.mRoot??(this.mRoot=W3.createRoot(e)),this.mRoot.render(q.createElement(UG,{graph:this.graph,readOnly:this.readOnly,theme:this.theme,apiBaseUrl:this.apiBaseUrl||void 0,catalogApiBase:this.catalogApiBase||void 0,tenantId:this.tenantId||void 0,workflowCode:this.workflowCode||void 0,height:this.height,showHeader:this.showHeader,version:this.version,editorRoot:this.renderRoot,onVersionChange:i=>{this.version=i,this.dispatchEvent(new CustomEvent("version-change",{detail:{version:i},bubbles:!0,composed:!0}))},onGraphChange:i=>{const s=Qi(i);s!==this.mLastGraphSignature&&(this.mInternalGraphUpdate=!0,this.graph=i,this.mLastGraphSignature=s,this.graphJson=JSON.stringify(i),this.dispatchEvent(new CustomEvent("graph-change",{detail:i,bubbles:!0,composed:!0})))},onPublish:async i=>{await this.MPublishGraphAsync(i)}})))}async MPublishGraphAsync(n){const e=QL.toRuleSet(n,this.mLoadedRuleSet??void 0);this.mLoadedRuleSet=e;const t={graph:n,ruleSet:e};if(this.dispatchEvent(new CustomEvent("publish-start",{detail:t,bubbles:!0,composed:!0})),!this.apiBaseUrl.trim()||!this.workflowCode.trim()){this.dispatchEvent(new CustomEvent("publish",{detail:t,bubbles:!0,composed:!0}));return}try{const r=await this.MPersistRuleSetAsync(t);this.setAttribute("data-last-publish-status",r.status??"Active"),this.setAttribute("data-last-publish-approval",String(r.approvalWorkflowEnabled)),this.dispatchEvent(new CustomEvent("publish-complete",{detail:r,bubbles:!0,composed:!0}))}catch(r){const i=r instanceof Error?r.message:"Rule Studio publish failed.";throw this.dispatchEvent(new CustomEvent("publish-error",{detail:{message:i,graph:n,ruleSet:e},bubbles:!0,composed:!0})),r}}async MPersistRuleSetAsync(n){const e=this.workflowCode.trim(),t=this.apiBaseUrl.replace(/\/$/,""),r="ui-studio",i=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}`,{method:"POST",body:JSON.stringify({ruleSet:n.ruleSet,activateAfterSave:!1,actor:r})}),s=Number(i.savedVersion??0);if(!Number.isFinite(s)||s<=0)throw new Error("Rule Studio publish did not return a saved version.");const l=!!i.approvalWorkflowEnabled;let c=!!i.activated,h=typeof i.activeVersion=="number"?i.activeVersion:null,m=typeof i.status=="string"?i.status:void 0,v=`Saved version ${s}.`;if(l){const y=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}/${s}/submit`,{method:"POST",body:JSON.stringify({actor:r})});m=typeof y.status=="string"?y.status:m,v=`Saved version ${s} and submitted for approval.`}else if(!c||h!==s){const y=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}/${s}/activate`,{method:"POST",body:JSON.stringify({actor:r})});c=!0,h=typeof y.activeVersion=="number"?y.activeVersion:s,m="Active",v=`Saved version ${s} and activated it.`}else v=`Saved version ${s} and activated it.`;return{...n,savedVersion:s,activeVersion:h,approvalWorkflowEnabled:l,activated:c,status:m,message:v}}async MRequestJson(n,e){const t=Zo(e.headers,{tenantId:this.tenantId});!t.has("Content-Type")&&e.body&&t.set("Content-Type","application/json"),t.has("Accept")||t.set("Accept","application/json");const r=await fetch(n,{...e,headers:t});if(!r.ok){const i=await r.text();throw new Error(i||`Rule Studio request failed: ${r.status} ${r.statusText}`)}return await r.json()}async MLoadWorkflowGraphAsync(){const n=this.workflowCode.trim(),e=this.apiBaseUrl.trim();if(!n||!e||this.graphJson.trim())return;const t=++this.mWorkflowLoadVersion,r=this.version!=null?`?version=${this.version}`:"",i=`${e.replace(/\/$/,"")}/rulesets/${encodeURIComponent(n)}/export${r}`;try{const s=await fetch(i,{headers:Zo(void 0,{tenantId:this.tenantId})});if(!s.ok)return;const l=await s.json();if(t!=this.mWorkflowLoadVersion||!l.ruleSetJson)return;const c=JSON.parse(l.ruleSetJson);this.mLoadedRuleSet=c;const h=Ai(QL.fromRuleSet(c));this.mInternalGraphUpdate=!0,this.graph=h,this.mLastGraphSignature=Qi(h),this.graphJson=JSON.stringify(h)}catch{}}};ba.styles=[N1(iI),N1(oI)],ks([ci({attribute:!1})],ba.prototype,"graph",2),ks([ci({type:String,attribute:"graph-json"})],ba.prototype,"graphJson",2),ks([ci({type:Boolean,attribute:"read-only"})],ba.prototype,"readOnly",2),ks([ci({type:String})],ba.prototype,"theme",2),ks([ci({type:String,attribute:"api-base-url"})],ba.prototype,"apiBaseUrl",2),ks([ci({type:String,attribute:"catalog-api-base"})],ba.prototype,"catalogApiBase",2),ks([ci({type:Number})],ba.prototype,"height",2),ks([ci({type:String,attribute:"workflow-code"})],ba.prototype,"workflowCode",2),ks([ci({type:String,attribute:"tenant-id"})],ba.prototype,"tenantId",2),ks([ci({type:Boolean,attribute:"show-header"})],ba.prototype,"showHeader",2),ks([ci({type:Number})],ba.prototype,"version",2),ba=ks([F1("mu-rule-flow-designer")],ba);class LL{constructor(e,t){this.baseUrl=e,this.mGetHeaders=t}async mFetch(e,t){var l;const r=((l=this.mGetHeaders)==null?void 0:l.call(this))??Zo(),i=new Headers(r);t!=null&&t.headers&&new Headers(t.headers).forEach((h,m)=>i.set(m,h));const s=await fetch(`${this.baseUrl}${e}`,{...t,headers:i});if(!s.ok)throw new Error(`Trace API ${s.status}: ${await s.text()}`);return s.json()}async mEnableDebugger(e,t){await this.mFetch(`/muonroi/rule-debugger/${e}/enable`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})})}async mDisableDebugger(e){await this.mFetch(`/muonroi/rule-debugger/${e}/disable`,{method:"POST"})}async mQueryTraces(e,t){const r=new URLSearchParams;t!=null&&t.correlationId&&r.set("correlationId",t.correlationId),t!=null&&t.from&&r.set("from",t.from);const i=r.toString();return this.mFetch(`/muonroi/rule-debugger/${e}/traces${i?`?${i}`:""}`)}}var PK=Object.defineProperty,$K=Object.getOwnPropertyDescriptor,Xa=(n,e,t,r)=>{for(var i=r>1?void 0:r?$K(e,t):e,s=n.length-1,l;s>=0;s--)(l=n[s])&&(i=(r?l(e,t,i):l(i))||i);return r&&i&&PK(e,t,i),i};const MK=["BeforeEval","AfterEval","AfterExec","Error","Compensate"],AK=["before-eval","after-eval","after-exec","error","compensate"];let Ho=class extends ed{constructor(){super(...arguments),this.apiBaseUrl="",this.tenantId="",this.correlationId="",this.readOnly=!1,this.tracesJson="",this._traces=[],this._loading=!1,this._error=null,this._expandedIds=new Set,this._phaseFilter="all",this._successFilter="all",this._apiClient=null}connectedCallback(){super.connectedCallback(),this.apiBaseUrl&&(this._apiClient=new LL(this.apiBaseUrl))}updated(n){if(n.has("tracesJson")&&this.tracesJson)try{this._traces=JSON.parse(this.tracesJson)}catch{}n.has("apiBaseUrl")&&this.apiBaseUrl&&(this._apiClient=new LL(this.apiBaseUrl))}async loadTraces(){if(!(!this._apiClient||!this.tenantId)){this._loading=!0,this._error=null;try{this._traces=await this._apiClient.mQueryTraces(this.tenantId,{correlationId:this.correlationId||void 0})}catch(n){this._error=n instanceof Error?n.message:String(n)}finally{this._loading=!1}}}async enableDebugger(n=30){!this._apiClient||!this.tenantId||await this._apiClient.mEnableDebugger(this.tenantId,{durationMinutes:n})}async disableDebugger(){!this._apiClient||!this.tenantId||await this._apiClient.mDisableDebugger(this.tenantId)}_phaseLabel(n){return MK[n]??"Unknown"}_phaseClassSuffix(n){return AK[n]??"before-eval"}get _filteredTraces(){return this._traces.filter(n=>!(this._phaseFilter!=="all"&&n.phase!==this._phaseFilter||this._successFilter==="success"&&!n.isSuccess||this._successFilter==="failure"&&n.isSuccess))}_toggleExpand(n){const e=new Set(this._expandedIds);e.has(n)?e.delete(n):e.add(n),this._expandedIds=e}_formatJson(n){if(!n)return"—";try{return JSON.stringify(JSON.parse(n),null,2)}catch{return n}}render(){return xr`
362
+ `}),C.jsxs("div",{style:{flex:Co?`0 0 ${100-z}%`:"1 1 auto",position:"relative",overflow:"hidden"},children:[C.jsx("div",{style:{...lK,background:He.overlayBg,border:He.overlayBorder,boxShadow:He.overlayShadow},children:ul}),A.length===0&&!an?C.jsx(IG,{onAddTrigger:es}):null,C.jsxs(LV,{proOptions:{hideAttribution:!0},style:{width:"100%",height:"100%"},colorMode:r==="dark"?"dark":"light",nodes:A,edges:I,nodeTypes:hT,onMoveStart:()=>{Fe.current=!1},onNodeDragStart:()=>{Fe.current=!1},onNodesChange:B=>Un(B),onEdgesChange:B=>zn(B),onConnect:B=>{var We;if(t)return;const H=Rp(ur(Vt.current,zP({...B,label:"always",data:{edgeType:"always"}},qt.current)),{currentFlowContract:h?Ft.current.get(h):void 0,flowContractsByCode:Ft.current,nodeContractsById:Jt.current});if(!H.isValid){V({status:"error",message:((We=H.issues[0])==null?void 0:We.message)??"Cannot connect nodes because the new order violates dependencies."});return}const xe=`${B.source}-${B.target}-${qt.current.length+1}`;pe(xe),ee(""),Ji(pT(H.graph),{syncViewport:!0})},onNodeClick:(B,H)=>{ko(H.id)},onEdgeClick:(B,H)=>{pe(H.id),ee(""),W("basic-info")},onPaneClick:()=>{ee(""),pe(""),W("basic-info")},nodesConnectable:!an,nodesDraggable:!an,elementsSelectable:!0,children:[C.jsx(BG,{nodeIds:A.map(B=>B.id),syncToken:wn,hostElement:Fe.current?Li.current:null}),C.jsx(ZG,{}),C.jsx(c6,{}),C.jsx(GV,{}),C.jsx(VV,{})]}),Yr.length>0?C.jsxs("aside",{"data-testid":"rule-flow-dependency-overlay",style:{...gK,background:He.overlayBg,border:He.overlayBorder,boxShadow:He.overlayShadow},children:[C.jsxs("button",{type:"button",style:{...vK,cursor:"pointer",background:"transparent",border:"none",width:"100%",textAlign:"left",display:"flex",alignItems:"center",justifyContent:"space-between"},onClick:()=>Dn(B=>!B),"aria-expanded":lr,children:[C.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:4},children:[C.jsx("strong",{children:"Execution Order"}),C.jsx("span",{style:{fontSize:12,color:He.textMuted},children:"Prerequisites and downstream dependents."})]}),C.jsx("span",{style:{...rK(lr),width:22,height:22,fontSize:12},children:"▾"})]}),lr?C.jsx("div",{style:yK,children:Yr.map(B=>C.jsxs("button",{type:"button","data-testid":`dependency-overlay-${B.ruleCode}`,style:OK(B.nodeId===Z,He),onClick:()=>ko(B.nodeId),children:[C.jsxs("span",{style:{fontWeight:700,color:He.textPrimary},children:["#",B.order," ",B.label]}),C.jsx("span",{style:{fontSize:11,color:He.textSecondary},children:B.ruleCode}),C.jsxs("span",{style:{fontSize:11,color:He.textMuted},children:["Depends on: ",B.dependsOn.length>0?B.dependsOn.join(", "):"none"]}),C.jsxs("span",{style:{fontSize:11,color:He.textMuted},children:["Unlocks: ",B.dependents.length>0?B.dependents.join(", "):"none"]})]},B.nodeId))}):null]}):null]}),Co?C.jsxs(C.Fragment,{children:[C.jsx("div",{onPointerDown:dn,style:{height:4,cursor:"ns-resize",background:He.sidebarBorder.replace("1px solid ",""),transition:"background 150ms",flexShrink:0},onPointerEnter:B=>{B.currentTarget.style.background="var(--mu-color-interactive)"},onPointerLeave:B=>{B.currentTarget.style.background=He.sidebarBorder.replace("1px solid ","")}}),C.jsxs("div",{style:{flex:`0 0 ${z}%`,overflow:"auto",background:He.sidebarBg},children:[C.jsx(M9,{value:no,onChange:_s,onReset:()=>_s(ke()),tokens:He,editorRoot:E}),C.jsxs("div",{style:{display:"flex",gap:8,padding:"8px 12px",background:He.sidebarBg},children:[C.jsx("button",{type:"button",onClick:()=>{kt()},disabled:Jo||!s||!h,style:{padding:"6px 16px",borderRadius:6,border:"none",cursor:"pointer",background:"var(--mu-color-success)",color:"var(--mu-text-on-accent)",fontWeight:600,fontSize:12,opacity:Jo?.6:1},children:Jo?"Executing...":"Execute"}),C.jsx("button",{type:"button",onClick:Kt,style:{padding:"6px 16px",borderRadius:6,cursor:"pointer",background:"transparent",border:He.actionSecondaryBorder,color:He.textSecondary,fontWeight:500,fontSize:12},children:"Cancel"})]}),fl||Jo||hl?C.jsx(A9,{result:fl,loading:Jo,error:hl,onClose:Kt,onSelectNode:B=>{const H=Vt.current.find(xe=>xe.data.ruleCode===B||xe.data.label===B);H&&ko(H.id)},tokens:He}):null]})]}):null]}),Ye||vi?C.jsxs("aside",{"data-testid":"rule-flow-right-panel",style:{...sK,background:He.sidebarBg,border:He.sidebarBorder},children:[C.jsxs("div",{style:{padding:"12px 14px 8px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[C.jsx("strong",{style:{fontSize:13,color:He.textPrimary},children:"Inspector"}),C.jsx("button",{type:"button",style:{background:"transparent",border:"none",cursor:"pointer",color:He.textMuted,fontSize:14,padding:2},onClick:()=>{ee(""),pe("")},title:"Close inspector",children:"✕"})]}),Ku]}):null]}),Ze?C.jsx(HG,{warnings:Ze.warnings,onCancel:()=>rt(null),onConfirm:()=>{(async()=>{var B;try{V({status:"loading"}),await(m==null?void 0:m(Ze.graph)),rt(null),V({status:"ready",title:"Published"}),Me(0),mn(0,!1);const H=E instanceof ShadowRoot?E.host:null,xe=(B=H==null?void 0:H.getAttribute)==null?void 0:B.call(H,"data-last-publish-status");(xe==null?void 0:xe.toLowerCase())==="pendingapproval"||(xe==null?void 0:xe.toLowerCase())==="draft"?ut("Rule saved and submitted for approval."):ut("Rule published and activated successfully.")}catch(H){rt(null),V({status:"error",message:H.message||"Rule Studio publish failed."}),Mt(`Publish failed: ${H.message||"Unknown error"}`)}})()}}):null,Pd?C.jsx(k6,{open:!0,onClose:()=>ji(!1),versions:Qr,activeVersion:Dt,initialLeftVersion:(Dt==null?void 0:Dt.version)??null,initialRightVersion:x??null,apiBaseUrl:s??"",workflowCode:h??"",tenantId:c,tokens:He}):null]});function Un(B){if(t)return;const H=E$(B,Vt.current);if(ht.current){L(H);return}const xe=H.filter(jn=>jn.selected).map(jn=>jn.id);ee(xe[0]??Z);const We=B.some(jn=>jn.type==="add"||jn.type==="remove"||jn.type==="replace"),ze=B.filter(jn=>jn.type==="position"),Pt=ze.some(jn=>jn.dragging),Wt=ze.length>0&&!Pt;if(!We&&!Wt){L(H);return}Wt&&(Fe.current=!1),Ji(ur(H,qt.current))}function zn(B){if(t)return;const H=_$(B,qt.current);if(ht.current){j(Q(H));return}const xe=H.filter(ze=>ze.selected).map(ze=>ze.id);if(pe(xe[0]??ie),!B.some(ze=>ze.type==="add"||ze.type==="remove"||ze.type==="replace")){j(Q(H));return}Ji(ur(Vt.current,H))}function Yt(B,H,xe){t||(B.dataTransfer.setData(fT,H),B.dataTransfer.setData("text/plain",H),xe&&B.dataTransfer.setData(CL,JSON.stringify(xe)),B.dataTransfer.effectAllowed="move")}function Nn(B){t||!B.dataTransfer.types.includes(fT)||(B.preventDefault(),B.dataTransfer.dropEffect="move")}function ir(B){if(t)return;const H=B.dataTransfer.getData(fT),xe=B.dataTransfer.getData(CL);if(!JC(H))return;B.preventDefault();const We=B.currentTarget.getBoundingClientRect(),ze={x:Math.max(32,B.clientX-We.left-84),y:Math.max(32,B.clientY-We.top-24)};if(xe)try{const Pt=JSON.parse(xe);if(Pt.code){ll(Pt,ze);return}}catch{}eo(H,ze)}}async function _L(n,e,t){if(e.has(t))return e.get(t)??null;try{const r=await n.MGetFlowContract(t);return e.set(t,r),r}catch{return null}}async function RL(n,e,t){try{return await n.MGetNodeAuthoringContract(e,t)}catch{return null}}async function VG(n,e,t){var s;const r=await RL(n,e,t.id);if(r)return r;const i=t.ruleCode?WD(t.type,t.ruleCode,t.data.contractRef):t.data.contractRef;if(!((s=i==null?void 0:i.sourceCode)!=null&&s.trim()))return null;try{const l=await n.MGetByReference(i);return{flowCode:e,nodeId:t.id,nodeType:t.type,ruleCode:t.ruleCode,order:t.data.order,dependsOn:t.data.dependsOn??[],requestScope:l.requestContract,responseDelta:l.responseContract}}catch{return null}}function FG(n){const e=nu(n.data);return{id:n.id,type:eT(n.type),label:n.data.label,ruleCode:n.data.ruleCode,feelExpression:e.language==="feel"?e.body:void 0,position:{x:n.position.x,y:n.position.y},data:qC(n.data)}}function XG(n){var e;return{id:n.id,source:n.source,target:n.target,label:typeof n.label=="string"?n.label:void 0,edgeType:Zx((e=n.data)==null?void 0:e.edgeType)}}function pT(n){const e=Ai(n);if(e.nodes.length===0)return e;const t=new Map;for(const h of e.nodes)t.set(h.id,[]);for(const h of e.edges){const m=t.get(h.target)??[];m.push(h.source),t.set(h.target,m)}const r=new Map,i=new Set,s=h=>{const m=r.get(h);if(m!==void 0)return m;if(i.has(h))return 0;i.add(h);const v=t.get(h)??[],y=v.length===0?0:Math.max(...v.map(x=>s(x)))+1;return i.delete(h),r.set(h,y),y},l=new Map;for(const h of e.nodes){const m=h.type==="trigger"?0:s(h.id),v=l.get(m)??[];v.push(h),l.set(m,v)}const c=e.nodes.map(h=>({...h}));for(const[h,m]of l)m.sort((v,y)=>{const x=v.data.order??Number.MAX_SAFE_INTEGER,S=y.data.order??Number.MAX_SAFE_INTEGER;return x!==S?x-S:(v.label??"").localeCompare(y.label??"")}).forEach((v,y)=>{const x=c.find(S=>S.id===v.id);x&&(x.position={x:80+h*260,y:120+y*150})});return{...e,nodes:c}}function WG(n){const e=n.nodes.filter(i=>i.type!=="trigger"&&i.type!=="end"&&(i.ruleCode??"").trim().length>0),t=new Map(e.map(i=>[i.ruleCode??i.id,i])),r=new Map;for(const i of e)for(const s of i.data.dependsOn??[]){const l=r.get(s)??[];l.push(i.ruleCode??i.id),r.set(s,l)}return e.map(i=>{const s=i.ruleCode??i.id,l=(r.get(s)??[]).filter(c=>t.has(c)).sort((c,h)=>c.localeCompare(h));return{nodeId:i.id,label:i.label,ruleCode:s,order:i.data.order??0,dependsOn:[...i.data.dependsOn??[]].sort((c,h)=>c.localeCompare(h)),dependents:l}}).sort((i,s)=>i.order!==s.order?i.order-s.order:(i.label??"").localeCompare(s.label??""))}function PL(n,e){const t=e==="input"?n.inputColumns:n.outputColumns;return{contractName:`${n.id}_${e}`,title:e==="input"?"Decision Table Inputs":"Decision Table Outputs",description:n.description,rootType:"object",fields:t.map(r=>({path:r.name,label:r.label,dataType:r.dataType,required:e==="input",runtimeWritten:e==="output",description:`${e==="input"?"Input":"Output"} column from decision table '${n.name}'.`}))}}function HG({warnings:n,onCancel:e,onConfirm:t}){return C.jsx("div",{style:xK,children:C.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"rule-flow-publish-confirm-title",style:bK,children:[C.jsxs("div",{style:$L,children:[C.jsx("strong",{id:"rule-flow-publish-confirm-title",children:"Confirm Publish"}),C.jsx("span",{children:n.length>0?"This flow can publish, but warnings still exist. Review them before continuing.":"This will hand the current validated graph to the host publish handler."})]}),n.length>0?C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:n.map((r,i)=>C.jsxs("div",{style:oG,children:[C.jsx("strong",{children:r.code})," ",r.message]},`${r.code}-${r.message}-${i}`))}):null,C.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--mu-space-sm)"},children:[C.jsx("button",{type:"button",style:xa(!1),onClick:e,children:"Cancel"}),C.jsx("button",{type:"button",style:xa(!0),onClick:t,children:n.length>0?"Publish With Warnings":"Confirm Publish"})]})]})})}function YG(n,e){const t=D9(n),r=new Blob([t],{type:"application/json"}),i=URL.createObjectURL(r),s=document.createElement("a");s.style.display="none",s.href=i,s.download=`${e??"rule-flow"}.json`,document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(i),100)}function qG({selectedEdge:n,readOnly:e,onUpdateEdgeType:t,onDeleteEdge:r}){var s;if(!n)return C.jsx("div",{style:{color:"var(--mu-text-muted)",fontSize:13,lineHeight:1.5},children:"Select a node or edge to edit it. Use edge routing to decide whether downstream nodes run `always`, `on pass`, `on fail`, or `on error`."});const i=Zx((s=n.data)==null?void 0:s.edgeType);return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14,minHeight:0},children:[C.jsxs("div",{style:$L,children:[C.jsx("strong",{children:"Edge Routing"}),C.jsxs("span",{children:[n.source," → ",n.target]})]}),C.jsxs("label",{style:dK,children:["Edge Type",C.jsx("select",{style:hK,value:i,disabled:e,onChange:l=>t(Zx(l.target.value)),children:["always","on-true","on-false","on-error"].map(l=>C.jsx("option",{value:l,children:dT[l]},l))})]}),C.jsxs("div",{style:pK,children:[C.jsx("strong",{children:dT[i]}),C.jsx("span",{children:DG[i]})]}),e?null:C.jsx("button",{type:"button",style:mK,onClick:r,children:"Delete Edge"})]})}const GG={display:"grid",gap:"var(--mu-space-sm)",minHeight:0,height:"100%",width:"100%",minWidth:0,overflow:"auto"},KG={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},JG={display:"flex",flex:"1 1 auto",minHeight:0},eK={position:"relative",minWidth:0,borderRadius:24,overflow:"hidden",border:"1px solid var(--mu-border-subtle)"},$L={display:"flex",flexDirection:"column",gap:4,fontSize:13,color:"var(--mu-text-muted)"},tK={display:"flex",flexDirection:"column",gap:6,padding:20,borderRadius:18,border:"1px solid var(--mu-color-warning-border)",background:"var(--mu-color-warning-bg)",color:"var(--mu-color-warning-text)"},nK=n=>({display:"flex",flexDirection:"column",gap:4,padding:"10px 12px",borderRadius:14,border:n?"1px solid var(--mu-color-error-border)":"1px solid var(--mu-color-warning-border)",background:n?"var(--mu-color-error-bg)":"var(--mu-color-warning-bg)",color:n?"var(--mu-color-error-text)":"var(--mu-color-warning-text)",fontSize:12}),ML={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",minHeight:0,height:"100%",overflow:"auto",paddingRight:4};function rK(n){return{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:999,background:"var(--mu-border-subtle)",color:"var(--mu-text-secondary)",fontSize:14,transform:n?"rotate(180deg)":"rotate(0deg)",transition:"transform 160ms ease"}}function iK(n,e){const t=(e==null?void 0:e.paletteBtnBorderAlpha)??"22",r=(e==null?void 0:e.paletteBtnBgAlpha)??"10";return{display:"flex",flexDirection:"column",gap:4,borderRadius:14,border:`1px solid ${Av[n]}${t}`,background:`${Av[n]}${r}`,color:(e==null?void 0:e.textPrimary)??"var(--mu-text-primary)",padding:"11px 12px",textAlign:"left",fontWeight:600,cursor:"grab"}}function oK(n,e,t=280,r=!1){if(n)return{gridTemplateColumns:"minmax(0, 1fr)",alignContent:"start"};const i=r?"48px":`${t}px`;return{gridTemplateColumns:e?`${i} minmax(0, 1fr) minmax(320px, 420px)`:`${i} minmax(0, 1fr)`,alignContent:"stretch"}}const aK={display:"flex",flexDirection:"column",gap:0,borderRadius:18,minHeight:0,overflow:"auto"},sK={display:"flex",flexDirection:"column",gap:0,borderRadius:18,minHeight:0,overflow:"auto"};function mT(n){return{background:"transparent",border:"none",cursor:"pointer",fontSize:11,color:n.textMuted,padding:"2px 4px",borderRadius:4,whiteSpace:"nowrap"}}const gT={display:"block",width:"100%",textAlign:"left",padding:"8px 14px",background:"transparent",border:"none",cursor:"pointer",fontSize:13,borderRadius:0},lK={position:"absolute",top:12,left:12,zIndex:3,borderRadius:14,padding:"8px 12px",maxWidth:"calc(100% - 24px)"};function uK(n){return{minHeight:n?420:640,order:n?-1:0}}function cK(n){return{}}function fK(n){return{}}const dK={display:"flex",flexDirection:"column",gap:6,fontSize:12,color:"var(--mu-text-secondary)",fontWeight:600},hK={width:"100%",borderRadius:12,border:"1px solid var(--mu-border-input)",background:"var(--mu-surface-input)",color:"var(--mu-text-primary)",minHeight:42,padding:"10px 12px",fontSize:14},pK={display:"flex",flexDirection:"column",gap:6,padding:"12px 14px",borderRadius:14,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-raised)",color:"var(--mu-text-label)",fontSize:12,lineHeight:1.5},mK={borderRadius:14,border:"1px solid var(--mu-color-error-border)",background:"var(--mu-color-error-bg)",color:"var(--mu-color-error-text)",padding:"11px 14px",fontWeight:700},gK={position:"absolute",top:16,right:16,zIndex:2,display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",width:"min(320px, calc(100% - 32px))",maxHeight:"calc(100% - 32px)",padding:14,borderRadius:18,overflow:"auto"},vK={display:"flex",flexDirection:"column",gap:4,fontSize:12,color:"var(--mu-text-muted)"},yK={display:"flex",flexDirection:"column",gap:8};function OK(n,e){return{display:"flex",flexDirection:"column",gap:4,width:"100%",textAlign:"left",padding:"10px 12px",borderRadius:14,border:n?(e==null?void 0:e.overlayItemSelectedBorder)??"1px solid var(--mu-color-interactive-border)":(e==null?void 0:e.overlayItemBorder)??"1px solid var(--mu-border-subtle)",background:n?(e==null?void 0:e.overlayItemSelectedBg)??"var(--mu-color-selected-bg)":(e==null?void 0:e.overlayItemBg)??"var(--mu-surface-raised)",color:(e==null?void 0:e.textPrimary)??"var(--mu-text-primary)",cursor:"pointer"}}const xK={position:"fixed",inset:0,zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--mu-surface-backdrop)"},bK={display:"flex",flexDirection:"column",gap:16,width:"min(560px, 100%)",padding:20,borderRadius:22,border:"1px solid var(--mu-border-default)",background:"var(--mu-surface-dialog)",boxShadow:"var(--mu-shadow-dialog)"},wK={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 16px",borderRadius:"18px 18px 0 0",minHeight:42},qu={display:"inline-flex",alignItems:"center",padding:"2px 10px",borderRadius:8,fontSize:12,fontWeight:600,letterSpacing:"0.02em"},SK={position:"absolute",top:"calc(100% + 4px)",right:0,zIndex:10,display:"flex",flexDirection:"column",gap:6,padding:"10px 14px",borderRadius:12,minWidth:200,maxWidth:360},AL={nodes:[zv("trigger",{x:80,y:180},{label:"Start"}),zv("end",{x:760,y:180},{label:"End"})],edges:[{id:"edge-trigger-end",source:"trigger-1",target:"end-1",edgeType:"always"}],metadata:{version:1}};class QL{static fromRuleSet(e){const t=iu(e),r=t.flowGraph;if(EK(r)){const v=vT({...r,metadata:{...r.metadata,workflowName:Rd(t.workflowName)??r.metadata.workflowName}}),y=r.nodes??[];return v.nodes=v.nodes.map((x,S)=>{const E=iu(y[S]),k=E.expressionLanguage,R=iu(E.data),P=R.connectorConfig,Q=typeof R.connectorType=="string"?R.connectorType:void 0;let A;if(P&&typeof P=="object"){const L=P;L.connectorConfig&&typeof L.connectorConfig=="object"?A={connectorType:typeof L.connectorType=="string"?L.connectorType:Q,connectorConfig:L.connectorConfig,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}:"url"in L||"method"in L||"body"in L||"operation"in L||"webhookUrl"in L||"to"in L||"key"in L?A={connectorType:typeof L.connectorType=="string"?L.connectorType:Q,connectorConfig:L,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}:A={connectorType:typeof L.connectorType=="string"?L.connectorType:Q,connectorConfig:void 0,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}}return{...x,expressionLanguage:k==="feel"||k==="javascript"?k:void 0,data:{...x.data,connectorConfig:A}}}),v}const i=Rd(t.workflowName)??Rd(t.WorkflowName)??"wf.new",s=CK(t);if(s.length===0)return{...AL,metadata:{...AL.metadata,workflowName:i}};const l=[zv("trigger",{x:80,y:180},{label:"Start"})],c=[];let h="trigger-1";for(let v=0;v<s.length;v+=1){const y=s[v],x=zv("condition",{x:220+v*220,y:180},{label:y,ruleCode:y,nodeId:y});l.push(x),c.push({id:`edge-${h}-${x.id}`,source:h,target:x.id,edgeType:"always"}),h=x.id}const m=zv("end",{x:220+s.length*220,y:180},{label:"End"});return l.push(m),c.push({id:`edge-${h}-${m.id}`,source:h,target:m.id,edgeType:"always"}),{nodes:l,edges:c,metadata:{version:1,workflowName:i}}}static toRuleSet(e,t){const r=iu(t),i=vT(e),s=kK(i),l=e.metadata.workflowName??e.metadata.ruleSetCode??Rd(r.workflowName)??Rd(r.WorkflowName)??"wf.new",c={...i,nodes:i.nodes.map(h=>{var v;const m={...h};return h.expressionLanguage&&(m.expressionLanguage=h.expressionLanguage),(v=h.data)!=null&&v.connectorConfig&&(m.data={...m.data,connectorConfig:h.data.connectorConfig}),m})};return{...r,workflowName:l,rules:s,flowGraph:c}}static serialize(e){return JSON.stringify(vT(e),null,2)}}function kK(n){var l,c,h;const e=new Map(n.nodes.map(m=>[m.id,m])),t=new Map;for(const m of n.edges){const v=t.get(m.source)??[];v.push(m),t.set(m.source,v)}const r=new Set,i=[];let s=((l=n.nodes.find(m=>m.type==="trigger"))==null?void 0:l.id)??((c=n.nodes[0])==null?void 0:c.id);for(;s&&!r.has(s);){r.add(s);const m=e.get(s);if(m&&m.type!=="trigger"&&m.type!=="end"){const y=((h=m.ruleCode)==null?void 0:h.trim())||m.label.trim();y.length>0&&!i.includes(y)&&i.push(y)}const v=(t.get(s)??[]).slice().sort((y,x)=>(y.target??"").localeCompare(x.target??""))[0];s=v==null?void 0:v.target}return i.length>0?i:n.nodes.filter(m=>m.type!=="trigger"&&m.type!=="end").map(m=>{var v;return((v=m.ruleCode)==null?void 0:v.trim())||m.label.trim()}).filter(m=>m.length>0)}function CK(n){return(Array.isArray(n.rules)?n.rules:Array.isArray(n.Rules)?n.Rules:[]).map(t=>typeof t=="string"?t:iu(t).RuleName&&typeof iu(t).RuleName=="string"?iu(t).RuleName:Rd(iu(t).ruleCode)??Rd(iu(t).code)??"").map(t=>t.trim()).filter(t=>t.length>0)}function vT(n){var e,t,r;return{nodes:n.nodes.map((i,s)=>{var l,c,h,m,v;return{...i,id:i.id||`${i.type}-${s+1}`,label:i.label.trim()||`${TK(i.type)} ${s+1}`,expressionLanguage:i.expressionLanguage==="feel"||i.expressionLanguage==="javascript"?i.expressionLanguage:void 0,position:{x:Number.isFinite((l=i.position)==null?void 0:l.x)?i.position.x:s*220,y:Number.isFinite((c=i.position)==null?void 0:c.y)?i.position.y:180},data:{...i.data??{},outputFields:i.type==="condition"?(()=>{var E,k,R;const y=(((k=(E=i.data)==null?void 0:E.contractOverride)==null?void 0:k.responseFields)??[]).filter(P=>!P.isResultPayload&&typeof P.valueExpression=="string"&&P.valueExpression.trim().length>0).map(P=>({path:P.path,valueExpression:P.valueExpression,dataType:P.dataType,runtimeWritten:!0})),x=(Array.isArray((R=i.data)==null?void 0:R.outputFields)?i.data.outputFields:[]).filter(P=>typeof(P==null?void 0:P.path)=="string"&&P.path.trim().length>0&&(!P.valueExpression||!P.valueExpression.trim())).map(P=>({path:P.path,valueExpression:P.valueExpression??"",dataType:P.dataType??"string",runtimeWritten:!0})),S=new Set(y.map(P=>P.path));return[...y,...x.filter(P=>!S.has(P.path))]})():(h=i.data)==null?void 0:h.outputFields,connectorConfig:(m=i.data)==null?void 0:m.connectorConfig,contractRef:i.type!=="trigger"&&i.type!=="end"&&i.ruleCode?{sourceType:i.type==="decision-table"?"decision-table":i.type==="sub-flow"?"flow":i.type==="connector"?"api":"rule",sourceCode:i.ruleCode}:((v=i.data)==null?void 0:v.contractRef)??void 0}}}),edges:n.edges.map((i,s)=>({...i,id:i.id||`edge-${s+1}`,edgeType:i.edgeType??"always"})),metadata:{version:((e=n.metadata)==null?void 0:e.version)??1,workflowName:((t=n.metadata)==null?void 0:t.workflowName)??((r=n.metadata)==null?void 0:r.ruleSetCode)}}}function zv(n,e,t){var i;const r=n==="trigger"||n==="end"?"1":`${Math.abs(e.x)}`;return{id:((i=t.nodeId)==null?void 0:i.trim())||`${n}-${r}`,type:n,label:t.label,ruleCode:t.ruleCode,position:e,data:t.ruleCode?{contractRef:{sourceType:"rule",sourceCode:t.ruleCode}}:{}}}function TK(n){return n.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function Rd(n){return typeof n=="string"&&n.trim().length>0?n.trim():void 0}function iu(n){return n!==null&&typeof n=="object"?n:{}}function EK(n){const e=iu(n);return Array.isArray(e.nodes)&&Array.isArray(e.edges)&&e.metadata!==void 0}var _K=Object.defineProperty,RK=Object.getOwnPropertyDescriptor,ks=(n,e,t,r)=>{for(var i=r>1?void 0:r?RK(e,t):e,s=n.length-1,l;s>=0;s--)(l=n[s])&&(i=(r?l(e,t,i):l(i))||i);return r&&i&&_K(e,t,i),i};const DL="rule-flow-designer";let ba=class extends ed{constructor(){super(...arguments),this.graph=FO(),this.graphJson="",this.readOnly=!1,this.theme="light",this.apiBaseUrl="",this.catalogApiBase="",this.height=640,this.workflowCode="",this.tenantId="",this.showHeader=!0,this.version=null,this.mInternalGraphUpdate=!1,this.mLastGraphSignature=Qi(this.graph),this.mWorkflowLoadVersion=0,this.mLoadedRuleSet=null}connectedCallback(){super.connectedCallback(),this.MUpgradeProperty("graph"),this.MUpgradeProperty("graphJson"),this.MUpgradeProperty("readOnly"),this.MUpgradeProperty("theme"),this.MUpgradeProperty("apiBaseUrl"),this.MUpgradeProperty("catalogApiBase"),this.MUpgradeProperty("height"),this.MUpgradeProperty("workflowCode"),this.MUpgradeProperty("tenantId"),this.MUpgradeProperty("showHeader"),this.MUpgradeProperty("version"),this.MSyncGraphFromJson()}firstUpdated(){queueMicrotask(()=>{this.MRenderEditor(),this.graphJson.trim()||this.MLoadWorkflowGraphAsync()})}updated(n){if(n.has("graphJson")&&!this.mInternalGraphUpdate&&this.MSyncGraphFromJsonIfNeeded()){this.MRenderEditor();return}if(n.has("version")){this.mInternalGraphUpdate=!0,this.graphJson.trim()&&(this.graphJson=""),this.graph=FO(),this.mLastGraphSignature=Qi(this.graph),this.MLoadWorkflowGraphAsync();return}!this.mInternalGraphUpdate&&(n.has("graph")||n.has("graphJson")||n.has("readOnly")||n.has("theme")||n.has("apiBaseUrl")||n.has("catalogApiBase")||n.has("height")||n.has("tenantId")||n.has("showHeader"))&&this.MRenderEditor(),(n.has("workflowCode")||n.has("apiBaseUrl")||n.has("tenantId"))&&!this.graphJson.trim()&&this.MLoadWorkflowGraphAsync(),this.mInternalGraphUpdate&&(n.has("graphJson")||n.has("graph"))&&(this.mInternalGraphUpdate=!1,this.MRenderEditor())}disconnectedCallback(){var n;(n=this.mRoot)==null||n.unmount(),this.mRoot=void 0,super.disconnectedCallback()}render(){const n=v2(DL);return n||xr`<section id="editor-host" class="block h-full min-h-[640px] w-full"></section>`}MUpgradeProperty(n){if(!Object.prototype.hasOwnProperty.call(this,n))return;const e=Reflect.get(this,n);Reflect.deleteProperty(this,n),Reflect.set(this,n,e)}MSyncGraphFromJson(){if(!this.graphJson.trim()){this.graph=Ai(this.graph),this.mLastGraphSignature=Qi(this.graph);return}try{this.graph=Ai(JSON.parse(this.graphJson)),this.mLastGraphSignature=Qi(this.graph)}catch{this.graph=FO(),this.mLastGraphSignature=Qi(this.graph)}}MSyncGraphFromJsonIfNeeded(){if(!this.graphJson.trim())return!1;try{const n=Ai(JSON.parse(this.graphJson)),e=Qi(n);return e===this.mLastGraphSignature?!1:(this.graph=n,this.mLastGraphSignature=e,!0)}catch{return!1}}MRenderEditor(){var t,r;if(v2(DL)){(t=this.mRoot)==null||t.unmount(),this.mRoot=void 0;return}const e=(r=this.renderRoot)==null?void 0:r.querySelector("#editor-host");e&&(this.mRoot??(this.mRoot=W3.createRoot(e)),this.mRoot.render(q.createElement(UG,{graph:this.graph,readOnly:this.readOnly,theme:this.theme,apiBaseUrl:this.apiBaseUrl||void 0,catalogApiBase:this.catalogApiBase||void 0,tenantId:this.tenantId||void 0,workflowCode:this.workflowCode||void 0,height:this.height,showHeader:this.showHeader,version:this.version,editorRoot:this.renderRoot,onVersionChange:i=>{this.version=i,this.dispatchEvent(new CustomEvent("version-change",{detail:{version:i},bubbles:!0,composed:!0}))},onGraphChange:i=>{const s=Qi(i);s!==this.mLastGraphSignature&&(this.mInternalGraphUpdate=!0,this.graph=i,this.mLastGraphSignature=s,this.graphJson=JSON.stringify(i),this.dispatchEvent(new CustomEvent("graph-change",{detail:i,bubbles:!0,composed:!0})))},onPublish:async i=>{await this.MPublishGraphAsync(i)}})))}async MPublishGraphAsync(n){const e=QL.toRuleSet(n,this.mLoadedRuleSet??void 0);this.mLoadedRuleSet=e;const t={graph:n,ruleSet:e};if(this.dispatchEvent(new CustomEvent("publish-start",{detail:t,bubbles:!0,composed:!0})),!this.apiBaseUrl.trim()||!this.workflowCode.trim()){this.dispatchEvent(new CustomEvent("publish",{detail:t,bubbles:!0,composed:!0}));return}try{const r=await this.MPersistRuleSetAsync(t);this.setAttribute("data-last-publish-status",r.status??"Active"),this.setAttribute("data-last-publish-approval",String(r.approvalWorkflowEnabled)),this.dispatchEvent(new CustomEvent("publish-complete",{detail:r,bubbles:!0,composed:!0}))}catch(r){const i=r instanceof Error?r.message:"Rule Studio publish failed.";throw this.dispatchEvent(new CustomEvent("publish-error",{detail:{message:i,graph:n,ruleSet:e},bubbles:!0,composed:!0})),r}}async MPersistRuleSetAsync(n){const e=this.workflowCode.trim(),t=this.apiBaseUrl.replace(/\/$/,""),r="ui-studio",i=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}`,{method:"POST",body:JSON.stringify({ruleSet:n.ruleSet,activateAfterSave:!1,actor:r})}),s=Number(i.savedVersion??0);if(!Number.isFinite(s)||s<=0)throw new Error("Rule Studio publish did not return a saved version.");const l=!!i.approvalWorkflowEnabled;let c=!!i.activated,h=typeof i.activeVersion=="number"?i.activeVersion:null,m=typeof i.status=="string"?i.status:void 0,v=`Saved version ${s}.`;if(l){const y=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}/${s}/submit`,{method:"POST",body:JSON.stringify({actor:r})});m=typeof y.status=="string"?y.status:m,v=`Saved version ${s} and submitted for approval.`}else if(!c||h!==s){const y=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}/${s}/activate`,{method:"POST",body:JSON.stringify({actor:r})});c=!0,h=typeof y.activeVersion=="number"?y.activeVersion:s,m="Active",v=`Saved version ${s} and activated it.`}else v=`Saved version ${s} and activated it.`;return{...n,savedVersion:s,activeVersion:h,approvalWorkflowEnabled:l,activated:c,status:m,message:v}}async MRequestJson(n,e){const t=Zo(e.headers,{tenantId:this.tenantId});!t.has("Content-Type")&&e.body&&t.set("Content-Type","application/json"),t.has("Accept")||t.set("Accept","application/json");const r=await fetch(n,{...e,headers:t});if(!r.ok){const i=await r.text();throw new Error(i||`Rule Studio request failed: ${r.status} ${r.statusText}`)}return await r.json()}async MLoadWorkflowGraphAsync(){const n=this.workflowCode.trim(),e=this.apiBaseUrl.trim();if(!n||!e||this.graphJson.trim())return;const t=++this.mWorkflowLoadVersion,r=this.version!=null?`?version=${this.version}`:"",i=`${e.replace(/\/$/,"")}/rulesets/${encodeURIComponent(n)}/export${r}`;try{const s=await fetch(i,{headers:Zo(void 0,{tenantId:this.tenantId})});if(!s.ok)return;const l=await s.json();if(t!=this.mWorkflowLoadVersion||!l.ruleSetJson)return;const c=JSON.parse(l.ruleSetJson);this.mLoadedRuleSet=c;const h=Ai(QL.fromRuleSet(c));this.mInternalGraphUpdate=!0,this.graph=h,this.mLastGraphSignature=Qi(h),this.graphJson=JSON.stringify(h)}catch{}}};ba.styles=[N1(iI),N1(oI)],ks([ci({attribute:!1})],ba.prototype,"graph",2),ks([ci({type:String,attribute:"graph-json"})],ba.prototype,"graphJson",2),ks([ci({type:Boolean,attribute:"read-only"})],ba.prototype,"readOnly",2),ks([ci({type:String})],ba.prototype,"theme",2),ks([ci({type:String,attribute:"api-base-url"})],ba.prototype,"apiBaseUrl",2),ks([ci({type:String,attribute:"catalog-api-base"})],ba.prototype,"catalogApiBase",2),ks([ci({type:Number})],ba.prototype,"height",2),ks([ci({type:String,attribute:"workflow-code"})],ba.prototype,"workflowCode",2),ks([ci({type:String,attribute:"tenant-id"})],ba.prototype,"tenantId",2),ks([ci({type:Boolean,attribute:"show-header"})],ba.prototype,"showHeader",2),ks([ci({type:Number})],ba.prototype,"version",2),ba=ks([F1("mu-rule-flow-designer")],ba);class LL{constructor(e,t){this.baseUrl=e,this.mGetHeaders=t}async mFetch(e,t){var l;const r=((l=this.mGetHeaders)==null?void 0:l.call(this))??Zo(),i=new Headers(r);t!=null&&t.headers&&new Headers(t.headers).forEach((h,m)=>i.set(m,h));const s=await fetch(`${this.baseUrl}${e}`,{...t,headers:i});if(!s.ok)throw new Error(`Trace API ${s.status}: ${await s.text()}`);return s.json()}async mEnableDebugger(e,t){await this.mFetch(`/muonroi/rule-debugger/${e}/enable`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})})}async mDisableDebugger(e){await this.mFetch(`/muonroi/rule-debugger/${e}/disable`,{method:"POST"})}async mQueryTraces(e,t){const r=new URLSearchParams;t!=null&&t.correlationId&&r.set("correlationId",t.correlationId),t!=null&&t.from&&r.set("from",t.from);const i=r.toString();return this.mFetch(`/muonroi/rule-debugger/${e}/traces${i?`?${i}`:""}`)}}var PK=Object.defineProperty,$K=Object.getOwnPropertyDescriptor,Xa=(n,e,t,r)=>{for(var i=r>1?void 0:r?$K(e,t):e,s=n.length-1,l;s>=0;s--)(l=n[s])&&(i=(r?l(e,t,i):l(i))||i);return r&&i&&PK(e,t,i),i};const MK=["BeforeEval","AfterEval","AfterExec","Error","Compensate"],AK=["before-eval","after-eval","after-exec","error","compensate"];let Ho=class extends ed{constructor(){super(...arguments),this.apiBaseUrl="",this.tenantId="",this.correlationId="",this.readOnly=!1,this.tracesJson="",this._traces=[],this._loading=!1,this._error=null,this._expandedIds=new Set,this._phaseFilter="all",this._successFilter="all",this._apiClient=null}connectedCallback(){super.connectedCallback(),this.apiBaseUrl&&(this._apiClient=new LL(this.apiBaseUrl))}updated(n){if(n.has("tracesJson")&&this.tracesJson)try{this._traces=JSON.parse(this.tracesJson)}catch{}n.has("apiBaseUrl")&&this.apiBaseUrl&&(this._apiClient=new LL(this.apiBaseUrl))}async loadTraces(){if(!(!this._apiClient||!this.tenantId)){this._loading=!0,this._error=null;try{this._traces=await this._apiClient.mQueryTraces(this.tenantId,{correlationId:this.correlationId||void 0})}catch(n){this._error=n instanceof Error?n.message:String(n)}finally{this._loading=!1}}}async enableDebugger(n=30){!this._apiClient||!this.tenantId||await this._apiClient.mEnableDebugger(this.tenantId,{durationMinutes:n})}async disableDebugger(){!this._apiClient||!this.tenantId||await this._apiClient.mDisableDebugger(this.tenantId)}_phaseLabel(n){return MK[n]??"Unknown"}_phaseClassSuffix(n){return AK[n]??"before-eval"}get _filteredTraces(){return this._traces.filter(n=>!(this._phaseFilter!=="all"&&n.phase!==this._phaseFilter||this._successFilter==="success"&&!n.isSuccess||this._successFilter==="failure"&&n.isSuccess))}_toggleExpand(n){const e=new Set(this._expandedIds);e.has(n)?e.delete(n):e.add(n),this._expandedIds=e}_formatJson(n){if(!n)return"—";try{return JSON.stringify(JSON.parse(n),null,2)}catch{return n}}render(){return xr`
363
363
  <div class="trace-viewer">
364
364
  <div class="trace-header">
365
365
  <span class="trace-title">Execution Traces</span>
@@ -54134,10 +54134,10 @@ function Aoe({
54134
54134
  }
54135
54135
  }
54136
54136
  ) : null,
54137
- /* @__PURE__ */ k.jsx(
54137
+ vf ? /* @__PURE__ */ k.jsx(
54138
54138
  uq,
54139
54139
  {
54140
- open: vf,
54140
+ open: !0,
54141
54141
  onClose: () => Yi(!1),
54142
54142
  versions: Hr,
54143
54143
  activeVersion: zt,
@@ -54148,7 +54148,7 @@ function Aoe({
54148
54148
  tenantId: c,
54149
54149
  tokens: qe
54150
54150
  }
54151
- )
54151
+ ) : null
54152
54152
  ] });
54153
54153
  function Xn(B) {
54154
54154
  if (t)
@@ -54925,7 +54925,11 @@ let ra = class extends dr {
54925
54925
  this.MRenderEditor();
54926
54926
  return;
54927
54927
  }
54928
- !this.mInternalGraphUpdate && (n.has("graph") || n.has("graphJson") || n.has("readOnly") || n.has("theme") || n.has("apiBaseUrl") || n.has("catalogApiBase") || n.has("height") || n.has("tenantId") || n.has("showHeader") || n.has("version")) && this.MRenderEditor(), n.has("version") && this.graphJson.trim() && (this.mInternalGraphUpdate = !0, this.graphJson = "", this.graph = Gw(), this.mLastGraphSignature = to(this.graph)), (n.has("workflowCode") || n.has("apiBaseUrl") || n.has("tenantId") || n.has("version")) && !this.graphJson.trim() && this.MLoadWorkflowGraphAsync(), this.mInternalGraphUpdate && (n.has("graphJson") || n.has("graph")) && (this.mInternalGraphUpdate = !1, this.MRenderEditor());
54928
+ if (n.has("version")) {
54929
+ this.mInternalGraphUpdate = !0, this.graphJson.trim() && (this.graphJson = ""), this.graph = Gw(), this.mLastGraphSignature = to(this.graph), this.MLoadWorkflowGraphAsync();
54930
+ return;
54931
+ }
54932
+ !this.mInternalGraphUpdate && (n.has("graph") || n.has("graphJson") || n.has("readOnly") || n.has("theme") || n.has("apiBaseUrl") || n.has("catalogApiBase") || n.has("height") || n.has("tenantId") || n.has("showHeader")) && this.MRenderEditor(), (n.has("workflowCode") || n.has("apiBaseUrl") || n.has("tenantId")) && !this.graphJson.trim() && this.MLoadWorkflowGraphAsync(), this.mInternalGraphUpdate && (n.has("graphJson") || n.has("graph")) && (this.mInternalGraphUpdate = !1, this.MRenderEditor());
54929
54933
  }
54930
54934
  disconnectedCallback() {
54931
54935
  var n;
@@ -731,7 +731,7 @@ React keys must be passed directly to JSX without using spread:
731
731
  0%, 100% { box-shadow: 0 0 8px var(--mu-color-interactive-subtle); }
732
732
  50% { box-shadow: 0 0 20px var(--mu-color-interactive-border), 0 0 40px var(--mu-color-interactive-subtle); }
733
733
  }
734
- `}),M.jsxs("div",{style:{flex:Hd?`0 0 ${100-K}%`:"1 1 auto",position:"relative",overflow:"hidden"},children:[M.jsx("div",{style:{...nnt,background:Yt.overlayBg,border:Yt.overlayBorder,boxShadow:Yt.overlayShadow},children:Cm}),O.length===0&&!Mt?M.jsx(Pit,{onAddTrigger:zf}):null,M.jsxs(Mqe,{proOptions:{hideAttribution:!0},style:{width:"100%",height:"100%"},colorMode:i==="dark"?"dark":"light",nodes:O,edges:D,nodeTypes:LX,onMoveStart:()=>{Ot.current=!1},onNodeDragStart:()=>{Ot.current=!1},onNodesChange:oe=>Pr(oe),onEdgesChange:oe=>Sr(oe),onConnect:oe=>{var jt;if(t)return;const be=pL(yo(dn.current,Y_e({...oe,label:"always",data:{edgeType:"always"}},wn.current)),{currentFlowContract:l?Cn.current.get(l):void 0,flowContractsByCode:Cn.current,nodeContractsById:Wn.current});if(!be.isValid){V({status:"error",message:((jt=be.issues[0])==null?void 0:jt.message)??"Cannot connect nodes because the new order violates dependencies."});return}const Ke=`${oe.source}-${oe.target}-${wn.current.length+1}`;Y(Ke),F(""),Kc(TX(be.graph),{syncViewport:!0})},onNodeClick:(oe,be)=>{Wd(be.id)},onEdgeClick:(oe,be)=>{Y(be.id),F(""),j("basic-info")},onPaneClick:()=>{F(""),Y(""),j("basic-info")},nodesConnectable:!Mt,nodesDraggable:!Mt,elementsSelectable:!0,children:[M.jsx(Fit,{nodeIds:O.map(oe=>oe.id),syncToken:Yn,hostElement:Ot.current?vo.current:null}),M.jsx(Bit,{}),M.jsx(cQe,{}),M.jsx(Zqe,{}),M.jsx(zqe,{})]}),Ha.length>0?M.jsxs("aside",{"data-testid":"rule-flow-dependency-overlay",style:{...unt,background:Yt.overlayBg,border:Yt.overlayBorder,boxShadow:Yt.overlayShadow},children:[M.jsxs("button",{type:"button",style:{...hnt,cursor:"pointer",background:"transparent",border:"none",width:"100%",textAlign:"left",display:"flex",alignItems:"center",justifyContent:"space-between"},onClick:()=>Pi(oe=>!oe),"aria-expanded":ws,children:[M.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:4},children:[M.jsx("strong",{children:"Execution Order"}),M.jsx("span",{style:{fontSize:12,color:Yt.textMuted},children:"Prerequisites and downstream dependents."})]}),M.jsx("span",{style:{...Yit(ws),width:22,height:22,fontSize:12},children:"▾"})]}),ws?M.jsx("div",{style:fnt,children:Ha.map(oe=>M.jsxs("button",{type:"button","data-testid":`dependency-overlay-${oe.ruleCode}`,style:gnt(oe.nodeId===A,Yt),onClick:()=>Wd(oe.nodeId),children:[M.jsxs("span",{style:{fontWeight:700,color:Yt.textPrimary},children:["#",oe.order," ",oe.label]}),M.jsx("span",{style:{fontSize:11,color:Yt.textSecondary},children:oe.ruleCode}),M.jsxs("span",{style:{fontSize:11,color:Yt.textMuted},children:["Depends on: ",oe.dependsOn.length>0?oe.dependsOn.join(", "):"none"]}),M.jsxs("span",{style:{fontSize:11,color:Yt.textMuted},children:["Unlocks: ",oe.dependents.length>0?oe.dependents.join(", "):"none"]})]},oe.nodeId))}):null]}):null]}),Hd?M.jsxs(M.Fragment,{children:[M.jsx("div",{onPointerDown:Ss,style:{height:4,cursor:"ns-resize",background:Yt.sidebarBorder.replace("1px solid ",""),transition:"background 150ms",flexShrink:0},onPointerEnter:oe=>{oe.currentTarget.style.background="var(--mu-color-interactive)"},onPointerLeave:oe=>{oe.currentTarget.style.background=Yt.sidebarBorder.replace("1px solid ","")}}),M.jsxs("div",{style:{flex:`0 0 ${K}%`,overflow:"auto",background:Yt.sidebarBg},children:[M.jsx(Det,{value:Yc,onChange:Ug,onReset:()=>Ug(at()),tokens:Yt,editorRoot:m}),M.jsxs("div",{style:{display:"flex",gap:8,padding:"8px 12px",background:Yt.sidebarBg},children:[M.jsx("button",{type:"button",onClick:()=>{Ji()},disabled:zu||!r||!l,style:{padding:"6px 16px",borderRadius:6,border:"none",cursor:"pointer",background:"var(--mu-color-success)",color:"var(--mu-text-on-accent)",fontWeight:600,fontSize:12,opacity:zu?.6:1},children:zu?"Executing...":"Execute"}),M.jsx("button",{type:"button",onClick:Jn,style:{padding:"6px 16px",borderRadius:6,cursor:"pointer",background:"transparent",border:Yt.actionSecondaryBorder,color:Yt.textSecondary,fontWeight:500,fontSize:12},children:"Cancel"})]}),xm||zu||Om?M.jsx(Iet,{result:xm,loading:zu,error:Om,onClose:Jn,onSelectNode:oe=>{const be=dn.current.find(Ke=>Ke.data.ruleCode===oe||Ke.data.label===oe);be&&Wd(be.id)},tokens:Yt}):null]})]}):null]}),$t||Mr?M.jsxs("aside",{"data-testid":"rule-flow-right-panel",style:{...int,background:Yt.sidebarBg,border:Yt.sidebarBorder},children:[M.jsxs("div",{style:{padding:"12px 14px 8px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[M.jsx("strong",{style:{fontSize:13,color:Yt.textPrimary},children:"Inspector"}),M.jsx("button",{type:"button",style:{background:"transparent",border:"none",cursor:"pointer",color:Yt.textMuted,fontSize:14,padding:2},onClick:()=>{F(""),Y("")},title:"Close inspector",children:"✕"})]}),Py]}):null]}),Ct?M.jsx(zit,{warnings:Ct.warnings,onCancel:()=>Zt(null),onConfirm:()=>{(async()=>{var oe;try{V({status:"loading"}),await(c==null?void 0:c(Ct.graph)),Zt(null),V({status:"ready",title:"Published"}),Ye(0),xe(0,!1);const be=m instanceof ShadowRoot?m.host:null,Ke=(oe=be==null?void 0:be.getAttribute)==null?void 0:oe.call(be,"data-last-publish-status");(Ke==null?void 0:Ke.toLowerCase())==="pendingapproval"||(Ke==null?void 0:Ke.toLowerCase())==="draft"?Vt("Rule saved and submitted for approval."):Vt("Rule published and activated successfully.")}catch(be){Zt(null),V({status:"error",message:be.message||"Rule Studio publish failed."}),Bi(`Publish failed: ${be.message||"Unknown error"}`)}})()}}):null,M.jsx(vQe,{open:uO,onClose:()=>pc(!1),versions:St,activeVersion:Di,initialLeftVersion:(Di==null?void 0:Di.version)??null,initialRightVersion:f??null,apiBaseUrl:r??"",workflowCode:l??"",tenantId:a,tokens:Yt})]});function Pr(oe){if(t)return;const be=Vbe(oe,dn.current);if(ni.current){L(be);return}const Ke=be.filter(kr=>kr.selected).map(kr=>kr.id);F(Ke[0]??A);const jt=oe.some(kr=>kr.type==="add"||kr.type==="remove"||kr.type==="replace"),Dt=oe.filter(kr=>kr.type==="position"),un=Dt.some(kr=>kr.dragging),Vn=Dt.length>0&&!un;if(!jt&&!Vn){L(be);return}Vn&&(Ot.current=!1),Kc(yo(be,wn.current))}function Sr(oe){if(t)return;const be=zbe(oe,wn.current);if(ni.current){R(k(be));return}const Ke=be.filter(Dt=>Dt.selected).map(Dt=>Dt.id);if(Y(Ke[0]??$),!oe.some(Dt=>Dt.type==="add"||Dt.type==="remove"||Dt.type==="replace")){R(k(be));return}Kc(yo(dn.current,be))}function qn(oe,be,Ke){t||(oe.dataTransfer.setData(OX,be),oe.dataTransfer.setData("text/plain",be),Ke&&oe.dataTransfer.setData(qCe,JSON.stringify(Ke)),oe.dataTransfer.effectAllowed="move")}function xr(oe){t||!oe.dataTransfer.types.includes(OX)||(oe.preventDefault(),oe.dataTransfer.dropEffect="move")}function ho(oe){if(t)return;const be=oe.dataTransfer.getData(OX),Ke=oe.dataTransfer.getData(qCe);if(!gX(be))return;oe.preventDefault();const jt=oe.currentTarget.getBoundingClientRect(),Dt={x:Math.max(32,oe.clientX-jt.left-84),y:Math.max(32,oe.clientY-jt.top-24)};if(Ke)try{const un=JSON.parse(Ke);if(un.code){wm(un,Dt);return}}catch{}Zc(be,Dt)}}async function ZCe(s,e,t){if(e.has(t))return e.get(t)??null;try{const i=await s.MGetFlowContract(t);return e.set(t,i),i}catch{return null}}async function XCe(s,e,t){try{return await s.MGetNodeAuthoringContract(e,t)}catch{return null}}async function $it(s,e,t){var r;const i=await XCe(s,e,t.id);if(i)return i;const n=t.ruleCode?gCe(t.type,t.ruleCode,t.data.contractRef):t.data.contractRef;if(!((r=n==null?void 0:n.sourceCode)!=null&&r.trim()))return null;try{const o=await s.MGetByReference(n);return{flowCode:e,nodeId:t.id,nodeType:t.type,ruleCode:t.ruleCode,order:t.data.order,dependsOn:t.data.dependsOn??[],requestScope:o.requestContract,responseDelta:o.responseContract}}catch{return null}}function Wit(s){const e=b_(s.data);return{id:s.id,type:pX(s.type),label:s.data.label,ruleCode:s.data.ruleCode,feelExpression:e.language==="feel"?e.body:void 0,position:{x:s.position.x,y:s.position.y},data:uX(s.data)}}function Hit(s){var e;return{id:s.id,source:s.source,target:s.target,label:typeof s.label=="string"?s.label:void 0,edgeType:a8((e=s.data)==null?void 0:e.edgeType)}}function TX(s){const e=Cl(s);if(e.nodes.length===0)return e;const t=new Map;for(const l of e.nodes)t.set(l.id,[]);for(const l of e.edges){const c=t.get(l.target)??[];c.push(l.source),t.set(l.target,c)}const i=new Map,n=new Set,r=l=>{const c=i.get(l);if(c!==void 0)return c;if(n.has(l))return 0;n.add(l);const d=t.get(l)??[],u=d.length===0?0:Math.max(...d.map(f=>r(f)))+1;return n.delete(l),i.set(l,u),u},o=new Map;for(const l of e.nodes){const c=l.type==="trigger"?0:r(l.id),d=o.get(c)??[];d.push(l),o.set(c,d)}const a=e.nodes.map(l=>({...l}));for(const[l,c]of o)c.sort((d,u)=>{const f=d.data.order??Number.MAX_SAFE_INTEGER,p=u.data.order??Number.MAX_SAFE_INTEGER;return f!==p?f-p:(d.label??"").localeCompare(u.label??"")}).forEach((d,u)=>{const f=a.find(p=>p.id===d.id);f&&(f.position={x:80+l*260,y:120+u*150})});return{...e,nodes:a}}function Vit(s){const e=s.nodes.filter(n=>n.type!=="trigger"&&n.type!=="end"&&(n.ruleCode??"").trim().length>0),t=new Map(e.map(n=>[n.ruleCode??n.id,n])),i=new Map;for(const n of e)for(const r of n.data.dependsOn??[]){const o=i.get(r)??[];o.push(n.ruleCode??n.id),i.set(r,o)}return e.map(n=>{const r=n.ruleCode??n.id,o=(i.get(r)??[]).filter(a=>t.has(a)).sort((a,l)=>a.localeCompare(l));return{nodeId:n.id,label:n.label,ruleCode:r,order:n.data.order??0,dependsOn:[...n.data.dependsOn??[]].sort((a,l)=>a.localeCompare(l)),dependents:o}}).sort((n,r)=>n.order!==r.order?n.order-r.order:(n.label??"").localeCompare(r.label??""))}function YCe(s,e){const t=e==="input"?s.inputColumns:s.outputColumns;return{contractName:`${s.id}_${e}`,title:e==="input"?"Decision Table Inputs":"Decision Table Outputs",description:s.description,rootType:"object",fields:t.map(i=>({path:i.name,label:i.label,dataType:i.dataType,required:e==="input",runtimeWritten:e==="output",description:`${e==="input"?"Input":"Output"} column from decision table '${s.name}'.`}))}}function zit({warnings:s,onCancel:e,onConfirm:t}){return M.jsx("div",{style:pnt,children:M.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"rule-flow-publish-confirm-title",style:mnt,children:[M.jsxs("div",{style:JCe,children:[M.jsx("strong",{id:"rule-flow-publish-confirm-title",children:"Confirm Publish"}),M.jsx("span",{children:s.length>0?"This flow can publish, but warnings still exist. Review them before continuing.":"This will hand the current validated graph to the host publish handler."})]}),s.length>0?M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:s.map((i,n)=>M.jsxs("div",{style:tit,children:[M.jsx("strong",{children:i.code})," ",i.message]},`${i.code}-${i.message}-${n}`))}):null,M.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--mu-space-sm)"},children:[M.jsx("button",{type:"button",style:ch(!1),onClick:e,children:"Cancel"}),M.jsx("button",{type:"button",style:ch(!0),onClick:t,children:s.length>0?"Publish With Warnings":"Confirm Publish"})]})]})})}function Uit(s,e){const t=uCe(s),i=new Blob([t],{type:"application/json"}),n=URL.createObjectURL(i),r=document.createElement("a");r.style.display="none",r.href=n,r.download=`${e??"rule-flow"}.json`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>URL.revokeObjectURL(n),100)}function jit({selectedEdge:s,readOnly:e,onUpdateEdgeType:t,onDeleteEdge:i}){var r;if(!s)return M.jsx("div",{style:{color:"var(--mu-text-muted)",fontSize:13,lineHeight:1.5},children:"Select a node or edge to edit it. Use edge routing to decide whether downstream nodes run `always`, `on pass`, `on fail`, or `on error`."});const n=a8((r=s.data)==null?void 0:r.edgeType);return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14,minHeight:0},children:[M.jsxs("div",{style:JCe,children:[M.jsx("strong",{children:"Edge Routing"}),M.jsxs("span",{children:[s.source," → ",s.target]})]}),M.jsxs("label",{style:ant,children:["Edge Type",M.jsx("select",{style:lnt,value:n,disabled:e,onChange:o=>t(a8(o.target.value)),children:["always","on-true","on-false","on-error"].map(o=>M.jsx("option",{value:o,children:EX[o]},o))})]}),M.jsxs("div",{style:cnt,children:[M.jsx("strong",{children:EX[n]}),M.jsx("span",{children:Iit[n]})]}),e?null:M.jsx("button",{type:"button",style:dnt,onClick:i,children:"Delete Edge"})]})}const qit={display:"grid",gap:"var(--mu-space-sm)",minHeight:0,height:"100%",width:"100%",minWidth:0,overflow:"auto"},Qit={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},Git={display:"flex",flex:"1 1 auto",minHeight:0},Kit={position:"relative",minWidth:0,borderRadius:24,overflow:"hidden",border:"1px solid var(--mu-border-subtle)"},JCe={display:"flex",flexDirection:"column",gap:4,fontSize:13,color:"var(--mu-text-muted)"},Zit={display:"flex",flexDirection:"column",gap:6,padding:20,borderRadius:18,border:"1px solid var(--mu-color-warning-border)",background:"var(--mu-color-warning-bg)",color:"var(--mu-color-warning-text)"},Xit=s=>({display:"flex",flexDirection:"column",gap:4,padding:"10px 12px",borderRadius:14,border:s?"1px solid var(--mu-color-error-border)":"1px solid var(--mu-color-warning-border)",background:s?"var(--mu-color-error-bg)":"var(--mu-color-warning-bg)",color:s?"var(--mu-color-error-text)":"var(--mu-color-warning-text)",fontSize:12}),eSe={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",minHeight:0,height:"100%",overflow:"auto",paddingRight:4};function Yit(s){return{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:999,background:"var(--mu-border-subtle)",color:"var(--mu-text-secondary)",fontSize:14,transform:s?"rotate(180deg)":"rotate(0deg)",transition:"transform 160ms ease"}}function Jit(s,e){const t=(e==null?void 0:e.paletteBtnBorderAlpha)??"22",i=(e==null?void 0:e.paletteBtnBgAlpha)??"10";return{display:"flex",flexDirection:"column",gap:4,borderRadius:14,border:`1px solid ${oM[s]}${t}`,background:`${oM[s]}${i}`,color:(e==null?void 0:e.textPrimary)??"var(--mu-text-primary)",padding:"11px 12px",textAlign:"left",fontWeight:600,cursor:"grab"}}function ent(s,e,t=280,i=!1){if(s)return{gridTemplateColumns:"minmax(0, 1fr)",alignContent:"start"};const n=i?"48px":`${t}px`;return{gridTemplateColumns:e?`${n} minmax(0, 1fr) minmax(320px, 420px)`:`${n} minmax(0, 1fr)`,alignContent:"stretch"}}const tnt={display:"flex",flexDirection:"column",gap:0,borderRadius:18,minHeight:0,overflow:"auto"},int={display:"flex",flexDirection:"column",gap:0,borderRadius:18,minHeight:0,overflow:"auto"};function DX(s){return{background:"transparent",border:"none",cursor:"pointer",fontSize:11,color:s.textMuted,padding:"2px 4px",borderRadius:4,whiteSpace:"nowrap"}}const IX={display:"block",width:"100%",textAlign:"left",padding:"8px 14px",background:"transparent",border:"none",cursor:"pointer",fontSize:13,borderRadius:0},nnt={position:"absolute",top:12,left:12,zIndex:3,borderRadius:14,padding:"8px 12px",maxWidth:"calc(100% - 24px)"};function snt(s){return{minHeight:s?420:640,order:s?-1:0}}function rnt(s){return{}}function ont(s){return{}}const ant={display:"flex",flexDirection:"column",gap:6,fontSize:12,color:"var(--mu-text-secondary)",fontWeight:600},lnt={width:"100%",borderRadius:12,border:"1px solid var(--mu-border-input)",background:"var(--mu-surface-input)",color:"var(--mu-text-primary)",minHeight:42,padding:"10px 12px",fontSize:14},cnt={display:"flex",flexDirection:"column",gap:6,padding:"12px 14px",borderRadius:14,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-raised)",color:"var(--mu-text-label)",fontSize:12,lineHeight:1.5},dnt={borderRadius:14,border:"1px solid var(--mu-color-error-border)",background:"var(--mu-color-error-bg)",color:"var(--mu-color-error-text)",padding:"11px 14px",fontWeight:700},unt={position:"absolute",top:16,right:16,zIndex:2,display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",width:"min(320px, calc(100% - 32px))",maxHeight:"calc(100% - 32px)",padding:14,borderRadius:18,overflow:"auto"},hnt={display:"flex",flexDirection:"column",gap:4,fontSize:12,color:"var(--mu-text-muted)"},fnt={display:"flex",flexDirection:"column",gap:8};function gnt(s,e){return{display:"flex",flexDirection:"column",gap:4,width:"100%",textAlign:"left",padding:"10px 12px",borderRadius:14,border:s?(e==null?void 0:e.overlayItemSelectedBorder)??"1px solid var(--mu-color-interactive-border)":(e==null?void 0:e.overlayItemBorder)??"1px solid var(--mu-border-subtle)",background:s?(e==null?void 0:e.overlayItemSelectedBg)??"var(--mu-color-selected-bg)":(e==null?void 0:e.overlayItemBg)??"var(--mu-surface-raised)",color:(e==null?void 0:e.textPrimary)??"var(--mu-text-primary)",cursor:"pointer"}}const pnt={position:"fixed",inset:0,zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--mu-surface-backdrop)"},mnt={display:"flex",flexDirection:"column",gap:16,width:"min(560px, 100%)",padding:20,borderRadius:22,border:"1px solid var(--mu-border-default)",background:"var(--mu-surface-dialog)",boxShadow:"var(--mu-shadow-dialog)"},_nt={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 16px",borderRadius:"18px 18px 0 0",minHeight:42},vv={display:"inline-flex",alignItems:"center",padding:"2px 10px",borderRadius:8,fontSize:12,fontWeight:600,letterSpacing:"0.02em"},bnt={position:"absolute",top:"calc(100% + 4px)",right:0,zIndex:10,display:"flex",flexDirection:"column",gap:6,padding:"10px 14px",borderRadius:12,minWidth:200,maxWidth:360},tSe={nodes:[dM("trigger",{x:80,y:180},{label:"Start"}),dM("end",{x:760,y:180},{label:"End"})],edges:[{id:"edge-trigger-end",source:"trigger-1",target:"end-1",edgeType:"always"}],metadata:{version:1}};class iSe{static fromRuleSet(e){const t=y_(e),i=t.flowGraph;if(Cnt(i)){const d=RX({...i,metadata:{...i.metadata,workflowName:oS(t.workflowName)??i.metadata.workflowName}}),u=i.nodes??[];return d.nodes=d.nodes.map((f,p)=>{const m=y_(u[p]),b=m.expressionLanguage,w=y_(m.data),S=w.connectorConfig,k=typeof w.connectorType=="string"?w.connectorType:void 0;let O;if(S&&typeof S=="object"){const L=S;L.connectorConfig&&typeof L.connectorConfig=="object"?O={connectorType:typeof L.connectorType=="string"?L.connectorType:k,connectorConfig:L.connectorConfig,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}:"url"in L||"method"in L||"body"in L||"operation"in L||"webhookUrl"in L||"to"in L||"key"in L?O={connectorType:typeof L.connectorType=="string"?L.connectorType:k,connectorConfig:L,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}:O={connectorType:typeof L.connectorType=="string"?L.connectorType:k,connectorConfig:void 0,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}}return{...f,expressionLanguage:b==="feel"||b==="javascript"?b:void 0,data:{...f.data,connectorConfig:O}}}),d}const n=oS(t.workflowName)??oS(t.WorkflowName)??"wf.new",r=ynt(t);if(r.length===0)return{...tSe,metadata:{...tSe.metadata,workflowName:n}};const o=[dM("trigger",{x:80,y:180},{label:"Start"})],a=[];let l="trigger-1";for(let d=0;d<r.length;d+=1){const u=r[d],f=dM("condition",{x:220+d*220,y:180},{label:u,ruleCode:u,nodeId:u});o.push(f),a.push({id:`edge-${l}-${f.id}`,source:l,target:f.id,edgeType:"always"}),l=f.id}const c=dM("end",{x:220+r.length*220,y:180},{label:"End"});return o.push(c),a.push({id:`edge-${l}-${c.id}`,source:l,target:c.id,edgeType:"always"}),{nodes:o,edges:a,metadata:{version:1,workflowName:n}}}static toRuleSet(e,t){const i=y_(t),n=RX(e),r=vnt(n),o=e.metadata.workflowName??e.metadata.ruleSetCode??oS(i.workflowName)??oS(i.WorkflowName)??"wf.new",a={...n,nodes:n.nodes.map(l=>{var d;const c={...l};return l.expressionLanguage&&(c.expressionLanguage=l.expressionLanguage),(d=l.data)!=null&&d.connectorConfig&&(c.data={...c.data,connectorConfig:l.data.connectorConfig}),c})};return{...i,workflowName:o,rules:r,flowGraph:a}}static serialize(e){return JSON.stringify(RX(e),null,2)}}function vnt(s){var o,a,l;const e=new Map(s.nodes.map(c=>[c.id,c])),t=new Map;for(const c of s.edges){const d=t.get(c.source)??[];d.push(c),t.set(c.source,d)}const i=new Set,n=[];let r=((o=s.nodes.find(c=>c.type==="trigger"))==null?void 0:o.id)??((a=s.nodes[0])==null?void 0:a.id);for(;r&&!i.has(r);){i.add(r);const c=e.get(r);if(c&&c.type!=="trigger"&&c.type!=="end"){const u=((l=c.ruleCode)==null?void 0:l.trim())||c.label.trim();u.length>0&&!n.includes(u)&&n.push(u)}const d=(t.get(r)??[]).slice().sort((u,f)=>(u.target??"").localeCompare(f.target??""))[0];r=d==null?void 0:d.target}return n.length>0?n:s.nodes.filter(c=>c.type!=="trigger"&&c.type!=="end").map(c=>{var d;return((d=c.ruleCode)==null?void 0:d.trim())||c.label.trim()}).filter(c=>c.length>0)}function ynt(s){return(Array.isArray(s.rules)?s.rules:Array.isArray(s.Rules)?s.Rules:[]).map(t=>typeof t=="string"?t:y_(t).RuleName&&typeof y_(t).RuleName=="string"?y_(t).RuleName:oS(y_(t).ruleCode)??oS(y_(t).code)??"").map(t=>t.trim()).filter(t=>t.length>0)}function RX(s){var e,t,i;return{nodes:s.nodes.map((n,r)=>{var o,a,l,c,d;return{...n,id:n.id||`${n.type}-${r+1}`,label:n.label.trim()||`${wnt(n.type)} ${r+1}`,expressionLanguage:n.expressionLanguage==="feel"||n.expressionLanguage==="javascript"?n.expressionLanguage:void 0,position:{x:Number.isFinite((o=n.position)==null?void 0:o.x)?n.position.x:r*220,y:Number.isFinite((a=n.position)==null?void 0:a.y)?n.position.y:180},data:{...n.data??{},outputFields:n.type==="condition"?(()=>{var m,b,w;const u=(((b=(m=n.data)==null?void 0:m.contractOverride)==null?void 0:b.responseFields)??[]).filter(S=>!S.isResultPayload&&typeof S.valueExpression=="string"&&S.valueExpression.trim().length>0).map(S=>({path:S.path,valueExpression:S.valueExpression,dataType:S.dataType,runtimeWritten:!0})),f=(Array.isArray((w=n.data)==null?void 0:w.outputFields)?n.data.outputFields:[]).filter(S=>typeof(S==null?void 0:S.path)=="string"&&S.path.trim().length>0&&(!S.valueExpression||!S.valueExpression.trim())).map(S=>({path:S.path,valueExpression:S.valueExpression??"",dataType:S.dataType??"string",runtimeWritten:!0})),p=new Set(u.map(S=>S.path));return[...u,...f.filter(S=>!p.has(S.path))]})():(l=n.data)==null?void 0:l.outputFields,connectorConfig:(c=n.data)==null?void 0:c.connectorConfig,contractRef:n.type!=="trigger"&&n.type!=="end"&&n.ruleCode?{sourceType:n.type==="decision-table"?"decision-table":n.type==="sub-flow"?"flow":n.type==="connector"?"api":"rule",sourceCode:n.ruleCode}:((d=n.data)==null?void 0:d.contractRef)??void 0}}}),edges:s.edges.map((n,r)=>({...n,id:n.id||`edge-${r+1}`,edgeType:n.edgeType??"always"})),metadata:{version:((e=s.metadata)==null?void 0:e.version)??1,workflowName:((t=s.metadata)==null?void 0:t.workflowName)??((i=s.metadata)==null?void 0:i.ruleSetCode)}}}function dM(s,e,t){var n;const i=s==="trigger"||s==="end"?"1":`${Math.abs(e.x)}`;return{id:((n=t.nodeId)==null?void 0:n.trim())||`${s}-${i}`,type:s,label:t.label,ruleCode:t.ruleCode,position:e,data:t.ruleCode?{contractRef:{sourceType:"rule",sourceCode:t.ruleCode}}:{}}}function wnt(s){return s.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function oS(s){return typeof s=="string"&&s.trim().length>0?s.trim():void 0}function y_(s){return s!==null&&typeof s=="object"?s:{}}function Cnt(s){const e=y_(s);return Array.isArray(e.nodes)&&Array.isArray(e.edges)&&e.metadata!==void 0}var Snt=Object.defineProperty,xnt=Object.getOwnPropertyDescriptor,fg=(s,e,t,i)=>{for(var n=i>1?void 0:i?xnt(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(n=(i?o(e,t,n):o(n))||n);return i&&n&&Snt(e,t,n),n};const nSe="rule-flow-designer";let dh=class extends to{constructor(){super(...arguments),this.graph=KN(),this.graphJson="",this.readOnly=!1,this.theme="light",this.apiBaseUrl="",this.catalogApiBase="",this.height=640,this.workflowCode="",this.tenantId="",this.showHeader=!0,this.version=null,this.mInternalGraphUpdate=!1,this.mLastGraphSignature=Sl(this.graph),this.mWorkflowLoadVersion=0,this.mLoadedRuleSet=null}connectedCallback(){super.connectedCallback(),this.MUpgradeProperty("graph"),this.MUpgradeProperty("graphJson"),this.MUpgradeProperty("readOnly"),this.MUpgradeProperty("theme"),this.MUpgradeProperty("apiBaseUrl"),this.MUpgradeProperty("catalogApiBase"),this.MUpgradeProperty("height"),this.MUpgradeProperty("workflowCode"),this.MUpgradeProperty("tenantId"),this.MUpgradeProperty("showHeader"),this.MUpgradeProperty("version"),this.MSyncGraphFromJson()}firstUpdated(){queueMicrotask(()=>{this.MRenderEditor(),this.graphJson.trim()||this.MLoadWorkflowGraphAsync()})}updated(s){if(s.has("graphJson")&&!this.mInternalGraphUpdate&&this.MSyncGraphFromJsonIfNeeded()){this.MRenderEditor();return}!this.mInternalGraphUpdate&&(s.has("graph")||s.has("graphJson")||s.has("readOnly")||s.has("theme")||s.has("apiBaseUrl")||s.has("catalogApiBase")||s.has("height")||s.has("tenantId")||s.has("showHeader")||s.has("version"))&&this.MRenderEditor(),s.has("version")&&this.graphJson.trim()&&(this.mInternalGraphUpdate=!0,this.graphJson="",this.graph=KN(),this.mLastGraphSignature=Sl(this.graph)),(s.has("workflowCode")||s.has("apiBaseUrl")||s.has("tenantId")||s.has("version"))&&!this.graphJson.trim()&&this.MLoadWorkflowGraphAsync(),this.mInternalGraphUpdate&&(s.has("graphJson")||s.has("graph"))&&(this.mInternalGraphUpdate=!1,this.MRenderEditor())}disconnectedCallback(){var s;(s=this.mRoot)==null||s.unmount(),this.mRoot=void 0,super.disconnectedCallback()}render(){const s=e_(nSe);return s||kt`<section id="editor-host" class="block h-full min-h-[640px] w-full"></section>`}MUpgradeProperty(s){if(!Object.prototype.hasOwnProperty.call(this,s))return;const e=Reflect.get(this,s);Reflect.deleteProperty(this,s),Reflect.set(this,s,e)}MSyncGraphFromJson(){if(!this.graphJson.trim()){this.graph=Cl(this.graph),this.mLastGraphSignature=Sl(this.graph);return}try{this.graph=Cl(JSON.parse(this.graphJson)),this.mLastGraphSignature=Sl(this.graph)}catch{this.graph=KN(),this.mLastGraphSignature=Sl(this.graph)}}MSyncGraphFromJsonIfNeeded(){if(!this.graphJson.trim())return!1;try{const s=Cl(JSON.parse(this.graphJson)),e=Sl(s);return e===this.mLastGraphSignature?!1:(this.graph=s,this.mLastGraphSignature=e,!0)}catch{return!1}}MRenderEditor(){var t,i;if(e_(nSe)){(t=this.mRoot)==null||t.unmount(),this.mRoot=void 0;return}const e=(i=this.renderRoot)==null?void 0:i.querySelector("#editor-host");e&&(this.mRoot??(this.mRoot=t9e.createRoot(e)),this.mRoot.render(ve.createElement(KCe,{graph:this.graph,readOnly:this.readOnly,theme:this.theme,apiBaseUrl:this.apiBaseUrl||void 0,catalogApiBase:this.catalogApiBase||void 0,tenantId:this.tenantId||void 0,workflowCode:this.workflowCode||void 0,height:this.height,showHeader:this.showHeader,version:this.version,editorRoot:this.renderRoot,onVersionChange:n=>{this.version=n,this.dispatchEvent(new CustomEvent("version-change",{detail:{version:n},bubbles:!0,composed:!0}))},onGraphChange:n=>{const r=Sl(n);r!==this.mLastGraphSignature&&(this.mInternalGraphUpdate=!0,this.graph=n,this.mLastGraphSignature=r,this.graphJson=JSON.stringify(n),this.dispatchEvent(new CustomEvent("graph-change",{detail:n,bubbles:!0,composed:!0})))},onPublish:async n=>{await this.MPublishGraphAsync(n)}})))}async MPublishGraphAsync(s){const e=iSe.toRuleSet(s,this.mLoadedRuleSet??void 0);this.mLoadedRuleSet=e;const t={graph:s,ruleSet:e};if(this.dispatchEvent(new CustomEvent("publish-start",{detail:t,bubbles:!0,composed:!0})),!this.apiBaseUrl.trim()||!this.workflowCode.trim()){this.dispatchEvent(new CustomEvent("publish",{detail:t,bubbles:!0,composed:!0}));return}try{const i=await this.MPersistRuleSetAsync(t);this.setAttribute("data-last-publish-status",i.status??"Active"),this.setAttribute("data-last-publish-approval",String(i.approvalWorkflowEnabled)),this.dispatchEvent(new CustomEvent("publish-complete",{detail:i,bubbles:!0,composed:!0}))}catch(i){const n=i instanceof Error?i.message:"Rule Studio publish failed.";throw this.dispatchEvent(new CustomEvent("publish-error",{detail:{message:n,graph:s,ruleSet:e},bubbles:!0,composed:!0})),i}}async MPersistRuleSetAsync(s){const e=this.workflowCode.trim(),t=this.apiBaseUrl.replace(/\/$/,""),i="ui-studio",n=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}`,{method:"POST",body:JSON.stringify({ruleSet:s.ruleSet,activateAfterSave:!1,actor:i})}),r=Number(n.savedVersion??0);if(!Number.isFinite(r)||r<=0)throw new Error("Rule Studio publish did not return a saved version.");const o=!!n.approvalWorkflowEnabled;let a=!!n.activated,l=typeof n.activeVersion=="number"?n.activeVersion:null,c=typeof n.status=="string"?n.status:void 0,d=`Saved version ${r}.`;if(o){const u=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}/${r}/submit`,{method:"POST",body:JSON.stringify({actor:i})});c=typeof u.status=="string"?u.status:c,d=`Saved version ${r} and submitted for approval.`}else if(!a||l!==r){const u=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}/${r}/activate`,{method:"POST",body:JSON.stringify({actor:i})});a=!0,l=typeof u.activeVersion=="number"?u.activeVersion:r,c="Active",d=`Saved version ${r} and activated it.`}else d=`Saved version ${r} and activated it.`;return{...s,savedVersion:r,activeVersion:l,approvalWorkflowEnabled:o,activated:a,status:c,message:d}}async MRequestJson(s,e){const t=hd(e.headers,{tenantId:this.tenantId});!t.has("Content-Type")&&e.body&&t.set("Content-Type","application/json"),t.has("Accept")||t.set("Accept","application/json");const i=await fetch(s,{...e,headers:t});if(!i.ok){const n=await i.text();throw new Error(n||`Rule Studio request failed: ${i.status} ${i.statusText}`)}return await i.json()}async MLoadWorkflowGraphAsync(){const s=this.workflowCode.trim(),e=this.apiBaseUrl.trim();if(!s||!e||this.graphJson.trim())return;const t=++this.mWorkflowLoadVersion,i=this.version!=null?`?version=${this.version}`:"",n=`${e.replace(/\/$/,"")}/rulesets/${encodeURIComponent(s)}/export${i}`;try{const r=await fetch(n,{headers:hd(void 0,{tenantId:this.tenantId})});if(!r.ok)return;const o=await r.json();if(t!=this.mWorkflowLoadVersion||!o.ruleSetJson)return;const a=JSON.parse(o.ruleSetJson);this.mLoadedRuleSet=a;const l=Cl(iSe.fromRuleSet(a));this.mInternalGraphUpdate=!0,this.graph=l,this.mLastGraphSignature=Sl(l),this.graphJson=JSON.stringify(l)}catch{}}};dh.styles=[Ho(La),Ho(i9e)],fg([Jt({attribute:!1})],dh.prototype,"graph",2),fg([Jt({type:String,attribute:"graph-json"})],dh.prototype,"graphJson",2),fg([Jt({type:Boolean,attribute:"read-only"})],dh.prototype,"readOnly",2),fg([Jt({type:String})],dh.prototype,"theme",2),fg([Jt({type:String,attribute:"api-base-url"})],dh.prototype,"apiBaseUrl",2),fg([Jt({type:String,attribute:"catalog-api-base"})],dh.prototype,"catalogApiBase",2),fg([Jt({type:Number})],dh.prototype,"height",2),fg([Jt({type:String,attribute:"workflow-code"})],dh.prototype,"workflowCode",2),fg([Jt({type:String,attribute:"tenant-id"})],dh.prototype,"tenantId",2),fg([Jt({type:Boolean,attribute:"show-header"})],dh.prototype,"showHeader",2),fg([Jt({type:Number})],dh.prototype,"version",2),dh=fg([Vo("mu-rule-flow-designer")],dh);var knt=Object.defineProperty,Ont=Object.getOwnPropertyDescriptor,g8=(s,e,t,i)=>{for(var n=i>1?void 0:i?Ont(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(n=(i?o(e,t,n):o(n))||n);return i&&n&&knt(e,t,n),n};const Ent="rule-test-runner";let mL=class extends to{constructor(){super(...arguments),this.testEndpoint="",this.mPayload='{"facts": []}',this.mResult=""}async MRun(){this.dispatchEvent(new CustomEvent("run",{detail:{payload:this.mPayload},bubbles:!0,composed:!0})),this.mResult="Rule test request dispatched."}render(){const s=e_(Ent);return s||kt`
734
+ `}),M.jsxs("div",{style:{flex:Hd?`0 0 ${100-K}%`:"1 1 auto",position:"relative",overflow:"hidden"},children:[M.jsx("div",{style:{...nnt,background:Yt.overlayBg,border:Yt.overlayBorder,boxShadow:Yt.overlayShadow},children:Cm}),O.length===0&&!Mt?M.jsx(Pit,{onAddTrigger:zf}):null,M.jsxs(Mqe,{proOptions:{hideAttribution:!0},style:{width:"100%",height:"100%"},colorMode:i==="dark"?"dark":"light",nodes:O,edges:D,nodeTypes:LX,onMoveStart:()=>{Ot.current=!1},onNodeDragStart:()=>{Ot.current=!1},onNodesChange:oe=>Pr(oe),onEdgesChange:oe=>Sr(oe),onConnect:oe=>{var jt;if(t)return;const be=pL(yo(dn.current,Y_e({...oe,label:"always",data:{edgeType:"always"}},wn.current)),{currentFlowContract:l?Cn.current.get(l):void 0,flowContractsByCode:Cn.current,nodeContractsById:Wn.current});if(!be.isValid){V({status:"error",message:((jt=be.issues[0])==null?void 0:jt.message)??"Cannot connect nodes because the new order violates dependencies."});return}const Ke=`${oe.source}-${oe.target}-${wn.current.length+1}`;Y(Ke),F(""),Kc(TX(be.graph),{syncViewport:!0})},onNodeClick:(oe,be)=>{Wd(be.id)},onEdgeClick:(oe,be)=>{Y(be.id),F(""),j("basic-info")},onPaneClick:()=>{F(""),Y(""),j("basic-info")},nodesConnectable:!Mt,nodesDraggable:!Mt,elementsSelectable:!0,children:[M.jsx(Fit,{nodeIds:O.map(oe=>oe.id),syncToken:Yn,hostElement:Ot.current?vo.current:null}),M.jsx(Bit,{}),M.jsx(cQe,{}),M.jsx(Zqe,{}),M.jsx(zqe,{})]}),Ha.length>0?M.jsxs("aside",{"data-testid":"rule-flow-dependency-overlay",style:{...unt,background:Yt.overlayBg,border:Yt.overlayBorder,boxShadow:Yt.overlayShadow},children:[M.jsxs("button",{type:"button",style:{...hnt,cursor:"pointer",background:"transparent",border:"none",width:"100%",textAlign:"left",display:"flex",alignItems:"center",justifyContent:"space-between"},onClick:()=>Pi(oe=>!oe),"aria-expanded":ws,children:[M.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:4},children:[M.jsx("strong",{children:"Execution Order"}),M.jsx("span",{style:{fontSize:12,color:Yt.textMuted},children:"Prerequisites and downstream dependents."})]}),M.jsx("span",{style:{...Yit(ws),width:22,height:22,fontSize:12},children:"▾"})]}),ws?M.jsx("div",{style:fnt,children:Ha.map(oe=>M.jsxs("button",{type:"button","data-testid":`dependency-overlay-${oe.ruleCode}`,style:gnt(oe.nodeId===A,Yt),onClick:()=>Wd(oe.nodeId),children:[M.jsxs("span",{style:{fontWeight:700,color:Yt.textPrimary},children:["#",oe.order," ",oe.label]}),M.jsx("span",{style:{fontSize:11,color:Yt.textSecondary},children:oe.ruleCode}),M.jsxs("span",{style:{fontSize:11,color:Yt.textMuted},children:["Depends on: ",oe.dependsOn.length>0?oe.dependsOn.join(", "):"none"]}),M.jsxs("span",{style:{fontSize:11,color:Yt.textMuted},children:["Unlocks: ",oe.dependents.length>0?oe.dependents.join(", "):"none"]})]},oe.nodeId))}):null]}):null]}),Hd?M.jsxs(M.Fragment,{children:[M.jsx("div",{onPointerDown:Ss,style:{height:4,cursor:"ns-resize",background:Yt.sidebarBorder.replace("1px solid ",""),transition:"background 150ms",flexShrink:0},onPointerEnter:oe=>{oe.currentTarget.style.background="var(--mu-color-interactive)"},onPointerLeave:oe=>{oe.currentTarget.style.background=Yt.sidebarBorder.replace("1px solid ","")}}),M.jsxs("div",{style:{flex:`0 0 ${K}%`,overflow:"auto",background:Yt.sidebarBg},children:[M.jsx(Det,{value:Yc,onChange:Ug,onReset:()=>Ug(at()),tokens:Yt,editorRoot:m}),M.jsxs("div",{style:{display:"flex",gap:8,padding:"8px 12px",background:Yt.sidebarBg},children:[M.jsx("button",{type:"button",onClick:()=>{Ji()},disabled:zu||!r||!l,style:{padding:"6px 16px",borderRadius:6,border:"none",cursor:"pointer",background:"var(--mu-color-success)",color:"var(--mu-text-on-accent)",fontWeight:600,fontSize:12,opacity:zu?.6:1},children:zu?"Executing...":"Execute"}),M.jsx("button",{type:"button",onClick:Jn,style:{padding:"6px 16px",borderRadius:6,cursor:"pointer",background:"transparent",border:Yt.actionSecondaryBorder,color:Yt.textSecondary,fontWeight:500,fontSize:12},children:"Cancel"})]}),xm||zu||Om?M.jsx(Iet,{result:xm,loading:zu,error:Om,onClose:Jn,onSelectNode:oe=>{const be=dn.current.find(Ke=>Ke.data.ruleCode===oe||Ke.data.label===oe);be&&Wd(be.id)},tokens:Yt}):null]})]}):null]}),$t||Mr?M.jsxs("aside",{"data-testid":"rule-flow-right-panel",style:{...int,background:Yt.sidebarBg,border:Yt.sidebarBorder},children:[M.jsxs("div",{style:{padding:"12px 14px 8px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[M.jsx("strong",{style:{fontSize:13,color:Yt.textPrimary},children:"Inspector"}),M.jsx("button",{type:"button",style:{background:"transparent",border:"none",cursor:"pointer",color:Yt.textMuted,fontSize:14,padding:2},onClick:()=>{F(""),Y("")},title:"Close inspector",children:"✕"})]}),Py]}):null]}),Ct?M.jsx(zit,{warnings:Ct.warnings,onCancel:()=>Zt(null),onConfirm:()=>{(async()=>{var oe;try{V({status:"loading"}),await(c==null?void 0:c(Ct.graph)),Zt(null),V({status:"ready",title:"Published"}),Ye(0),xe(0,!1);const be=m instanceof ShadowRoot?m.host:null,Ke=(oe=be==null?void 0:be.getAttribute)==null?void 0:oe.call(be,"data-last-publish-status");(Ke==null?void 0:Ke.toLowerCase())==="pendingapproval"||(Ke==null?void 0:Ke.toLowerCase())==="draft"?Vt("Rule saved and submitted for approval."):Vt("Rule published and activated successfully.")}catch(be){Zt(null),V({status:"error",message:be.message||"Rule Studio publish failed."}),Bi(`Publish failed: ${be.message||"Unknown error"}`)}})()}}):null,uO?M.jsx(vQe,{open:!0,onClose:()=>pc(!1),versions:St,activeVersion:Di,initialLeftVersion:(Di==null?void 0:Di.version)??null,initialRightVersion:f??null,apiBaseUrl:r??"",workflowCode:l??"",tenantId:a,tokens:Yt}):null]});function Pr(oe){if(t)return;const be=Vbe(oe,dn.current);if(ni.current){L(be);return}const Ke=be.filter(kr=>kr.selected).map(kr=>kr.id);F(Ke[0]??A);const jt=oe.some(kr=>kr.type==="add"||kr.type==="remove"||kr.type==="replace"),Dt=oe.filter(kr=>kr.type==="position"),un=Dt.some(kr=>kr.dragging),Vn=Dt.length>0&&!un;if(!jt&&!Vn){L(be);return}Vn&&(Ot.current=!1),Kc(yo(be,wn.current))}function Sr(oe){if(t)return;const be=zbe(oe,wn.current);if(ni.current){R(k(be));return}const Ke=be.filter(Dt=>Dt.selected).map(Dt=>Dt.id);if(Y(Ke[0]??$),!oe.some(Dt=>Dt.type==="add"||Dt.type==="remove"||Dt.type==="replace")){R(k(be));return}Kc(yo(dn.current,be))}function qn(oe,be,Ke){t||(oe.dataTransfer.setData(OX,be),oe.dataTransfer.setData("text/plain",be),Ke&&oe.dataTransfer.setData(qCe,JSON.stringify(Ke)),oe.dataTransfer.effectAllowed="move")}function xr(oe){t||!oe.dataTransfer.types.includes(OX)||(oe.preventDefault(),oe.dataTransfer.dropEffect="move")}function ho(oe){if(t)return;const be=oe.dataTransfer.getData(OX),Ke=oe.dataTransfer.getData(qCe);if(!gX(be))return;oe.preventDefault();const jt=oe.currentTarget.getBoundingClientRect(),Dt={x:Math.max(32,oe.clientX-jt.left-84),y:Math.max(32,oe.clientY-jt.top-24)};if(Ke)try{const un=JSON.parse(Ke);if(un.code){wm(un,Dt);return}}catch{}Zc(be,Dt)}}async function ZCe(s,e,t){if(e.has(t))return e.get(t)??null;try{const i=await s.MGetFlowContract(t);return e.set(t,i),i}catch{return null}}async function XCe(s,e,t){try{return await s.MGetNodeAuthoringContract(e,t)}catch{return null}}async function $it(s,e,t){var r;const i=await XCe(s,e,t.id);if(i)return i;const n=t.ruleCode?gCe(t.type,t.ruleCode,t.data.contractRef):t.data.contractRef;if(!((r=n==null?void 0:n.sourceCode)!=null&&r.trim()))return null;try{const o=await s.MGetByReference(n);return{flowCode:e,nodeId:t.id,nodeType:t.type,ruleCode:t.ruleCode,order:t.data.order,dependsOn:t.data.dependsOn??[],requestScope:o.requestContract,responseDelta:o.responseContract}}catch{return null}}function Wit(s){const e=b_(s.data);return{id:s.id,type:pX(s.type),label:s.data.label,ruleCode:s.data.ruleCode,feelExpression:e.language==="feel"?e.body:void 0,position:{x:s.position.x,y:s.position.y},data:uX(s.data)}}function Hit(s){var e;return{id:s.id,source:s.source,target:s.target,label:typeof s.label=="string"?s.label:void 0,edgeType:a8((e=s.data)==null?void 0:e.edgeType)}}function TX(s){const e=Cl(s);if(e.nodes.length===0)return e;const t=new Map;for(const l of e.nodes)t.set(l.id,[]);for(const l of e.edges){const c=t.get(l.target)??[];c.push(l.source),t.set(l.target,c)}const i=new Map,n=new Set,r=l=>{const c=i.get(l);if(c!==void 0)return c;if(n.has(l))return 0;n.add(l);const d=t.get(l)??[],u=d.length===0?0:Math.max(...d.map(f=>r(f)))+1;return n.delete(l),i.set(l,u),u},o=new Map;for(const l of e.nodes){const c=l.type==="trigger"?0:r(l.id),d=o.get(c)??[];d.push(l),o.set(c,d)}const a=e.nodes.map(l=>({...l}));for(const[l,c]of o)c.sort((d,u)=>{const f=d.data.order??Number.MAX_SAFE_INTEGER,p=u.data.order??Number.MAX_SAFE_INTEGER;return f!==p?f-p:(d.label??"").localeCompare(u.label??"")}).forEach((d,u)=>{const f=a.find(p=>p.id===d.id);f&&(f.position={x:80+l*260,y:120+u*150})});return{...e,nodes:a}}function Vit(s){const e=s.nodes.filter(n=>n.type!=="trigger"&&n.type!=="end"&&(n.ruleCode??"").trim().length>0),t=new Map(e.map(n=>[n.ruleCode??n.id,n])),i=new Map;for(const n of e)for(const r of n.data.dependsOn??[]){const o=i.get(r)??[];o.push(n.ruleCode??n.id),i.set(r,o)}return e.map(n=>{const r=n.ruleCode??n.id,o=(i.get(r)??[]).filter(a=>t.has(a)).sort((a,l)=>a.localeCompare(l));return{nodeId:n.id,label:n.label,ruleCode:r,order:n.data.order??0,dependsOn:[...n.data.dependsOn??[]].sort((a,l)=>a.localeCompare(l)),dependents:o}}).sort((n,r)=>n.order!==r.order?n.order-r.order:(n.label??"").localeCompare(r.label??""))}function YCe(s,e){const t=e==="input"?s.inputColumns:s.outputColumns;return{contractName:`${s.id}_${e}`,title:e==="input"?"Decision Table Inputs":"Decision Table Outputs",description:s.description,rootType:"object",fields:t.map(i=>({path:i.name,label:i.label,dataType:i.dataType,required:e==="input",runtimeWritten:e==="output",description:`${e==="input"?"Input":"Output"} column from decision table '${s.name}'.`}))}}function zit({warnings:s,onCancel:e,onConfirm:t}){return M.jsx("div",{style:pnt,children:M.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"rule-flow-publish-confirm-title",style:mnt,children:[M.jsxs("div",{style:JCe,children:[M.jsx("strong",{id:"rule-flow-publish-confirm-title",children:"Confirm Publish"}),M.jsx("span",{children:s.length>0?"This flow can publish, but warnings still exist. Review them before continuing.":"This will hand the current validated graph to the host publish handler."})]}),s.length>0?M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:s.map((i,n)=>M.jsxs("div",{style:tit,children:[M.jsx("strong",{children:i.code})," ",i.message]},`${i.code}-${i.message}-${n}`))}):null,M.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--mu-space-sm)"},children:[M.jsx("button",{type:"button",style:ch(!1),onClick:e,children:"Cancel"}),M.jsx("button",{type:"button",style:ch(!0),onClick:t,children:s.length>0?"Publish With Warnings":"Confirm Publish"})]})]})})}function Uit(s,e){const t=uCe(s),i=new Blob([t],{type:"application/json"}),n=URL.createObjectURL(i),r=document.createElement("a");r.style.display="none",r.href=n,r.download=`${e??"rule-flow"}.json`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>URL.revokeObjectURL(n),100)}function jit({selectedEdge:s,readOnly:e,onUpdateEdgeType:t,onDeleteEdge:i}){var r;if(!s)return M.jsx("div",{style:{color:"var(--mu-text-muted)",fontSize:13,lineHeight:1.5},children:"Select a node or edge to edit it. Use edge routing to decide whether downstream nodes run `always`, `on pass`, `on fail`, or `on error`."});const n=a8((r=s.data)==null?void 0:r.edgeType);return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14,minHeight:0},children:[M.jsxs("div",{style:JCe,children:[M.jsx("strong",{children:"Edge Routing"}),M.jsxs("span",{children:[s.source," → ",s.target]})]}),M.jsxs("label",{style:ant,children:["Edge Type",M.jsx("select",{style:lnt,value:n,disabled:e,onChange:o=>t(a8(o.target.value)),children:["always","on-true","on-false","on-error"].map(o=>M.jsx("option",{value:o,children:EX[o]},o))})]}),M.jsxs("div",{style:cnt,children:[M.jsx("strong",{children:EX[n]}),M.jsx("span",{children:Iit[n]})]}),e?null:M.jsx("button",{type:"button",style:dnt,onClick:i,children:"Delete Edge"})]})}const qit={display:"grid",gap:"var(--mu-space-sm)",minHeight:0,height:"100%",width:"100%",minWidth:0,overflow:"auto"},Qit={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},Git={display:"flex",flex:"1 1 auto",minHeight:0},Kit={position:"relative",minWidth:0,borderRadius:24,overflow:"hidden",border:"1px solid var(--mu-border-subtle)"},JCe={display:"flex",flexDirection:"column",gap:4,fontSize:13,color:"var(--mu-text-muted)"},Zit={display:"flex",flexDirection:"column",gap:6,padding:20,borderRadius:18,border:"1px solid var(--mu-color-warning-border)",background:"var(--mu-color-warning-bg)",color:"var(--mu-color-warning-text)"},Xit=s=>({display:"flex",flexDirection:"column",gap:4,padding:"10px 12px",borderRadius:14,border:s?"1px solid var(--mu-color-error-border)":"1px solid var(--mu-color-warning-border)",background:s?"var(--mu-color-error-bg)":"var(--mu-color-warning-bg)",color:s?"var(--mu-color-error-text)":"var(--mu-color-warning-text)",fontSize:12}),eSe={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",minHeight:0,height:"100%",overflow:"auto",paddingRight:4};function Yit(s){return{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:999,background:"var(--mu-border-subtle)",color:"var(--mu-text-secondary)",fontSize:14,transform:s?"rotate(180deg)":"rotate(0deg)",transition:"transform 160ms ease"}}function Jit(s,e){const t=(e==null?void 0:e.paletteBtnBorderAlpha)??"22",i=(e==null?void 0:e.paletteBtnBgAlpha)??"10";return{display:"flex",flexDirection:"column",gap:4,borderRadius:14,border:`1px solid ${oM[s]}${t}`,background:`${oM[s]}${i}`,color:(e==null?void 0:e.textPrimary)??"var(--mu-text-primary)",padding:"11px 12px",textAlign:"left",fontWeight:600,cursor:"grab"}}function ent(s,e,t=280,i=!1){if(s)return{gridTemplateColumns:"minmax(0, 1fr)",alignContent:"start"};const n=i?"48px":`${t}px`;return{gridTemplateColumns:e?`${n} minmax(0, 1fr) minmax(320px, 420px)`:`${n} minmax(0, 1fr)`,alignContent:"stretch"}}const tnt={display:"flex",flexDirection:"column",gap:0,borderRadius:18,minHeight:0,overflow:"auto"},int={display:"flex",flexDirection:"column",gap:0,borderRadius:18,minHeight:0,overflow:"auto"};function DX(s){return{background:"transparent",border:"none",cursor:"pointer",fontSize:11,color:s.textMuted,padding:"2px 4px",borderRadius:4,whiteSpace:"nowrap"}}const IX={display:"block",width:"100%",textAlign:"left",padding:"8px 14px",background:"transparent",border:"none",cursor:"pointer",fontSize:13,borderRadius:0},nnt={position:"absolute",top:12,left:12,zIndex:3,borderRadius:14,padding:"8px 12px",maxWidth:"calc(100% - 24px)"};function snt(s){return{minHeight:s?420:640,order:s?-1:0}}function rnt(s){return{}}function ont(s){return{}}const ant={display:"flex",flexDirection:"column",gap:6,fontSize:12,color:"var(--mu-text-secondary)",fontWeight:600},lnt={width:"100%",borderRadius:12,border:"1px solid var(--mu-border-input)",background:"var(--mu-surface-input)",color:"var(--mu-text-primary)",minHeight:42,padding:"10px 12px",fontSize:14},cnt={display:"flex",flexDirection:"column",gap:6,padding:"12px 14px",borderRadius:14,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-raised)",color:"var(--mu-text-label)",fontSize:12,lineHeight:1.5},dnt={borderRadius:14,border:"1px solid var(--mu-color-error-border)",background:"var(--mu-color-error-bg)",color:"var(--mu-color-error-text)",padding:"11px 14px",fontWeight:700},unt={position:"absolute",top:16,right:16,zIndex:2,display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",width:"min(320px, calc(100% - 32px))",maxHeight:"calc(100% - 32px)",padding:14,borderRadius:18,overflow:"auto"},hnt={display:"flex",flexDirection:"column",gap:4,fontSize:12,color:"var(--mu-text-muted)"},fnt={display:"flex",flexDirection:"column",gap:8};function gnt(s,e){return{display:"flex",flexDirection:"column",gap:4,width:"100%",textAlign:"left",padding:"10px 12px",borderRadius:14,border:s?(e==null?void 0:e.overlayItemSelectedBorder)??"1px solid var(--mu-color-interactive-border)":(e==null?void 0:e.overlayItemBorder)??"1px solid var(--mu-border-subtle)",background:s?(e==null?void 0:e.overlayItemSelectedBg)??"var(--mu-color-selected-bg)":(e==null?void 0:e.overlayItemBg)??"var(--mu-surface-raised)",color:(e==null?void 0:e.textPrimary)??"var(--mu-text-primary)",cursor:"pointer"}}const pnt={position:"fixed",inset:0,zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--mu-surface-backdrop)"},mnt={display:"flex",flexDirection:"column",gap:16,width:"min(560px, 100%)",padding:20,borderRadius:22,border:"1px solid var(--mu-border-default)",background:"var(--mu-surface-dialog)",boxShadow:"var(--mu-shadow-dialog)"},_nt={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 16px",borderRadius:"18px 18px 0 0",minHeight:42},vv={display:"inline-flex",alignItems:"center",padding:"2px 10px",borderRadius:8,fontSize:12,fontWeight:600,letterSpacing:"0.02em"},bnt={position:"absolute",top:"calc(100% + 4px)",right:0,zIndex:10,display:"flex",flexDirection:"column",gap:6,padding:"10px 14px",borderRadius:12,minWidth:200,maxWidth:360},tSe={nodes:[dM("trigger",{x:80,y:180},{label:"Start"}),dM("end",{x:760,y:180},{label:"End"})],edges:[{id:"edge-trigger-end",source:"trigger-1",target:"end-1",edgeType:"always"}],metadata:{version:1}};class iSe{static fromRuleSet(e){const t=y_(e),i=t.flowGraph;if(Cnt(i)){const d=RX({...i,metadata:{...i.metadata,workflowName:oS(t.workflowName)??i.metadata.workflowName}}),u=i.nodes??[];return d.nodes=d.nodes.map((f,p)=>{const m=y_(u[p]),b=m.expressionLanguage,w=y_(m.data),S=w.connectorConfig,k=typeof w.connectorType=="string"?w.connectorType:void 0;let O;if(S&&typeof S=="object"){const L=S;L.connectorConfig&&typeof L.connectorConfig=="object"?O={connectorType:typeof L.connectorType=="string"?L.connectorType:k,connectorConfig:L.connectorConfig,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}:"url"in L||"method"in L||"body"in L||"operation"in L||"webhookUrl"in L||"to"in L||"key"in L?O={connectorType:typeof L.connectorType=="string"?L.connectorType:k,connectorConfig:L,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}:O={connectorType:typeof L.connectorType=="string"?L.connectorType:k,connectorConfig:void 0,credentialId:typeof L.credentialId=="string"?L.credentialId:void 0}}return{...f,expressionLanguage:b==="feel"||b==="javascript"?b:void 0,data:{...f.data,connectorConfig:O}}}),d}const n=oS(t.workflowName)??oS(t.WorkflowName)??"wf.new",r=ynt(t);if(r.length===0)return{...tSe,metadata:{...tSe.metadata,workflowName:n}};const o=[dM("trigger",{x:80,y:180},{label:"Start"})],a=[];let l="trigger-1";for(let d=0;d<r.length;d+=1){const u=r[d],f=dM("condition",{x:220+d*220,y:180},{label:u,ruleCode:u,nodeId:u});o.push(f),a.push({id:`edge-${l}-${f.id}`,source:l,target:f.id,edgeType:"always"}),l=f.id}const c=dM("end",{x:220+r.length*220,y:180},{label:"End"});return o.push(c),a.push({id:`edge-${l}-${c.id}`,source:l,target:c.id,edgeType:"always"}),{nodes:o,edges:a,metadata:{version:1,workflowName:n}}}static toRuleSet(e,t){const i=y_(t),n=RX(e),r=vnt(n),o=e.metadata.workflowName??e.metadata.ruleSetCode??oS(i.workflowName)??oS(i.WorkflowName)??"wf.new",a={...n,nodes:n.nodes.map(l=>{var d;const c={...l};return l.expressionLanguage&&(c.expressionLanguage=l.expressionLanguage),(d=l.data)!=null&&d.connectorConfig&&(c.data={...c.data,connectorConfig:l.data.connectorConfig}),c})};return{...i,workflowName:o,rules:r,flowGraph:a}}static serialize(e){return JSON.stringify(RX(e),null,2)}}function vnt(s){var o,a,l;const e=new Map(s.nodes.map(c=>[c.id,c])),t=new Map;for(const c of s.edges){const d=t.get(c.source)??[];d.push(c),t.set(c.source,d)}const i=new Set,n=[];let r=((o=s.nodes.find(c=>c.type==="trigger"))==null?void 0:o.id)??((a=s.nodes[0])==null?void 0:a.id);for(;r&&!i.has(r);){i.add(r);const c=e.get(r);if(c&&c.type!=="trigger"&&c.type!=="end"){const u=((l=c.ruleCode)==null?void 0:l.trim())||c.label.trim();u.length>0&&!n.includes(u)&&n.push(u)}const d=(t.get(r)??[]).slice().sort((u,f)=>(u.target??"").localeCompare(f.target??""))[0];r=d==null?void 0:d.target}return n.length>0?n:s.nodes.filter(c=>c.type!=="trigger"&&c.type!=="end").map(c=>{var d;return((d=c.ruleCode)==null?void 0:d.trim())||c.label.trim()}).filter(c=>c.length>0)}function ynt(s){return(Array.isArray(s.rules)?s.rules:Array.isArray(s.Rules)?s.Rules:[]).map(t=>typeof t=="string"?t:y_(t).RuleName&&typeof y_(t).RuleName=="string"?y_(t).RuleName:oS(y_(t).ruleCode)??oS(y_(t).code)??"").map(t=>t.trim()).filter(t=>t.length>0)}function RX(s){var e,t,i;return{nodes:s.nodes.map((n,r)=>{var o,a,l,c,d;return{...n,id:n.id||`${n.type}-${r+1}`,label:n.label.trim()||`${wnt(n.type)} ${r+1}`,expressionLanguage:n.expressionLanguage==="feel"||n.expressionLanguage==="javascript"?n.expressionLanguage:void 0,position:{x:Number.isFinite((o=n.position)==null?void 0:o.x)?n.position.x:r*220,y:Number.isFinite((a=n.position)==null?void 0:a.y)?n.position.y:180},data:{...n.data??{},outputFields:n.type==="condition"?(()=>{var m,b,w;const u=(((b=(m=n.data)==null?void 0:m.contractOverride)==null?void 0:b.responseFields)??[]).filter(S=>!S.isResultPayload&&typeof S.valueExpression=="string"&&S.valueExpression.trim().length>0).map(S=>({path:S.path,valueExpression:S.valueExpression,dataType:S.dataType,runtimeWritten:!0})),f=(Array.isArray((w=n.data)==null?void 0:w.outputFields)?n.data.outputFields:[]).filter(S=>typeof(S==null?void 0:S.path)=="string"&&S.path.trim().length>0&&(!S.valueExpression||!S.valueExpression.trim())).map(S=>({path:S.path,valueExpression:S.valueExpression??"",dataType:S.dataType??"string",runtimeWritten:!0})),p=new Set(u.map(S=>S.path));return[...u,...f.filter(S=>!p.has(S.path))]})():(l=n.data)==null?void 0:l.outputFields,connectorConfig:(c=n.data)==null?void 0:c.connectorConfig,contractRef:n.type!=="trigger"&&n.type!=="end"&&n.ruleCode?{sourceType:n.type==="decision-table"?"decision-table":n.type==="sub-flow"?"flow":n.type==="connector"?"api":"rule",sourceCode:n.ruleCode}:((d=n.data)==null?void 0:d.contractRef)??void 0}}}),edges:s.edges.map((n,r)=>({...n,id:n.id||`edge-${r+1}`,edgeType:n.edgeType??"always"})),metadata:{version:((e=s.metadata)==null?void 0:e.version)??1,workflowName:((t=s.metadata)==null?void 0:t.workflowName)??((i=s.metadata)==null?void 0:i.ruleSetCode)}}}function dM(s,e,t){var n;const i=s==="trigger"||s==="end"?"1":`${Math.abs(e.x)}`;return{id:((n=t.nodeId)==null?void 0:n.trim())||`${s}-${i}`,type:s,label:t.label,ruleCode:t.ruleCode,position:e,data:t.ruleCode?{contractRef:{sourceType:"rule",sourceCode:t.ruleCode}}:{}}}function wnt(s){return s.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function oS(s){return typeof s=="string"&&s.trim().length>0?s.trim():void 0}function y_(s){return s!==null&&typeof s=="object"?s:{}}function Cnt(s){const e=y_(s);return Array.isArray(e.nodes)&&Array.isArray(e.edges)&&e.metadata!==void 0}var Snt=Object.defineProperty,xnt=Object.getOwnPropertyDescriptor,fg=(s,e,t,i)=>{for(var n=i>1?void 0:i?xnt(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(n=(i?o(e,t,n):o(n))||n);return i&&n&&Snt(e,t,n),n};const nSe="rule-flow-designer";let dh=class extends to{constructor(){super(...arguments),this.graph=KN(),this.graphJson="",this.readOnly=!1,this.theme="light",this.apiBaseUrl="",this.catalogApiBase="",this.height=640,this.workflowCode="",this.tenantId="",this.showHeader=!0,this.version=null,this.mInternalGraphUpdate=!1,this.mLastGraphSignature=Sl(this.graph),this.mWorkflowLoadVersion=0,this.mLoadedRuleSet=null}connectedCallback(){super.connectedCallback(),this.MUpgradeProperty("graph"),this.MUpgradeProperty("graphJson"),this.MUpgradeProperty("readOnly"),this.MUpgradeProperty("theme"),this.MUpgradeProperty("apiBaseUrl"),this.MUpgradeProperty("catalogApiBase"),this.MUpgradeProperty("height"),this.MUpgradeProperty("workflowCode"),this.MUpgradeProperty("tenantId"),this.MUpgradeProperty("showHeader"),this.MUpgradeProperty("version"),this.MSyncGraphFromJson()}firstUpdated(){queueMicrotask(()=>{this.MRenderEditor(),this.graphJson.trim()||this.MLoadWorkflowGraphAsync()})}updated(s){if(s.has("graphJson")&&!this.mInternalGraphUpdate&&this.MSyncGraphFromJsonIfNeeded()){this.MRenderEditor();return}if(s.has("version")){this.mInternalGraphUpdate=!0,this.graphJson.trim()&&(this.graphJson=""),this.graph=KN(),this.mLastGraphSignature=Sl(this.graph),this.MLoadWorkflowGraphAsync();return}!this.mInternalGraphUpdate&&(s.has("graph")||s.has("graphJson")||s.has("readOnly")||s.has("theme")||s.has("apiBaseUrl")||s.has("catalogApiBase")||s.has("height")||s.has("tenantId")||s.has("showHeader"))&&this.MRenderEditor(),(s.has("workflowCode")||s.has("apiBaseUrl")||s.has("tenantId"))&&!this.graphJson.trim()&&this.MLoadWorkflowGraphAsync(),this.mInternalGraphUpdate&&(s.has("graphJson")||s.has("graph"))&&(this.mInternalGraphUpdate=!1,this.MRenderEditor())}disconnectedCallback(){var s;(s=this.mRoot)==null||s.unmount(),this.mRoot=void 0,super.disconnectedCallback()}render(){const s=e_(nSe);return s||kt`<section id="editor-host" class="block h-full min-h-[640px] w-full"></section>`}MUpgradeProperty(s){if(!Object.prototype.hasOwnProperty.call(this,s))return;const e=Reflect.get(this,s);Reflect.deleteProperty(this,s),Reflect.set(this,s,e)}MSyncGraphFromJson(){if(!this.graphJson.trim()){this.graph=Cl(this.graph),this.mLastGraphSignature=Sl(this.graph);return}try{this.graph=Cl(JSON.parse(this.graphJson)),this.mLastGraphSignature=Sl(this.graph)}catch{this.graph=KN(),this.mLastGraphSignature=Sl(this.graph)}}MSyncGraphFromJsonIfNeeded(){if(!this.graphJson.trim())return!1;try{const s=Cl(JSON.parse(this.graphJson)),e=Sl(s);return e===this.mLastGraphSignature?!1:(this.graph=s,this.mLastGraphSignature=e,!0)}catch{return!1}}MRenderEditor(){var t,i;if(e_(nSe)){(t=this.mRoot)==null||t.unmount(),this.mRoot=void 0;return}const e=(i=this.renderRoot)==null?void 0:i.querySelector("#editor-host");e&&(this.mRoot??(this.mRoot=t9e.createRoot(e)),this.mRoot.render(ve.createElement(KCe,{graph:this.graph,readOnly:this.readOnly,theme:this.theme,apiBaseUrl:this.apiBaseUrl||void 0,catalogApiBase:this.catalogApiBase||void 0,tenantId:this.tenantId||void 0,workflowCode:this.workflowCode||void 0,height:this.height,showHeader:this.showHeader,version:this.version,editorRoot:this.renderRoot,onVersionChange:n=>{this.version=n,this.dispatchEvent(new CustomEvent("version-change",{detail:{version:n},bubbles:!0,composed:!0}))},onGraphChange:n=>{const r=Sl(n);r!==this.mLastGraphSignature&&(this.mInternalGraphUpdate=!0,this.graph=n,this.mLastGraphSignature=r,this.graphJson=JSON.stringify(n),this.dispatchEvent(new CustomEvent("graph-change",{detail:n,bubbles:!0,composed:!0})))},onPublish:async n=>{await this.MPublishGraphAsync(n)}})))}async MPublishGraphAsync(s){const e=iSe.toRuleSet(s,this.mLoadedRuleSet??void 0);this.mLoadedRuleSet=e;const t={graph:s,ruleSet:e};if(this.dispatchEvent(new CustomEvent("publish-start",{detail:t,bubbles:!0,composed:!0})),!this.apiBaseUrl.trim()||!this.workflowCode.trim()){this.dispatchEvent(new CustomEvent("publish",{detail:t,bubbles:!0,composed:!0}));return}try{const i=await this.MPersistRuleSetAsync(t);this.setAttribute("data-last-publish-status",i.status??"Active"),this.setAttribute("data-last-publish-approval",String(i.approvalWorkflowEnabled)),this.dispatchEvent(new CustomEvent("publish-complete",{detail:i,bubbles:!0,composed:!0}))}catch(i){const n=i instanceof Error?i.message:"Rule Studio publish failed.";throw this.dispatchEvent(new CustomEvent("publish-error",{detail:{message:n,graph:s,ruleSet:e},bubbles:!0,composed:!0})),i}}async MPersistRuleSetAsync(s){const e=this.workflowCode.trim(),t=this.apiBaseUrl.replace(/\/$/,""),i="ui-studio",n=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}`,{method:"POST",body:JSON.stringify({ruleSet:s.ruleSet,activateAfterSave:!1,actor:i})}),r=Number(n.savedVersion??0);if(!Number.isFinite(r)||r<=0)throw new Error("Rule Studio publish did not return a saved version.");const o=!!n.approvalWorkflowEnabled;let a=!!n.activated,l=typeof n.activeVersion=="number"?n.activeVersion:null,c=typeof n.status=="string"?n.status:void 0,d=`Saved version ${r}.`;if(o){const u=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}/${r}/submit`,{method:"POST",body:JSON.stringify({actor:i})});c=typeof u.status=="string"?u.status:c,d=`Saved version ${r} and submitted for approval.`}else if(!a||l!==r){const u=await this.MRequestJson(`${t}/rulesets/${encodeURIComponent(e)}/${r}/activate`,{method:"POST",body:JSON.stringify({actor:i})});a=!0,l=typeof u.activeVersion=="number"?u.activeVersion:r,c="Active",d=`Saved version ${r} and activated it.`}else d=`Saved version ${r} and activated it.`;return{...s,savedVersion:r,activeVersion:l,approvalWorkflowEnabled:o,activated:a,status:c,message:d}}async MRequestJson(s,e){const t=hd(e.headers,{tenantId:this.tenantId});!t.has("Content-Type")&&e.body&&t.set("Content-Type","application/json"),t.has("Accept")||t.set("Accept","application/json");const i=await fetch(s,{...e,headers:t});if(!i.ok){const n=await i.text();throw new Error(n||`Rule Studio request failed: ${i.status} ${i.statusText}`)}return await i.json()}async MLoadWorkflowGraphAsync(){const s=this.workflowCode.trim(),e=this.apiBaseUrl.trim();if(!s||!e||this.graphJson.trim())return;const t=++this.mWorkflowLoadVersion,i=this.version!=null?`?version=${this.version}`:"",n=`${e.replace(/\/$/,"")}/rulesets/${encodeURIComponent(s)}/export${i}`;try{const r=await fetch(n,{headers:hd(void 0,{tenantId:this.tenantId})});if(!r.ok)return;const o=await r.json();if(t!=this.mWorkflowLoadVersion||!o.ruleSetJson)return;const a=JSON.parse(o.ruleSetJson);this.mLoadedRuleSet=a;const l=Cl(iSe.fromRuleSet(a));this.mInternalGraphUpdate=!0,this.graph=l,this.mLastGraphSignature=Sl(l),this.graphJson=JSON.stringify(l)}catch{}}};dh.styles=[Ho(La),Ho(i9e)],fg([Jt({attribute:!1})],dh.prototype,"graph",2),fg([Jt({type:String,attribute:"graph-json"})],dh.prototype,"graphJson",2),fg([Jt({type:Boolean,attribute:"read-only"})],dh.prototype,"readOnly",2),fg([Jt({type:String})],dh.prototype,"theme",2),fg([Jt({type:String,attribute:"api-base-url"})],dh.prototype,"apiBaseUrl",2),fg([Jt({type:String,attribute:"catalog-api-base"})],dh.prototype,"catalogApiBase",2),fg([Jt({type:Number})],dh.prototype,"height",2),fg([Jt({type:String,attribute:"workflow-code"})],dh.prototype,"workflowCode",2),fg([Jt({type:String,attribute:"tenant-id"})],dh.prototype,"tenantId",2),fg([Jt({type:Boolean,attribute:"show-header"})],dh.prototype,"showHeader",2),fg([Jt({type:Number})],dh.prototype,"version",2),dh=fg([Vo("mu-rule-flow-designer")],dh);var knt=Object.defineProperty,Ont=Object.getOwnPropertyDescriptor,g8=(s,e,t,i)=>{for(var n=i>1?void 0:i?Ont(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(n=(i?o(e,t,n):o(n))||n);return i&&n&&knt(e,t,n),n};const Ent="rule-test-runner";let mL=class extends to{constructor(){super(...arguments),this.testEndpoint="",this.mPayload='{"facts": []}',this.mResult=""}async MRun(){this.dispatchEvent(new CustomEvent("run",{detail:{payload:this.mPayload},bubbles:!0,composed:!0})),this.mResult="Rule test request dispatched."}render(){const s=e_(Ent);return s||kt`
735
735
  <section class="space-y-2 rounded-lg border border-[var(--color-mu-border)] bg-white p-4">
736
736
  <h3 class="text-base font-semibold">Rule Test Runner</h3>
737
737
  <textarea class="min-h-24 w-full rounded border border-[var(--color-mu-border)] p-2 text-xs" .value=${this.mPayload} @input=${e=>this.mPayload=e.target.value}></textarea>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muonroi/ui-engine-rule-components",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Muonroi rule engine web components",
5
5
  "type": "module",
6
6
  "main": "dist/muonroi-rule-components.esm.js",
@@ -50,7 +50,7 @@
50
50
  "typescript": "^5.7.0",
51
51
  "vite": "^6.0.0",
52
52
  "vitest": "^2.1.8",
53
- "@muonroi/ui-engine-core": "0.1.4"
53
+ "@muonroi/ui-engine-core": "^0.1.9"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "npm run -w @muonroi/ui-engine-core build && vite build && vite build -c vite.trace.config.ts && vite build -c vite.flow.config.ts && tsc -p tsconfig.json --emitDeclarationOnly",