@object-ui/plugin-workflow 3.1.3 → 3.1.5
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.
- package/dist/index.js +2482 -1870
- package/dist/index.umd.cjs +3 -3
- package/package.json +9 -9
package/dist/index.umd.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@object-ui/core`),require(`react`),require(`@object-ui/components`),require(`lucide-react`),require(`clsx`),require(`tailwind-merge`)):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`lucide-react`,`clsx`,`tailwind-merge`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginWorkflow={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.lucide_react,e.clsx,e.tailwind_merge))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),m=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=u(t),a=0,o=i.length,s;a<o;a++)s=i[a],!f.call(e,s)&&s!==n&&c(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=l(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:s(d(e)),m(t||!e||!e.__esModule?c(n,`default`,{value:e,enumerable:!0}):n,e)))(n);var h=p((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),g=p((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,A,k,G,k),ue[k+A]=!0)}if(k=null,C!==void 0&&(l(C),k=""+C),m(g)&&(l(g.key),k=""+g.key),"key"in g){C={};for(var ne in g)ne!=="key"&&(C[ne]=g[ne])}else C=g;return k&&f(C,typeof s=="function"?s.displayName||s.name||"Unknown":s),O(s,k,C,d(),W,K)}function S(s){w(s)?s._store&&(s._store.validated=1):typeof s=="object"&&s!==null&&s.$$typeof===y&&(s._payload.status==="fulfilled"?w(s._payload.value)&&s._payload.value._store&&(s._payload.value._store.validated=1):s._store&&(s._store.validated=1))}function w(s){return typeof s=="object"&&s!==null&&s.$$typeof===R}var N=h,R=Symbol.for("react.transitional.element"),$=Symbol.for("react.portal"),c=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),_=Symbol.for("react.profiler"),T=Symbol.for("react.consumer"),r=Symbol.for("react.context"),b=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),ee=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),E=Symbol.for("react.activity"),M=Symbol.for("react.client.reference"),U=N.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F=Object.prototype.hasOwnProperty,X=Array.isArray,H=console.createTask?console.createTask:function(){return null};N={react_stack_bottom_frame:function(s){return s()}};var Z,z={},J=N.react_stack_bottom_frame.bind(N,t)(),ae=H(x(t)),ue={};te.Fragment=c,te.jsx=function(s,g,C){var A=1e4>U.recentlyCreatedOwnerStacks++;return j(s,g,C,!1,A?Error("react-stack-top-frame"):J,A?H(x(s)):ae)},te.jsxs=function(s,g,C){var A=1e4>U.recentlyCreatedOwnerStacks++;return j(s,g,C,!0,A?Error("react-stack-top-frame"):J,A?H(x(s)):ae)}})()),te}var we;function Me(){return we||(we=1,process.env.NODE_ENV==="production"?de.exports=Ve():de.exports=Fe()),de.exports}var e=Me();const ge={start:e.jsx(o.Play,{className:"h-4 w-4 text-green-500"}),end:e.jsx(o.CheckCircle,{className:"h-4 w-4 text-red-500"}),task:e.jsx(o.Circle,{className:"h-4 w-4 text-blue-500"}),approval:e.jsx(o.Users,{className:"h-4 w-4 text-purple-500"}),condition:e.jsx(o.GitBranch,{className:"h-4 w-4 text-orange-500"}),parallel:e.jsx(o.ArrowRight,{className:"h-4 w-4 text-teal-500"}),delay:e.jsx(o.Clock,{className:"h-4 w-4 text-gray-500"}),notification:e.jsx(o.Bell,{className:"h-4 w-4 text-yellow-500"}),script:e.jsx(o.Code,{className:"h-4 w-4 text-indigo-500"})},Ye={start:"border-green-300 bg-green-50",end:"border-red-300 bg-red-50",task:"border-blue-300 bg-blue-50",approval:"border-purple-300 bg-purple-50",condition:"border-orange-300 bg-orange-50",parallel:"border-teal-300 bg-teal-50",delay:"border-gray-300 bg-gray-50",notification:"border-yellow-300 bg-yellow-50",script:"border-indigo-300 bg-indigo-50"},Ue={draft:{variant:"secondary",label:"Draft"},active:{variant:"default",label:"Active"},paused:{variant:"outline",label:"Paused"},completed:{variant:"default",label:"Completed"},cancelled:{variant:"destructive",label:"Cancelled"}},Ce=({schema:n})=>{const{workflow:u,readOnly:l=!1,showToolbar:x=!0}=n,[d,t]=h.useState(u||{type:"workflow",title:"New Workflow",status:"draft",nodes:[{id:"start-1",type:"start",label:"Start",position:{x:100,y:100}},{id:"end-1",type:"end",label:"End",position:{x:100,y:400}}],edges:[],variables:[]}),[m,f]=h.useState(null),[D,O]=h.useState(null),j=h.useMemo(()=>d.nodes.find(r=>r.id===m),[d.nodes,m]),S=h.useCallback(r=>{if(l)return;const b=`${r}-${Date.now()}`,P={id:b,type:r,label:`New ${r.charAt(0).toUpperCase()+r.slice(1)}`,position:{x:200,y:(d.nodes.length+1)*80}};t(B=>({...B,nodes:[...B.nodes,P]})),f(b)},[l,d.nodes.length]),w=h.useCallback((r,b)=>{l||t(P=>({...P,nodes:P.nodes.map(B=>B.id===r?{...B,...b}:B)}))},[l]),N=h.useCallback(r=>{l||(t(b=>({...b,nodes:b.nodes.filter(P=>P.id!==r),edges:b.edges.filter(P=>P.source!==r&&P.target!==r)})),m===r&&f(null))},[l,m]),R=h.useCallback((r,b)=>{if(l)return;const B={id:`edge-${Date.now()}`,source:r,target:b};t(ee=>({...ee,edges:[...ee.edges,B]}))},[l]),$=h.useCallback(r=>{l||(t(b=>({...b,edges:b.edges.filter(P=>P.id!==r)})),D===r&&O(null))},[l,D]),c=()=>{console.log("Saving workflow:",d),n.onSave},v=()=>{t(r=>({...r,status:"active"})),console.log("Publishing workflow"),n.onPublish},_=Ue[d.status||"draft"],T=["task","approval","condition","parallel","delay","notification","script"];return e.jsxs("div",{className:"space-y-4",children:[x&&e.jsxs("div",{className:"flex items-center justify-between gap-2 p-4 bg-card rounded-lg border",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{children:e.jsx(a.Input,{value:d.title||"",onChange:r=>t(b=>({...b,title:r.target.value})),className:"text-lg font-semibold border-none p-0 h-auto focus-visible:ring-0",readOnly:l,placeholder:"Workflow Title"})}),e.jsx(a.Badge,{variant:_.variant,children:_.label})]}),!l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:c,children:[e.jsx(o.Save,{className:"h-4 w-4 mr-2"}),"Save"]}),e.jsxs(a.Button,{size:"sm",onClick:v,disabled:d.status==="active",children:[e.jsx(o.Play,{className:"h-4 w-4 mr-2"}),"Publish"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-4",children:[!l&&e.jsxs(a.Card,{className:"lg:col-span-1",children:[e.jsx(a.CardHeader,{children:e.jsx(a.CardTitle,{className:"text-sm",children:"Add Node"})}),e.jsx(a.CardContent,{className:"space-y-2",children:T.map(r=>e.jsxs("button",{onClick:()=>S(r),className:"w-full flex items-center gap-2 p-2 rounded-md border hover:bg-muted/50 transition-colors text-sm",children:[ge[r],e.jsx("span",{className:"capitalize",children:r})]},r))})]}),e.jsxs(a.Card,{className:l?"lg:col-span-3":"lg:col-span-2",children:[e.jsx(a.CardHeader,{children:e.jsxs(a.CardTitle,{className:"text-sm flex items-center gap-2",children:[e.jsx(o.GitBranch,{className:"h-4 w-4"}),"Workflow Flow"]})}),e.jsx(a.CardContent,{children:e.jsxs("div",{className:"space-y-2",children:[d.nodes.map(r=>e.jsxs("div",{onClick:()=>{f(r.id),O(null)},className:`flex items-center justify-between p-3 rounded-lg border-2 cursor-pointer transition-all ${Ye[r.type]} ${m===r.id?"ring-2 ring-primary shadow-md":"hover:shadow-sm"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[ge[r.type],e.jsx("span",{className:"font-medium text-sm",children:r.label}),e.jsxs("span",{className:"text-xs text-muted-foreground capitalize",children:["(",r.type,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[d.edges.filter(b=>b.source===r.id).length>0&&e.jsxs(a.Badge,{variant:"outline",className:"text-xs",children:[d.edges.filter(b=>b.source===r.id).length," out"]}),!l&&r.type!=="start"&&r.type!=="end"&&e.jsx(a.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-red-500 hover:text-red-700",onClick:b=>{b.stopPropagation(),N(r.id)},children:e.jsx(o.Trash2,{className:"h-3 w-3"})})]})]},r.id)),d.edges.length>0&&e.jsxs("div",{className:"mt-4 pt-4 border-t",children:[e.jsx(a.Label,{className:"text-xs text-muted-foreground mb-2 block",children:"Connections"}),d.edges.map(r=>{const b=d.nodes.find(B=>B.id===r.source),P=d.nodes.find(B=>B.id===r.target);return e.jsxs("div",{className:"flex items-center gap-2 p-2 text-sm",children:[e.jsx("span",{children:b?.label||r.source}),e.jsx(o.ArrowRight,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{children:P?.label||r.target}),r.label&&e.jsx(a.Badge,{variant:"outline",className:"text-xs",children:r.label}),!l&&e.jsx(a.Button,{size:"sm",variant:"ghost",className:"h-5 w-5 p-0 ml-auto text-red-500",onClick:()=>$(r.id),children:e.jsx(o.Trash2,{className:"h-3 w-3"})})]},r.id)})]}),!l&&d.nodes.length>=2&&e.jsxs("div",{className:"mt-4 pt-4 border-t",children:[e.jsx(a.Label,{className:"text-xs text-muted-foreground mb-2 block",children:"Quick Connect"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("select",{id:"edge-source",className:"border rounded-md p-1.5 text-sm bg-background",children:[e.jsx("option",{value:"",children:"From..."}),d.nodes.filter(r=>r.type!=="end").map(r=>e.jsx("option",{value:r.id,children:r.label},r.id))]}),e.jsxs("select",{id:"edge-target",className:"border rounded-md p-1.5 text-sm bg-background",children:[e.jsx("option",{value:"",children:"To..."}),d.nodes.filter(r=>r.type!=="start").map(r=>e.jsx("option",{value:r.id,children:r.label},r.id))]})]}),e.jsxs(a.Button,{size:"sm",variant:"outline",className:"mt-2 w-full",onClick:()=>{const r=document.getElementById("edge-source")?.value,b=document.getElementById("edge-target")?.value;r&&b&&r!==b&&R(r,b)},children:[e.jsx(o.Plus,{className:"h-3 w-3 mr-1"}),"Connect"]})]})]})})]}),e.jsxs(a.Card,{className:"lg:col-span-1",children:[e.jsx(a.CardHeader,{children:e.jsxs(a.CardTitle,{className:"text-sm flex items-center gap-2",children:[e.jsx(o.Settings,{className:"h-4 w-4"}),"Properties"]})}),e.jsx(a.CardContent,{children:j?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Label"}),e.jsx(a.Input,{value:j.label,onChange:r=>w(j.id,{label:r.target.value}),className:"h-8 text-sm",readOnly:l})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Type"}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-muted text-sm",children:[ge[j.type],e.jsx("span",{className:"capitalize",children:j.type})]})]}),j.description!==void 0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Description"}),e.jsx(a.Input,{value:j.description||"",onChange:r=>w(j.id,{description:r.target.value}),className:"h-8 text-sm",readOnly:l})]}),(j.type==="approval"||j.type==="task")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Assignee"}),e.jsx(a.Input,{value:j.assignee||"",onChange:r=>w(j.id,{assignee:r.target.value}),className:"h-8 text-sm",placeholder:"User, role, or expression",readOnly:l})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Assignee Type"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2 bg-background",value:j.assigneeType||"user",onChange:r=>w(j.id,{assigneeType:r.target.value}),disabled:l,children:[e.jsx("option",{value:"user",children:"User"}),e.jsx("option",{value:"role",children:"Role"}),e.jsx("option",{value:"group",children:"Group"}),e.jsx("option",{value:"expression",children:"Expression"})]})]})]}),j.type==="delay"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Timeout (minutes)"}),e.jsx(a.Input,{type:"number",value:j.timeout||60,onChange:r=>w(j.id,{timeout:Number(r.target.value)}),className:"h-8 text-sm",readOnly:l})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-2",children:["ID: ",j.id]})]}):e.jsx("div",{className:"text-sm text-muted-foreground text-center py-8",children:"Select a node to edit its properties"})})]})]})]})},ke=({schema:n})=>{const{currentNodeId:u,approvalRule:l,history:x=[],data:d,showHistory:t=!0,showComments:m=!0}=n,[f,D]=h.useState(""),[O,j]=h.useState(!1),S=N=>{j(!0),console.log(`Approval action: ${N}`,{currentNodeId:u,comment:f,data:d}),setTimeout(()=>{j(!1),D("")},500)},w=N=>{switch(N){case"approve":case"approved":return e.jsx(a.Badge,{variant:"default",className:"bg-green-500",children:"Approved"});case"reject":case"rejected":return e.jsx(a.Badge,{variant:"destructive",children:"Rejected"});case"reassign":case"reassigned":return e.jsx(a.Badge,{variant:"secondary",children:"Reassigned"});case"comment":return e.jsx(a.Badge,{variant:"outline",children:"Comment"});case"escalate":case"escalated":return e.jsx(a.Badge,{variant:"secondary",className:"bg-orange-500 text-white",children:"Escalated"});default:return e.jsx(a.Badge,{variant:"outline",children:N})}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(a.Card,{children:[e.jsx(a.CardHeader,{children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(o.Clock,{className:"h-5 w-5"}),"Pending Approval",l&&e.jsxs(a.Badge,{variant:"outline",className:"ml-2",children:[l.type==="any"&&"Any approver",l.type==="all"&&"All must approve",l.type==="majority"&&"Majority approval",l.type==="sequential"&&"Sequential"]})]})}),e.jsxs(a.CardContent,{className:"space-y-4",children:[d&&Object.keys(d).length>0&&e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg",children:[e.jsx(a.Label,{className:"text-xs text-muted-foreground mb-2 block",children:"Request Details"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Object.entries(d).slice(0,6).map(([N,R])=>e.jsxs("div",{className:"text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[N,": "]}),e.jsx("span",{className:"font-medium",children:String(R)})]},N))})]}),m&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(a.Label,{className:"flex items-center gap-2 text-sm",children:[e.jsx(o.MessageSquare,{className:"h-4 w-4"}),"Comment"]}),e.jsx(a.Input,{value:f,onChange:N=>D(N.target.value),placeholder:"Add a comment (optional)"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{onClick:()=>S("approve"),disabled:O,className:"bg-green-600 hover:bg-green-700",children:[e.jsx(o.Check,{className:"h-4 w-4 mr-2"}),"Approve"]}),e.jsxs(a.Button,{variant:"destructive",onClick:()=>S("reject"),disabled:O,children:[e.jsx(o.X,{className:"h-4 w-4 mr-2"}),"Reject"]}),e.jsxs(a.Button,{variant:"outline",onClick:()=>S("reassign"),disabled:O,children:[e.jsx(o.RefreshCw,{className:"h-4 w-4 mr-2"}),"Reassign"]})]})]})]}),t&&x.length>0&&e.jsxs(a.Card,{children:[e.jsx(a.CardHeader,{children:e.jsx(a.CardTitle,{className:"text-sm",children:"Approval History"})}),e.jsx(a.CardContent,{children:e.jsx("div",{className:"space-y-3",children:x.map((N,R)=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border",children:[e.jsx("div",{className:"mt-0.5",children:e.jsx(o.User,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm",children:N.actorName||N.actor}),w(N.action),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(N.timestamp).toLocaleString()})]}),N.comment&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:N.comment})]})]},R))})})]}),t&&x.length===0&&e.jsx(a.Card,{children:e.jsx(a.CardContent,{className:"p-6 text-center text-muted-foreground text-sm",children:"No approval history yet"})})]})},Se={record_created:"Record Created",record_updated:"Record Updated",record_deleted:"Record Deleted",field_changed:"Field Changed",scheduled:"Scheduled"},Te={send_email:"Send Email",update_field:"Update Field",create_record:"Create Record",delete_record:"Delete Record",webhook:"Webhook",notification:"Notification"},He={send_email:e.jsx(o.Mail,{className:"h-4 w-4"}),update_field:e.jsx(o.FileEdit,{className:"h-4 w-4"}),create_record:e.jsx(o.Plus,{className:"h-4 w-4"}),delete_record:e.jsx(o.Trash2,{className:"h-4 w-4"}),webhook:e.jsx(o.Globe,{className:"h-4 w-4"}),notification:e.jsx(o.Bell,{className:"h-4 w-4"})},Ee={equals:"Equals",not_equals:"Not Equals",contains:"Contains",greater_than:"Greater Than",less_than:"Less Than"},ze=()=>({id:`auto-${Date.now()}`,name:"",description:"",enabled:!0,trigger:{type:"record_created"},actions:[],createdAt:new Date().toISOString()}),le=({label:n,value:u,placeholder:l,onChange:x})=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:n}),e.jsx(a.Input,{value:u,onChange:d=>x(d.target.value),placeholder:l})]}),_e=({automation:n,objects:u=[],onSave:l,onCancel:x,className:d})=>{const[t,m]=h.useState(n??ze()),f=h.useCallback(c=>{m(v=>({...v,trigger:{...v.trigger,...c}}))},[]),D=h.useCallback(()=>{m(c=>({...c,actions:[...c.actions,{type:"send_email",params:{}}]}))},[]),O=h.useCallback((c,v)=>{m(_=>({..._,actions:_.actions.map((T,r)=>r===c?{...T,...v}:T)}))},[]),j=h.useCallback(c=>{m(v=>({...v,actions:v.actions.filter((_,T)=>T!==c)}))},[]),S=t.trigger.type!=="scheduled",w=t.trigger.type==="field_changed",N=t.trigger.type==="scheduled",R=u.find(c=>c.name===t.trigger.objectName)?.fields,$=(c,v)=>{const _=(T,r)=>O(v,{params:{...c.params,[T]:r}});switch(c.type){case"send_email":return e.jsxs(e.Fragment,{children:[e.jsx(le,{label:"To",value:c.params.to??"",placeholder:"Recipient email",onChange:T=>_("to",T)}),e.jsx(le,{label:"Subject",value:c.params.subject??"",placeholder:"Email subject",onChange:T=>_("subject",T)})]});case"webhook":return e.jsx(le,{label:"URL",value:c.params.url??"",placeholder:"https://...",onChange:T=>_("url",T)});case"notification":return e.jsx(le,{label:"Message",value:c.params.message??"",placeholder:"Notification message",onChange:T=>_("message",T)});case"update_field":case"create_record":case"delete_record":return e.jsx(le,{label:"Target Object",value:c.params.objectName??"",placeholder:"Object name",onChange:T=>_("objectName",T)});default:return null}};return e.jsxs("div",{className:d??"space-y-4",children:[e.jsxs(a.Card,{children:[e.jsx(a.CardHeader,{children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-sm",children:[e.jsx(o.Zap,{className:"h-4 w-4 text-yellow-500"}),"Trigger"]})}),e.jsxs(a.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Trigger Type"}),e.jsxs(a.Select,{value:t.trigger.type,onValueChange:c=>f({type:c}),children:[e.jsx(a.SelectTrigger,{children:e.jsx(a.SelectValue,{placeholder:"Select trigger type"})}),e.jsx(a.SelectContent,{children:Object.keys(Se).map(c=>e.jsx(a.SelectItem,{value:c,children:Se[c]},c))})]})]}),S&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Object"}),u.length>0?e.jsxs(a.Select,{value:t.trigger.objectName??"",onValueChange:c=>f({objectName:c}),children:[e.jsx(a.SelectTrigger,{children:e.jsx(a.SelectValue,{placeholder:"Select object"})}),e.jsx(a.SelectContent,{children:u.map(c=>e.jsx(a.SelectItem,{value:c.name,children:c.label},c.name))})]}):e.jsx(a.Input,{value:t.trigger.objectName??"",onChange:c=>f({objectName:c.target.value}),placeholder:"Object name"})]}),w&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Field"}),R?e.jsxs(a.Select,{value:t.trigger.fieldName??"",onValueChange:c=>f({fieldName:c}),children:[e.jsx(a.SelectTrigger,{children:e.jsx(a.SelectValue,{placeholder:"Select field"})}),e.jsx(a.SelectContent,{children:Object.keys(R).map(c=>e.jsx(a.SelectItem,{value:c,children:c},c))})]}):e.jsx(a.Input,{value:t.trigger.fieldName??"",onChange:c=>f({fieldName:c.target.value}),placeholder:"Field name"})]}),N&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs(a.Label,{className:"text-xs flex items-center gap-1",children:[e.jsx(o.Clock,{className:"h-3 w-3"})," Cron Schedule"]}),e.jsx(a.Input,{value:t.trigger.schedule??"",onChange:c=>f({schedule:c.target.value}),placeholder:"e.g. 0 9 * * 1-5"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Condition (optional)"}),e.jsx(a.Input,{value:t.trigger.condition??"",onChange:c=>f({condition:c.target.value}),placeholder:'e.g. ${data.status === "active"}'})]}),e.jsx(a.Separator,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(a.Label,{className:"text-xs font-medium",children:"Conditional Trigger (optional)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Run only when a field matches a specific value."}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Field"}),R?e.jsxs(a.Select,{value:t.trigger.conditionField??"",onValueChange:c=>f({conditionField:c}),children:[e.jsx(a.SelectTrigger,{children:e.jsx(a.SelectValue,{placeholder:"Field"})}),e.jsx(a.SelectContent,{children:Object.keys(R).map(c=>e.jsx(a.SelectItem,{value:c,children:c},c))})]}):e.jsx(a.Input,{value:t.trigger.conditionField??"",onChange:c=>f({conditionField:c.target.value}),placeholder:"e.g. status"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Operator"}),e.jsxs(a.Select,{value:t.trigger.conditionOperator??"equals",onValueChange:c=>f({conditionOperator:c}),children:[e.jsx(a.SelectTrigger,{children:e.jsx(a.SelectValue,{placeholder:"Operator"})}),e.jsx(a.SelectContent,{children:Object.keys(Ee).map(c=>e.jsx(a.SelectItem,{value:c,children:Ee[c]},c))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Value"}),e.jsx(a.Input,{value:t.trigger.conditionValue??"",onChange:c=>f({conditionValue:c.target.value}),placeholder:"e.g. urgent"})]})]})]})]})]}),e.jsxs(a.Card,{children:[e.jsx(a.CardHeader,{children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-sm",children:[e.jsx(o.Settings,{className:"h-4 w-4"})," Actions",e.jsx(a.Badge,{variant:"secondary",className:"ml-auto",children:t.actions.length})]})}),e.jsxs(a.CardContent,{className:"space-y-3",children:[t.actions.length>1&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(a.Label,{className:"text-xs",children:"Execution"}),e.jsxs(a.Select,{value:t.executionMode??"sequential",onValueChange:c=>m(v=>({...v,executionMode:c})),children:[e.jsx(a.SelectTrigger,{className:"h-7 w-36",children:e.jsx(a.SelectValue,{})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"sequential",children:"Sequential"}),e.jsx(a.SelectItem,{value:"parallel",children:"Parallel"})]})]})]}),t.actions.map((c,v)=>e.jsxs("div",{className:"rounded-lg border p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[He[c.type],e.jsx("span",{className:"text-sm font-medium",children:t.actions.length>1&&(t.executionMode??"sequential")==="sequential"?`Step ${v+1}`:`Action ${v+1}`}),v>0&&t.actions.length>1&&(t.executionMode??"sequential")==="sequential"&&e.jsx(a.Badge,{variant:"outline",className:"text-[10px] px-1",children:"then"})]}),e.jsx(a.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-red-500 hover:text-red-700",onClick:()=>j(v),children:e.jsx(o.Trash2,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Action Type"}),e.jsxs(a.Select,{value:c.type,onValueChange:_=>O(v,{type:_,params:{}}),children:[e.jsx(a.SelectTrigger,{children:e.jsx(a.SelectValue,{})}),e.jsx(a.SelectContent,{children:Object.keys(Te).map(_=>e.jsx(a.SelectItem,{value:_,children:Te[_]},_))})]})]}),$(c,v)]},v)),e.jsxs(a.Button,{variant:"outline",size:"sm",className:"w-full",onClick:D,children:[e.jsx(o.Plus,{className:"h-4 w-4 mr-2"})," Add Action"]})]})]}),e.jsxs(a.Card,{children:[e.jsx(a.CardHeader,{children:e.jsx(a.CardTitle,{className:"text-sm",children:"Summary"})}),e.jsxs(a.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Name"}),e.jsx(a.Input,{value:t.name,onChange:c=>m(v=>({...v,name:c.target.value})),placeholder:"Automation name"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Description"}),e.jsx(a.Input,{value:t.description??"",onChange:c=>m(v=>({...v,description:c.target.value})),placeholder:"Optional description"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-sm",children:"Enabled"}),e.jsx(a.Switch,{checked:t.enabled,onCheckedChange:c=>m(v=>({...v,enabled:c}))})]}),e.jsx(a.Separator,{}),e.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[x&&e.jsx(a.Button,{variant:"outline",size:"sm",onClick:x,children:"Cancel"}),e.jsxs(a.Button,{size:"sm",onClick:()=>l?.(t),children:[e.jsx(o.Zap,{className:"h-4 w-4 mr-2"})," Save Automation"]})]})]})]})]})},We={success:"default",failure:"destructive",running:"secondary",pending:"outline"},Ge={success:"Success",failure:"Failed",running:"Running",pending:"Pending"};function Xe(n,u){if(!u)return"—";const l=new Date(u).getTime()-new Date(n).getTime();if(l<1e3)return`${l}ms`;const x=Math.floor(l/1e3);if(x<60)return`${x}s`;const d=Math.floor(x/60),t=x%60;return`${d}m ${t}s`}const Ae=({runs:n=[],className:u})=>e.jsxs(a.Card,{className:u,children:[e.jsx(a.CardHeader,{children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-sm",children:[e.jsx(o.Clock,{className:"h-4 w-4"}),"Automation Run History",e.jsx(a.Badge,{variant:"outline",className:"ml-auto",children:n.length})]})}),e.jsx(a.CardContent,{children:n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No automation runs yet"}):e.jsx("div",{className:"space-y-2",children:n.map(l=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border p-3",children:[e.jsx(a.Badge,{variant:We[l.status],children:Ge[l.status]}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium",children:l.automationName}),l.triggerEvent&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["— ",l.triggerEvent]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:new Date(l.startedAt).toLocaleString()}),e.jsxs("span",{children:["Duration: ",Xe(l.startedAt,l.completedAt)]})]}),l.status==="failure"&&l.error&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:l.error})]})]},l.id))})})]});function pe(...n){return Re.twMerge(Be.clsx(n))}const Pe=130,re=52,ie={start:"Start",end:"End",task:"Task",user_task:"User Task",service_task:"Service Task",script_task:"Script Task",approval:"Approval",condition:"Condition",parallel_gateway:"Parallel Gateway",join_gateway:"Join Gateway",boundary_event:"Boundary Event",delay:"Delay",notification:"Notification",webhook:"Webhook"},Oe={start:e.jsx(o.Play,{className:"h-3.5 w-3.5 text-green-500"}),end:e.jsx(o.Square,{className:"h-3.5 w-3.5 text-red-500"}),task:e.jsx(o.CheckCircle,{className:"h-3.5 w-3.5 text-blue-500"}),user_task:e.jsx(o.Users,{className:"h-3.5 w-3.5 text-blue-600"}),service_task:e.jsx(o.Settings,{className:"h-3.5 w-3.5 text-blue-400"}),script_task:e.jsx(o.Code,{className:"h-3.5 w-3.5 text-indigo-500"}),approval:e.jsx(o.Users,{className:"h-3.5 w-3.5 text-purple-500"}),condition:e.jsx(o.GitBranch,{className:"h-3.5 w-3.5 text-orange-500"}),parallel_gateway:e.jsx(o.GitBranch,{className:"h-3.5 w-3.5 text-teal-500"}),join_gateway:e.jsx(o.GitMerge,{className:"h-3.5 w-3.5 text-teal-600"}),boundary_event:e.jsx(o.AlertCircle,{className:"h-3.5 w-3.5 text-amber-500"}),delay:e.jsx(o.Clock,{className:"h-3.5 w-3.5 text-gray-500"}),notification:e.jsx(o.Bell,{className:"h-3.5 w-3.5 text-yellow-500"}),webhook:e.jsx(o.Globe,{className:"h-3.5 w-3.5 text-cyan-500"})},Ze={start:"border-green-400 bg-green-50 dark:bg-green-950",end:"border-red-400 bg-red-50 dark:bg-red-950",task:"border-blue-300 bg-blue-50 dark:bg-blue-950",user_task:"border-blue-400 bg-blue-50 dark:bg-blue-950",service_task:"border-blue-200 bg-slate-50 dark:bg-slate-900",script_task:"border-indigo-300 bg-indigo-50 dark:bg-indigo-950",approval:"border-purple-400 bg-purple-50 dark:bg-purple-950",condition:"border-orange-400 bg-orange-50 dark:bg-orange-950",parallel_gateway:"border-teal-400 bg-teal-50 dark:bg-teal-950",join_gateway:"border-teal-500 bg-teal-50 dark:bg-teal-950",boundary_event:"border-amber-400 bg-amber-50 dark:bg-amber-950 border-dashed",delay:"border-gray-400 bg-gray-50 dark:bg-gray-900",notification:"border-yellow-400 bg-yellow-50 dark:bg-yellow-950",webhook:"border-cyan-400 bg-cyan-50 dark:bg-cyan-950"},Je={pending:{color:"text-muted-foreground",icon:e.jsx(o.Clock,{className:"h-3 w-3"})},running:{color:"text-blue-500",icon:e.jsx(o.Loader2,{className:"h-3 w-3 animate-spin"})},completed:{color:"text-green-500",icon:e.jsx(o.CheckCircle,{className:"h-3 w-3"})},failed:{color:"text-red-500",icon:e.jsx(o.AlertCircle,{className:"h-3 w-3"})},skipped:{color:"text-gray-400",icon:e.jsx(o.SkipForward,{className:"h-3 w-3"})}},Ke=["task","user_task","service_task","script_task","approval","condition","parallel_gateway","join_gateway","boundary_event","delay","notification","webhook"],Qe={allow:"Allow (run concurrently)",forbid:"Forbid (skip new)",replace:"Replace (cancel existing)",queue:"Queue (run after current)"},Ie={condition:"Condition",manual:"Manual",webhook:"Webhook",timer:"Timer",signal:"Signal"},qe=()=>[{id:"start-1",type:"start",label:"Start",position:{x:80,y:200}},{id:"end-1",type:"end",label:"End",position:{x:500,y:200}}],$e=()=>[];function ea(n){const[u,l]=h.useState([n]),[x,d]=h.useState(0),t=u[x],m=h.useCallback(S=>{l(w=>[...w.slice(0,x+1),S]),d(w=>w+1)},[x]),f=h.useCallback(()=>{d(S=>Math.max(0,S-1))},[]),D=h.useCallback(()=>{l(S=>(d(w=>Math.min(S.length-1,w+1)),S))},[]),O=x>0,j=x<u.length-1;return{current:t,push:m,undo:f,redo:D,canUndo:O,canRedo:j}}function aa(n,u,l){const x=[],d=["boundary_event"];n.forEach(m=>{d.includes(m.type)&&x.push(`Node "${m.label}" (${m.type}) has limited BPMN mapping.`)});const t=['<?xml version="1.0" encoding="UTF-8"?>','<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"',' xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"',' targetNamespace="http://objectui.org/bpmn">',` <process id="process-1" name="${l}" isExecutable="true">`,...n.map(m=>` <${sa(m.type)} id="${m.id}" name="${m.label}" />`),...u.map(m=>` <sequenceFlow ${[`id="${m.id}"`,`sourceRef="${m.source}"`,`targetRef="${m.target}"`,m.condition?`conditionExpression="${m.condition}"`:""].filter(Boolean).join(" ")} />`)," </process>","</definitions>"].join(`
|
|
7
|
-
`);return{success:!0,nodeCount:n.length,edgeCount:u.length,warnings:x.length?x:void 0,bpmnXml:t}}function sa(n){return{start:"startEvent",end:"endEvent",task:"task",user_task:"userTask",service_task:"serviceTask",script_task:"scriptTask",approval:"userTask",condition:"exclusiveGateway",parallel_gateway:"parallelGateway",join_gateway:"parallelGateway",boundary_event:"boundaryEvent",delay:"intermediateCatchEvent",notification:"sendTask",webhook:"serviceTask"}[n]??"task"}function ta(n,u){const l=n.position.x+Pe,x=n.position.y+re/2,d=u.position.x,t=u.position.y+re/2,m=(l+d)/2;return{d:`M ${l} ${x} C ${m} ${x}, ${m} ${t}, ${d} ${t}`,labelX:m,labelY:(x+t)/2-8}}const la=({node:n,isSelected:u,isConnectSource:l,connectMode:x,readOnly:d,showExecutionOverlay:t,onSelect:m,onDelete:f,onDragStart:D,onPortClick:O})=>{const j=n.executionStatus,S=j?Je[j]:null;return e.jsxs("div",{className:"absolute select-none",style:{left:n.position.x,top:n.position.y},draggable:!d&&!x,onDragStart:w=>D(w,n.id),onClick:w=>m(n.id,w.shiftKey),role:"group","aria-label":n.label,children:[e.jsxs("div",{className:pe("flex items-center gap-2 border-2 rounded px-3 py-2 min-h-[52px] transition-shadow cursor-pointer",Ze[n.type],u&&"ring-2 ring-primary shadow-md",l&&"ring-2 ring-blue-400 shadow-lg",x&&!l&&"cursor-crosshair",t&&j==="running"&&"ring-2 ring-blue-400",t&&j==="failed"&&"ring-2 ring-red-400",t&&j==="completed"&&"ring-2 ring-green-400"),style:{width:Pe,minHeight:re},children:[e.jsx("span",{className:"shrink-0",children:Oe[n.type]}),e.jsx("span",{className:"text-xs font-medium leading-tight flex-1 truncate",children:n.label}),t&&S&&e.jsx("span",{className:pe("shrink-0",S.color),children:S.icon})]}),!d&&(u||x)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-primary border-2 border-background shadow cursor-crosshair",style:{right:-6,top:re/2-6},title:"Connect from this node",onClick:w=>{w.stopPropagation(),O(n.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-muted-foreground border-2 border-background shadow cursor-crosshair",style:{left:-6,top:re/2-6},title:"Connect to this node",onClick:w=>{w.stopPropagation(),O(n.id)}})]}),!d&&u&&!x&&e.jsx("button",{className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow",onClick:w=>{w.stopPropagation(),f(n.id)},"aria-label":`Delete node ${n.label}`,children:e.jsx(o.Trash2,{className:"h-3 w-3"})})]})},ra=({node:n,edge:u,readOnly:l,onNodeChange:x,onEdgeChange:d})=>!n&&!u?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Select a node or edge to edit its properties."}):n?e.jsxs("div",{className:"p-3 space-y-3 overflow-y-auto",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Node Properties"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Label"}),e.jsx(a.Input,{value:n.label,onChange:t=>x({...n,label:t.target.value}),disabled:l,className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Type"}),e.jsxs(a.Select,{value:n.type,onValueChange:t=>x({...n,type:t}),disabled:l,children:[e.jsx(a.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(a.SelectValue,{})}),e.jsx(a.SelectContent,{children:Object.keys(ie).map(t=>e.jsx(a.SelectItem,{value:t,className:"text-xs",children:ie[t]},t))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Description"}),e.jsx(a.Input,{value:n.description??"",onChange:t=>x({...n,description:t.target.value}),disabled:l,className:"h-7 text-xs",placeholder:"Optional description"})]}),["task","user_task","service_task","script_task","delay","webhook"].includes(n.type)&&e.jsxs(e.Fragment,{children:[e.jsx(a.Separator,{}),e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Executor"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Executor Type"}),e.jsx(a.Input,{value:n.executor?.type??"",onChange:t=>x({...n,executor:{...n.executor,type:t.target.value}}),disabled:l,className:"h-7 text-xs",placeholder:"e.g. http, script, email"})]}),n.type==="delay"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Wait Event Type"}),e.jsxs(a.Select,{value:n.executor?.waitEventConfig?.eventType??"timer",onValueChange:t=>x({...n,executor:{...n.executor,type:n.executor?.type??"wait",waitEventConfig:{...n.executor?.waitEventConfig,eventType:t}}}),disabled:l,children:[e.jsx(a.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(a.SelectValue,{})}),e.jsx(a.SelectContent,{children:Object.keys(Ie).map(t=>e.jsx(a.SelectItem,{value:t,className:"text-xs",children:Ie[t]},t))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Timeout (ms)"}),e.jsx(a.Input,{type:"number",value:n.executor?.timeoutMs??"",onChange:t=>x({...n,executor:{...n.executor,type:n.executor?.type??"",timeoutMs:t.target.value?Number(t.target.value):void 0}}),disabled:l,className:"h-7 text-xs",placeholder:"e.g. 30000"})]})]}),n.type==="boundary_event"&&e.jsxs(e.Fragment,{children:[e.jsx(a.Separator,{}),e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Boundary Config"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Attached To Node ID"}),e.jsx(a.Input,{value:n.boundaryConfig?.attachedToNodeId??"",onChange:t=>x({...n,boundaryConfig:{...n.boundaryConfig,attachedToNodeId:t.target.value,eventType:n.boundaryConfig?.eventType??"error"}}),disabled:l,className:"h-7 text-xs",placeholder:"Host node id"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Event Type"}),e.jsxs(a.Select,{value:n.boundaryConfig?.eventType??"error",onValueChange:t=>x({...n,boundaryConfig:{...n.boundaryConfig,attachedToNodeId:n.boundaryConfig?.attachedToNodeId??"",eventType:t}}),disabled:l,children:[e.jsx(a.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(a.SelectValue,{})}),e.jsx(a.SelectContent,{children:["error","timer","message","signal","compensation"].map(t=>e.jsx(a.SelectItem,{value:t,className:"text-xs capitalize",children:t},t))})]})]})]})]}):u?e.jsxs("div",{className:"p-3 space-y-3 overflow-y-auto",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Edge Properties"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Label"}),e.jsx(a.Input,{value:u.label??"",onChange:t=>d({...u,label:t.target.value}),disabled:l,className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Type"}),e.jsxs(a.Select,{value:u.type??"default",onValueChange:t=>d({...u,type:t}),disabled:l,children:[e.jsx(a.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(a.SelectValue,{})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"default",className:"text-xs",children:"Default"}),e.jsx(a.SelectItem,{value:"conditional",className:"text-xs",children:"Conditional"}),e.jsx(a.SelectItem,{value:"timeout",className:"text-xs",children:"Timeout"})]})]})]}),u.type==="conditional"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"text-xs",children:"Condition Expression"}),e.jsx(a.Input,{value:u.condition??"",onChange:t=>d({...u,condition:t.target.value}),disabled:l,className:"h-7 text-xs font-mono",placeholder:"e.g. status === 'approved'"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"edge-isDefault",checked:u.isDefault??!1,onChange:t=>d({...u,isDefault:t.target.checked}),disabled:l,className:"h-3.5 w-3.5"}),e.jsx(a.Label,{htmlFor:"edge-isDefault",className:"text-xs",children:"Default edge (isDefault)"})]})]}):null,ia=({versions:n})=>e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Version History"}),n.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No version history available."}),e.jsx("div",{className:"space-y-1.5",children:n.map(u=>e.jsxs("div",{className:pe("rounded border p-2 text-xs",u.isCurrent?"border-primary bg-primary/5":"border-border bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:["v",u.version]}),u.isCurrent&&e.jsx(a.Badge,{variant:"default",className:"text-[10px] h-4",children:"Current"})]}),u.changeNote&&e.jsx("p",{className:"text-muted-foreground mt-0.5",children:u.changeNote}),e.jsxs("p",{className:"text-muted-foreground mt-0.5",children:[u.author&&e.jsxs(e.Fragment,{children:[u.author," · "]}),new Date(u.createdAt).toLocaleDateString()]})]},u.version))})]}),De=({schema:n,onSave:u})=>{const{readOnly:l=!1,showToolbar:x=!0,showMinimap:d=!1,showVersionHistory:t=!1,showExecutionOverlay:m=!1,executionSteps:f=[],versionHistory:D=[],concurrencyPolicy:O,title:j="New Flow",description:S="",status:w="draft"}=n,[N,R]=h.useState(j),[$,c]=h.useState(S),v=n.nodes??qe(),_=n.edges??$e(),{current:T,push:r,undo:b,redo:P,canUndo:B,canRedo:ee}=ea({nodes:v,edges:_}),y=T.nodes,E=T.edges,[M,U]=h.useState(null),[F,X]=h.useState(null),[H,Z]=h.useState(!1),[z,J]=h.useState(null),[ae,ue]=h.useState(!0),[s,g]=h.useState(t),[C,A]=h.useState(null),[W,K]=h.useState(1),k=h.useRef(null),G=h.useMemo(()=>y.find(i=>i.id===M)??null,[y,M]),ne=h.useMemo(()=>E.find(i=>i.id===F)??null,[E,F]),ce=h.useMemo(()=>{if(!m||f.length===0)return y;const i=new Map(f.map(p=>[p.nodeId,p.status]));return y.map(p=>i.has(p.id)?{...p,executionStatus:i.get(p.id)}:p)},[y,m,f]),na=h.useCallback(i=>{if(l)return;const I={id:`${i}-${Date.now()}`,type:i,label:ie[i],position:{x:200,y:80+y.length*70}};r({nodes:[...y,I],edges:E})},[l,y,E,r]),je=h.useCallback(i=>{if(l)return;const p=y.filter(V=>V.id!==i),I=E.filter(V=>V.source!==i&&V.target!==i);r({nodes:p,edges:I}),M===i&&U(null)},[l,y,E,r,M]),ca=h.useCallback(i=>{l||r({nodes:y.map(p=>p.id===i.id?i:p),edges:E})},[l,y,E,r]),Le=h.useCallback(i=>{l||(r({nodes:y,edges:E.filter(p=>p.id!==i)}),F===i&&X(null))},[l,y,E,r,F]),oa=h.useCallback(i=>{l||r({nodes:y,edges:E.map(p=>p.id===i.id?i:p)})},[l,y,E,r]),da=h.useCallback(i=>{if(!l){if(!H){Z(!0),J(i);return}if(z&&z!==i){const I={id:`edge-${Date.now()}`,source:z,target:i};r({nodes:y,edges:[...E,I]})}Z(!1),J(null)}},[l,H,z,y,E,r]),xe=h.useRef(null),Q=h.useRef(null),ua=h.useCallback((i,p)=>{xe.current=p;const I=y.find(V=>V.id===p);I&&(Q.current={mouseX:i.clientX,mouseY:i.clientY,nodeX:I.position.x,nodeY:I.position.y}),i.dataTransfer.effectAllowed="move"},[y]),xa=h.useCallback(i=>{if(i.preventDefault(),!xe.current||!Q.current||!k.current)return;k.current.getBoundingClientRect();const p=(i.clientX-Q.current.mouseX)/W,I=(i.clientY-Q.current.mouseY)/W,V=Math.max(0,Q.current.nodeX+p),he=Math.max(0,Q.current.nodeY+I),me=xe.current;r({nodes:y.map(q=>q.id===me?{...q,position:{x:V,y:he}}:q),edges:E}),xe.current=null,Q.current=null},[y,E,r,W]),ha=h.useCallback(()=>{const i=aa(y,E,N);A(i);const p=new Blob([i.bpmnXml??""],{type:"application/xml"}),I=URL.createObjectURL(p),V=document.createElement("a");V.href=I,V.download=`${N.replace(/\s+/g,"-").toLowerCase()}.bpmn`,V.click(),URL.revokeObjectURL(I)},[y,E,N]),fe=h.useCallback(()=>{u?.(y,E)},[y,E,u]),ma=h.useCallback(i=>{const p=i.ctrlKey||i.metaKey;if(p&&i.key==="z"&&!i.shiftKey){i.preventDefault(),b();return}if(p&&(i.key==="y"||i.key==="z"&&i.shiftKey)){i.preventDefault(),P();return}if(p&&i.key==="s"){i.preventDefault(),fe();return}i.key==="Escape"&&(Z(!1),J(null),U(null),X(null)),(i.key==="Delete"||i.key==="Backspace")&&(M?je(M):F&&Le(F))},[b,P,fe,M,F,je,Le]);return e.jsxs(a.Card,{className:"flex flex-col h-full min-h-[600px] outline-none",tabIndex:0,onKeyDown:ma,children:[e.jsx(a.CardHeader,{className:"py-2 px-4 border-b flex-shrink-0",children:e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(o.Zap,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx(a.CardTitle,{className:"text-sm font-semibold",children:l?e.jsx("span",{children:N}):e.jsx(a.Input,{value:N,onChange:i=>R(i.target.value),className:"h-6 text-sm font-semibold border-0 p-0 focus-visible:ring-0 bg-transparent","aria-label":"Flow title"})}),e.jsx(a.Badge,{variant:"outline",className:"text-xs capitalize",children:w}),O&&e.jsx(a.Badge,{variant:"secondary",className:"text-xs",children:Qe[O]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[!l&&e.jsxs(e.Fragment,{children:[e.jsx(a.Button,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:b,disabled:!B,title:"Undo (Ctrl+Z)",children:e.jsx(o.Undo2,{className:"h-4 w-4"})}),e.jsx(a.Button,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:P,disabled:!ee,title:"Redo (Ctrl+Y)",children:e.jsx(o.Redo2,{className:"h-4 w-4"})}),e.jsx(a.Separator,{orientation:"vertical",className:"h-5 mx-1"})]}),e.jsx(a.Button,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>K(i=>Math.min(2,i+.1)),title:"Zoom in",children:e.jsx(o.ZoomIn,{className:"h-4 w-4"})}),e.jsx(a.Button,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>K(1),title:"Reset zoom",children:e.jsx(o.RotateCcw,{className:"h-4 w-4"})}),e.jsx(a.Button,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>K(i=>Math.max(.3,i-.1)),title:"Zoom out",children:e.jsx(o.ZoomOut,{className:"h-4 w-4"})}),e.jsx(a.Separator,{orientation:"vertical",className:"h-5 mx-1"}),D.length>0&&e.jsx(a.Button,{size:"icon",variant:s?"secondary":"ghost",className:"h-7 w-7",onClick:()=>g(i=>!i),title:"Version history",children:e.jsx(o.History,{className:"h-4 w-4"})}),e.jsx(a.Button,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:ha,title:"Export BPMN",children:e.jsx(o.Download,{className:"h-4 w-4"})}),!l&&e.jsxs(e.Fragment,{children:[e.jsx(a.Button,{size:"icon",variant:"ghost",className:"h-7 w-7",title:"Import BPMN (drag & drop)",children:e.jsx(o.Upload,{className:"h-4 w-4"})}),e.jsxs(a.Button,{size:"sm",variant:"default",className:"h-7 text-xs gap-1",onClick:fe,title:"Save (Ctrl+S)",children:[e.jsx(o.Save,{className:"h-3.5 w-3.5"})," Save"]})]}),e.jsx(a.Button,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>ue(i=>!i),title:ae?"Hide properties":"Show properties",children:ae?e.jsx(o.PanelRightClose,{className:"h-4 w-4"}):e.jsx(o.PanelRightOpen,{className:"h-4 w-4"})})]})]})}),e.jsxs(a.CardContent,{className:"flex flex-1 p-0 overflow-hidden",children:[x&&!l&&e.jsxs("div",{className:"w-36 border-r bg-muted/30 flex-shrink-0 overflow-y-auto py-2 px-2",children:[e.jsx("p",{className:"text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-2 px-1",children:"Add Node"}),e.jsx("div",{className:"space-y-1",children:Ke.map(i=>e.jsxs("button",{className:"w-full flex items-center gap-2 text-xs px-2 py-1.5 rounded hover:bg-muted transition-colors text-left",onClick:()=>na(i),title:`Add ${ie[i]}`,children:[Oe[i],e.jsx("span",{className:"truncate",children:ie[i]})]},i))}),H&&e.jsxs(e.Fragment,{children:[e.jsx(a.Separator,{className:"my-2"}),e.jsxs("div",{className:"px-1",children:[e.jsx("p",{className:"text-[10px] text-blue-600 font-medium",children:"Connect mode"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Click a target node port to connect."}),e.jsx(a.Button,{size:"sm",variant:"outline",className:"h-6 text-xs mt-1 w-full",onClick:()=>{Z(!1),J(null)},children:"Cancel"})]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto relative bg-dot-pattern",children:e.jsxs("div",{ref:k,className:"relative",style:{width:1200,height:700,transform:`scale(${W})`,transformOrigin:"top left"},onDrop:xa,onDragOver:i=>i.preventDefault(),onClick:i=>{i.target===k.current&&(U(null),X(null))},children:[e.jsxs("svg",{className:"absolute inset-0 pointer-events-none",width:1200,height:700,style:{overflow:"visible"},children:[e.jsxs("defs",{children:[e.jsx("marker",{id:"fd-arrowhead",markerWidth:"10",markerHeight:"7",refX:"9",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"hsl(var(--foreground) / 0.5)"})}),e.jsx("marker",{id:"fd-arrowhead-selected",markerWidth:"10",markerHeight:"7",refX:"9",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"hsl(var(--primary))"})}),e.jsx("marker",{id:"fd-arrowhead-conditional",markerWidth:"10",markerHeight:"7",refX:"9",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"hsl(var(--foreground) / 0.6)"})})]}),E.map(i=>{const p=ce.find(oe=>oe.id===i.source),I=ce.find(oe=>oe.id===i.target);if(!p||!I)return null;const{d:V,labelX:he,labelY:me}=ta(p,I),q=i.id===F,be=i.type==="conditional",Ne=i.isDefault;return e.jsxs("g",{className:"pointer-events-auto cursor-pointer",onClick:oe=>{oe.stopPropagation(),X(i.id),U(null)},children:[e.jsx("path",{d:V,fill:"none",stroke:q?"hsl(var(--primary))":be?"hsl(var(--foreground) / 0.6)":"hsl(var(--foreground) / 0.4)",strokeWidth:q?2.5:2,strokeDasharray:be?"6 3":Ne?"3 3":void 0,markerEnd:`url(#fd-arrowhead${q?"-selected":be?"-conditional":""})`}),(i.label||Ne)&&e.jsx("text",{x:he,y:me,textAnchor:"middle",className:"text-[10px] fill-muted-foreground",style:{fontSize:10},children:i.label??(Ne?"(default)":"")}),i.condition&&e.jsx("text",{x:he,y:me+12,textAnchor:"middle",className:"text-[9px] fill-orange-500",style:{fontSize:9},children:i.condition.length>24?i.condition.slice(0,24)+"…":i.condition}),e.jsx("path",{d:V,fill:"none",stroke:"transparent",strokeWidth:12})]},i.id)})]}),ce.map(i=>e.jsx(la,{node:i,isSelected:M===i.id,isConnectSource:z===i.id,connectMode:H,readOnly:l,showExecutionOverlay:m,onSelect:(p,I)=>{I||X(null),U(p)},onDelete:je,onDragStart:ua,onPortClick:da},i.id)),H&&z&&e.jsxs("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-blue-600 text-white text-xs px-3 py-1.5 rounded shadow-lg pointer-events-none",children:[e.jsx(o.Link,{className:"h-3 w-3 inline mr-1"}),"Click a node port to complete the connection — Esc to cancel"]}),y.length===0&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-muted-foreground text-sm",children:"No nodes yet. Use the toolbar to add nodes."})]})}),s&&D.length>0&&e.jsx("div",{className:"w-48 border-l bg-background flex-shrink-0 overflow-y-auto",children:e.jsx(ia,{versions:D})}),ae&&e.jsxs("div",{className:"w-52 border-l bg-background flex-shrink-0 overflow-y-auto",children:[e.jsx(ra,{node:G,edge:ne,readOnly:l,onNodeChange:ca,onEdgeChange:oa}),C&&e.jsxs("div",{className:"p-3 border-t",children:[e.jsx("p",{className:"text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1",children:"BPMN Export"}),e.jsx(a.Badge,{variant:C.success?"default":"destructive",className:"text-[10px]",children:C.success?`Exported ${C.nodeCount} nodes`:"Export failed"}),C.warnings?.map((i,p)=>e.jsx("p",{className:"text-[10px] text-amber-600 mt-0.5",children:i},p))]})]})]})]})};Y.ComponentRegistry.register("workflow-designer",Ce,{label:"Workflow Designer",category:"Enterprise",inputs:[{name:"workflow",type:"code",label:"Initial Workflow Definition"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1},{name:"showToolbar",type:"boolean",label:"Show Toolbar",defaultValue:!0},{name:"showMinimap",type:"boolean",label:"Show Minimap",defaultValue:!1}]}),Y.ComponentRegistry.register("approval-process",ke,{label:"Approval Process",category:"Enterprise",inputs:[{name:"workflowId",type:"string",label:"Workflow ID"},{name:"instanceId",type:"string",label:"Instance ID"},{name:"currentNodeId",type:"string",label:"Current Node ID"},{name:"approvalRule",type:"code",label:"Approval Rule"},{name:"history",type:"code",label:"History"},{name:"showHistory",type:"boolean",label:"Show History",defaultValue:!0},{name:"showComments",type:"boolean",label:"Show Comments",defaultValue:!0}]}),Y.ComponentRegistry.register("automation-builder",_e,{label:"Automation Builder",category:"Enterprise",inputs:[{name:"automation",type:"code",label:"Automation Definition"},{name:"objects",type:"code",label:"Available Objects"}]}),Y.ComponentRegistry.register("automation-run-history",Ae,{label:"Automation Run History",category:"Enterprise",inputs:[{name:"runs",type:"code",label:"Run History"}]}),Y.ComponentRegistry.register("flow-designer",De,{label:"Flow Designer",category:"Enterprise",inputs:[{name:"nodes",type:"code",label:"Flow Nodes"},{name:"edges",type:"code",label:"Flow Edges"},{name:"title",type:"string",label:"Flow Title"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1},{name:"showToolbar",type:"boolean",label:"Show Toolbar",defaultValue:!0},{name:"showMinimap",type:"boolean",label:"Show Minimap",defaultValue:!1},{name:"showVersionHistory",type:"boolean",label:"Show Version History",defaultValue:!1},{name:"showExecutionOverlay",type:"boolean",label:"Show Execution Overlay",defaultValue:!1},{name:"concurrencyPolicy",type:"string",label:"Concurrency Policy"},{name:"versionHistory",type:"code",label:"Version History"},{name:"executionSteps",type:"code",label:"Execution Steps"}]}),L.ApprovalProcess=ke,L.AutomationBuilder=_e,L.AutomationRunHistory=Ae,L.FlowDesigner=De,L.WorkflowDesigner=Ce,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
|
|
6
|
+
<%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),_=p(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=h():t.exports=g()}))(),v={start:(0,_.jsx)(i.Play,{className:`h-4 w-4 text-green-500`}),end:(0,_.jsx)(i.CheckCircle,{className:`h-4 w-4 text-red-500`}),task:(0,_.jsx)(i.Circle,{className:`h-4 w-4 text-blue-500`}),approval:(0,_.jsx)(i.Users,{className:`h-4 w-4 text-purple-500`}),condition:(0,_.jsx)(i.GitBranch,{className:`h-4 w-4 text-orange-500`}),parallel:(0,_.jsx)(i.ArrowRight,{className:`h-4 w-4 text-teal-500`}),delay:(0,_.jsx)(i.Clock,{className:`h-4 w-4 text-gray-500`}),notification:(0,_.jsx)(i.Bell,{className:`h-4 w-4 text-yellow-500`}),script:(0,_.jsx)(i.Code,{className:`h-4 w-4 text-indigo-500`})},y={start:`border-green-300 bg-green-50`,end:`border-red-300 bg-red-50`,task:`border-blue-300 bg-blue-50`,approval:`border-purple-300 bg-purple-50`,condition:`border-orange-300 bg-orange-50`,parallel:`border-teal-300 bg-teal-50`,delay:`border-gray-300 bg-gray-50`,notification:`border-yellow-300 bg-yellow-50`,script:`border-indigo-300 bg-indigo-50`},b={draft:{variant:`secondary`,label:`Draft`},active:{variant:`default`,label:`Active`},paused:{variant:`outline`,label:`Paused`},completed:{variant:`default`,label:`Completed`},cancelled:{variant:`destructive`,label:`Cancelled`}},x=({schema:e})=>{let{workflow:t,readOnly:a=!1,showToolbar:o=!0}=e,[s,c]=(0,n.useState)(t||{type:`workflow`,title:`New Workflow`,status:`draft`,nodes:[{id:`start-1`,type:`start`,label:`Start`,position:{x:100,y:100}},{id:`end-1`,type:`end`,label:`End`,position:{x:100,y:400}}],edges:[],variables:[]}),[l,u]=(0,n.useState)(null),[d,f]=(0,n.useState)(null),p=(0,n.useMemo)(()=>s.nodes.find(e=>e.id===l),[s.nodes,l]),m=(0,n.useCallback)(e=>{if(a)return;let t=`${e}-${Date.now()}`,n={id:t,type:e,label:`New ${e.charAt(0).toUpperCase()+e.slice(1)}`,position:{x:200,y:(s.nodes.length+1)*80}};c(e=>({...e,nodes:[...e.nodes,n]})),u(t)},[a,s.nodes.length]),h=(0,n.useCallback)((e,t)=>{a||c(n=>({...n,nodes:n.nodes.map(n=>n.id===e?{...n,...t}:n)}))},[a]),g=(0,n.useCallback)(e=>{a||(c(t=>({...t,nodes:t.nodes.filter(t=>t.id!==e),edges:t.edges.filter(t=>t.source!==e&&t.target!==e)})),l===e&&u(null))},[a,l]),x=(0,n.useCallback)((e,t)=>{if(a)return;let n={id:`edge-${Date.now()}`,source:e,target:t};c(e=>({...e,edges:[...e.edges,n]}))},[a]),S=(0,n.useCallback)(e=>{a||(c(t=>({...t,edges:t.edges.filter(t=>t.id!==e)})),d===e&&f(null))},[a,d]),C=()=>{console.log(`Saving workflow:`,s),e.onSave},w=()=>{c(e=>({...e,status:`active`})),console.log(`Publishing workflow`),e.onPublish},T=b[s.status||`draft`];return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[o&&(0,_.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,_.jsx)(`div`,{children:(0,_.jsx)(r.Input,{value:s.title||``,onChange:e=>c(t=>({...t,title:e.target.value})),className:`text-lg font-semibold border-none p-0 h-auto focus-visible:ring-0`,readOnly:a,placeholder:`Workflow Title`})}),(0,_.jsx)(r.Badge,{variant:T.variant,children:T.label})]}),!a&&(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:C,children:[(0,_.jsx)(i.Save,{className:`h-4 w-4 mr-2`}),`Save`]}),(0,_.jsxs)(r.Button,{size:`sm`,onClick:w,disabled:s.status===`active`,children:[(0,_.jsx)(i.Play,{className:`h-4 w-4 mr-2`}),`Publish`]})]})]}),(0,_.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-4 gap-4`,children:[!a&&(0,_.jsxs)(r.Card,{className:`lg:col-span-1`,children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsx)(r.CardTitle,{className:`text-sm`,children:`Add Node`})}),(0,_.jsx)(r.CardContent,{className:`space-y-2`,children:[`task`,`approval`,`condition`,`parallel`,`delay`,`notification`,`script`].map(e=>(0,_.jsxs)(`button`,{onClick:()=>m(e),className:`w-full flex items-center gap-2 p-2 rounded-md border hover:bg-muted/50 transition-colors text-sm`,children:[v[e],(0,_.jsx)(`span`,{className:`capitalize`,children:e})]},e))})]}),(0,_.jsxs)(r.Card,{className:a?`lg:col-span-3`:`lg:col-span-2`,children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsxs)(r.CardTitle,{className:`text-sm flex items-center gap-2`,children:[(0,_.jsx)(i.GitBranch,{className:`h-4 w-4`}),`Workflow Flow`]})}),(0,_.jsx)(r.CardContent,{children:(0,_.jsxs)(`div`,{className:`space-y-2`,children:[s.nodes.map(e=>(0,_.jsxs)(`div`,{onClick:()=>{u(e.id),f(null)},className:`flex items-center justify-between p-3 rounded-lg border-2 cursor-pointer transition-all ${y[e.type]} ${l===e.id?`ring-2 ring-primary shadow-md`:`hover:shadow-sm`}`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[v[e.type],(0,_.jsx)(`span`,{className:`font-medium text-sm`,children:e.label}),(0,_.jsxs)(`span`,{className:`text-xs text-muted-foreground capitalize`,children:[`(`,e.type,`)`]})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-1`,children:[s.edges.filter(t=>t.source===e.id).length>0&&(0,_.jsxs)(r.Badge,{variant:`outline`,className:`text-xs`,children:[s.edges.filter(t=>t.source===e.id).length,` out`]}),!a&&e.type!==`start`&&e.type!==`end`&&(0,_.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 text-red-500 hover:text-red-700`,onClick:t=>{t.stopPropagation(),g(e.id)},children:(0,_.jsx)(i.Trash2,{className:`h-3 w-3`})})]})]},e.id)),s.edges.length>0&&(0,_.jsxs)(`div`,{className:`mt-4 pt-4 border-t`,children:[(0,_.jsx)(r.Label,{className:`text-xs text-muted-foreground mb-2 block`,children:`Connections`}),s.edges.map(e=>{let t=s.nodes.find(t=>t.id===e.source),n=s.nodes.find(t=>t.id===e.target);return(0,_.jsxs)(`div`,{className:`flex items-center gap-2 p-2 text-sm`,children:[(0,_.jsx)(`span`,{children:t?.label||e.source}),(0,_.jsx)(i.ArrowRight,{className:`h-3 w-3 text-muted-foreground`}),(0,_.jsx)(`span`,{children:n?.label||e.target}),e.label&&(0,_.jsx)(r.Badge,{variant:`outline`,className:`text-xs`,children:e.label}),!a&&(0,_.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 ml-auto text-red-500`,onClick:()=>S(e.id),children:(0,_.jsx)(i.Trash2,{className:`h-3 w-3`})})]},e.id)})]}),!a&&s.nodes.length>=2&&(0,_.jsxs)(`div`,{className:`mt-4 pt-4 border-t`,children:[(0,_.jsx)(r.Label,{className:`text-xs text-muted-foreground mb-2 block`,children:`Quick Connect`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,_.jsxs)(`select`,{id:`edge-source`,className:`border rounded-md p-1.5 text-sm bg-background`,children:[(0,_.jsx)(`option`,{value:``,children:`From...`}),s.nodes.filter(e=>e.type!==`end`).map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,_.jsxs)(`select`,{id:`edge-target`,className:`border rounded-md p-1.5 text-sm bg-background`,children:[(0,_.jsx)(`option`,{value:``,children:`To...`}),s.nodes.filter(e=>e.type!==`start`).map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),(0,_.jsxs)(r.Button,{size:`sm`,variant:`outline`,className:`mt-2 w-full`,onClick:()=>{let e=document.getElementById(`edge-source`)?.value,t=document.getElementById(`edge-target`)?.value;e&&t&&e!==t&&x(e,t)},children:[(0,_.jsx)(i.Plus,{className:`h-3 w-3 mr-1`}),`Connect`]})]})]})})]}),(0,_.jsxs)(r.Card,{className:`lg:col-span-1`,children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsxs)(r.CardTitle,{className:`text-sm flex items-center gap-2`,children:[(0,_.jsx)(i.Settings,{className:`h-4 w-4`}),`Properties`]})}),(0,_.jsx)(r.CardContent,{children:p?(0,_.jsxs)(`div`,{className:`space-y-3`,children:[(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Label`}),(0,_.jsx)(r.Input,{value:p.label,onChange:e=>h(p.id,{label:e.target.value}),className:`h-8 text-sm`,readOnly:a})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Type`}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-muted text-sm`,children:[v[p.type],(0,_.jsx)(`span`,{className:`capitalize`,children:p.type})]})]}),p.description!==void 0&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Description`}),(0,_.jsx)(r.Input,{value:p.description||``,onChange:e=>h(p.id,{description:e.target.value}),className:`h-8 text-sm`,readOnly:a})]}),(p.type===`approval`||p.type===`task`)&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Assignee`}),(0,_.jsx)(r.Input,{value:p.assignee||``,onChange:e=>h(p.id,{assignee:e.target.value}),className:`h-8 text-sm`,placeholder:`User, role, or expression`,readOnly:a})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Assignee Type`}),(0,_.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2 bg-background`,value:p.assigneeType||`user`,onChange:e=>h(p.id,{assigneeType:e.target.value}),disabled:a,children:[(0,_.jsx)(`option`,{value:`user`,children:`User`}),(0,_.jsx)(`option`,{value:`role`,children:`Role`}),(0,_.jsx)(`option`,{value:`group`,children:`Group`}),(0,_.jsx)(`option`,{value:`expression`,children:`Expression`})]})]})]}),p.type===`delay`&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Timeout (minutes)`}),(0,_.jsx)(r.Input,{type:`number`,value:p.timeout||60,onChange:e=>h(p.id,{timeout:Number(e.target.value)}),className:`h-8 text-sm`,readOnly:a})]}),(0,_.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-2`,children:[`ID: `,p.id]})]}):(0,_.jsx)(`div`,{className:`text-sm text-muted-foreground text-center py-8`,children:`Select a node to edit its properties`})})]})]})]})},S=({schema:e})=>{let{currentNodeId:t,approvalRule:a,history:o=[],data:s,showHistory:c=!0,showComments:l=!0}=e,[u,d]=(0,n.useState)(``),[f,p]=(0,n.useState)(!1),m=e=>{p(!0),console.log(`Approval action: ${e}`,{currentNodeId:t,comment:u,data:s}),setTimeout(()=>{p(!1),d(``)},500)},h=e=>{switch(e){case`approve`:case`approved`:return(0,_.jsx)(r.Badge,{variant:`default`,className:`bg-green-500`,children:`Approved`});case`reject`:case`rejected`:return(0,_.jsx)(r.Badge,{variant:`destructive`,children:`Rejected`});case`reassign`:case`reassigned`:return(0,_.jsx)(r.Badge,{variant:`secondary`,children:`Reassigned`});case`comment`:return(0,_.jsx)(r.Badge,{variant:`outline`,children:`Comment`});case`escalate`:case`escalated`:return(0,_.jsx)(r.Badge,{variant:`secondary`,className:`bg-orange-500 text-white`,children:`Escalated`});default:return(0,_.jsx)(r.Badge,{variant:`outline`,children:e})}};return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(r.Card,{children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsxs)(r.CardTitle,{className:`flex items-center gap-2`,children:[(0,_.jsx)(i.Clock,{className:`h-5 w-5`}),`Pending Approval`,a&&(0,_.jsxs)(r.Badge,{variant:`outline`,className:`ml-2`,children:[a.type===`any`&&`Any approver`,a.type===`all`&&`All must approve`,a.type===`majority`&&`Majority approval`,a.type===`sequential`&&`Sequential`]})]})}),(0,_.jsxs)(r.CardContent,{className:`space-y-4`,children:[s&&Object.keys(s).length>0&&(0,_.jsxs)(`div`,{className:`p-3 bg-muted/50 rounded-lg`,children:[(0,_.jsx)(r.Label,{className:`text-xs text-muted-foreground mb-2 block`,children:`Request Details`}),(0,_.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:Object.entries(s).slice(0,6).map(([e,t])=>(0,_.jsxs)(`div`,{className:`text-sm`,children:[(0,_.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`: `]}),(0,_.jsx)(`span`,{className:`font-medium`,children:String(t)})]},e))})]}),l&&(0,_.jsxs)(`div`,{className:`space-y-2`,children:[(0,_.jsxs)(r.Label,{className:`flex items-center gap-2 text-sm`,children:[(0,_.jsx)(i.MessageSquare,{className:`h-4 w-4`}),`Comment`]}),(0,_.jsx)(r.Input,{value:u,onChange:e=>d(e.target.value),placeholder:`Add a comment (optional)`})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsxs)(r.Button,{onClick:()=>m(`approve`),disabled:f,className:`bg-green-600 hover:bg-green-700`,children:[(0,_.jsx)(i.Check,{className:`h-4 w-4 mr-2`}),`Approve`]}),(0,_.jsxs)(r.Button,{variant:`destructive`,onClick:()=>m(`reject`),disabled:f,children:[(0,_.jsx)(i.X,{className:`h-4 w-4 mr-2`}),`Reject`]}),(0,_.jsxs)(r.Button,{variant:`outline`,onClick:()=>m(`reassign`),disabled:f,children:[(0,_.jsx)(i.RefreshCw,{className:`h-4 w-4 mr-2`}),`Reassign`]})]})]})]}),c&&o.length>0&&(0,_.jsxs)(r.Card,{children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsx)(r.CardTitle,{className:`text-sm`,children:`Approval History`})}),(0,_.jsx)(r.CardContent,{children:(0,_.jsx)(`div`,{className:`space-y-3`,children:o.map((e,t)=>(0,_.jsxs)(`div`,{className:`flex items-start gap-3 p-3 rounded-lg border`,children:[(0,_.jsx)(`div`,{className:`mt-0.5`,children:(0,_.jsx)(i.User,{className:`h-4 w-4 text-muted-foreground`})}),(0,_.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,_.jsx)(`span`,{className:`font-medium text-sm`,children:e.actorName||e.actor}),h(e.action),(0,_.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.timestamp).toLocaleString()})]}),e.comment&&(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.comment})]})]},t))})})]}),c&&o.length===0&&(0,_.jsx)(r.Card,{children:(0,_.jsx)(r.CardContent,{className:`p-6 text-center text-muted-foreground text-sm`,children:`No approval history yet`})})]})},C={record_created:`Record Created`,record_updated:`Record Updated`,record_deleted:`Record Deleted`,field_changed:`Field Changed`,scheduled:`Scheduled`},w={send_email:`Send Email`,update_field:`Update Field`,create_record:`Create Record`,delete_record:`Delete Record`,webhook:`Webhook`,notification:`Notification`},T={send_email:(0,_.jsx)(i.Mail,{className:`h-4 w-4`}),update_field:(0,_.jsx)(i.FileEdit,{className:`h-4 w-4`}),create_record:(0,_.jsx)(i.Plus,{className:`h-4 w-4`}),delete_record:(0,_.jsx)(i.Trash2,{className:`h-4 w-4`}),webhook:(0,_.jsx)(i.Globe,{className:`h-4 w-4`}),notification:(0,_.jsx)(i.Bell,{className:`h-4 w-4`})},E={equals:`Equals`,not_equals:`Not Equals`,contains:`Contains`,greater_than:`Greater Than`,less_than:`Less Than`},D=()=>({id:`auto-${Date.now()}`,name:``,description:``,enabled:!0,trigger:{type:`record_created`},actions:[],createdAt:new Date().toISOString()}),O=({label:e,value:t,placeholder:n,onChange:i})=>(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:e}),(0,_.jsx)(r.Input,{value:t,onChange:e=>i(e.target.value),placeholder:n})]}),k=({automation:e,objects:t=[],onSave:a,onCancel:o,className:s})=>{let[c,l]=(0,n.useState)(e??D()),u=(0,n.useCallback)(e=>{l(t=>({...t,trigger:{...t.trigger,...e}}))},[]),d=(0,n.useCallback)(()=>{l(e=>({...e,actions:[...e.actions,{type:`send_email`,params:{}}]}))},[]),f=(0,n.useCallback)((e,t)=>{l(n=>({...n,actions:n.actions.map((n,r)=>r===e?{...n,...t}:n)}))},[]),p=(0,n.useCallback)(e=>{l(t=>({...t,actions:t.actions.filter((t,n)=>n!==e)}))},[]),m=c.trigger.type!==`scheduled`,h=c.trigger.type===`field_changed`,g=c.trigger.type===`scheduled`,v=t.find(e=>e.name===c.trigger.objectName)?.fields,y=(e,t)=>{let n=(n,r)=>f(t,{params:{...e.params,[n]:r}});switch(e.type){case`send_email`:return(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(O,{label:`To`,value:e.params.to??``,placeholder:`Recipient email`,onChange:e=>n(`to`,e)}),(0,_.jsx)(O,{label:`Subject`,value:e.params.subject??``,placeholder:`Email subject`,onChange:e=>n(`subject`,e)})]});case`webhook`:return(0,_.jsx)(O,{label:`URL`,value:e.params.url??``,placeholder:`https://...`,onChange:e=>n(`url`,e)});case`notification`:return(0,_.jsx)(O,{label:`Message`,value:e.params.message??``,placeholder:`Notification message`,onChange:e=>n(`message`,e)});case`update_field`:case`create_record`:case`delete_record`:return(0,_.jsx)(O,{label:`Target Object`,value:e.params.objectName??``,placeholder:`Object name`,onChange:e=>n(`objectName`,e)});default:return null}};return(0,_.jsxs)(`div`,{className:s??`space-y-4`,children:[(0,_.jsxs)(r.Card,{children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-sm`,children:[(0,_.jsx)(i.Zap,{className:`h-4 w-4 text-yellow-500`}),`Trigger`]})}),(0,_.jsxs)(r.CardContent,{className:`space-y-4`,children:[(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Trigger Type`}),(0,_.jsxs)(r.Select,{value:c.trigger.type,onValueChange:e=>u({type:e}),children:[(0,_.jsx)(r.SelectTrigger,{children:(0,_.jsx)(r.SelectValue,{placeholder:`Select trigger type`})}),(0,_.jsx)(r.SelectContent,{children:Object.keys(C).map(e=>(0,_.jsx)(r.SelectItem,{value:e,children:C[e]},e))})]})]}),m&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Object`}),t.length>0?(0,_.jsxs)(r.Select,{value:c.trigger.objectName??``,onValueChange:e=>u({objectName:e}),children:[(0,_.jsx)(r.SelectTrigger,{children:(0,_.jsx)(r.SelectValue,{placeholder:`Select object`})}),(0,_.jsx)(r.SelectContent,{children:t.map(e=>(0,_.jsx)(r.SelectItem,{value:e.name,children:e.label},e.name))})]}):(0,_.jsx)(r.Input,{value:c.trigger.objectName??``,onChange:e=>u({objectName:e.target.value}),placeholder:`Object name`})]}),h&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Field`}),v?(0,_.jsxs)(r.Select,{value:c.trigger.fieldName??``,onValueChange:e=>u({fieldName:e}),children:[(0,_.jsx)(r.SelectTrigger,{children:(0,_.jsx)(r.SelectValue,{placeholder:`Select field`})}),(0,_.jsx)(r.SelectContent,{children:Object.keys(v).map(e=>(0,_.jsx)(r.SelectItem,{value:e,children:e},e))})]}):(0,_.jsx)(r.Input,{value:c.trigger.fieldName??``,onChange:e=>u({fieldName:e.target.value}),placeholder:`Field name`})]}),g&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsxs)(r.Label,{className:`text-xs flex items-center gap-1`,children:[(0,_.jsx)(i.Clock,{className:`h-3 w-3`}),` Cron Schedule`]}),(0,_.jsx)(r.Input,{value:c.trigger.schedule??``,onChange:e=>u({schedule:e.target.value}),placeholder:`e.g. 0 9 * * 1-5`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Condition (optional)`}),(0,_.jsx)(r.Input,{value:c.trigger.condition??``,onChange:e=>u({condition:e.target.value}),placeholder:'e.g. ${data.status === "active"}'})]}),(0,_.jsx)(r.Separator,{}),(0,_.jsxs)(`div`,{className:`space-y-3`,children:[(0,_.jsx)(r.Label,{className:`text-xs font-medium`,children:`Conditional Trigger (optional)`}),(0,_.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Run only when a field matches a specific value.`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Field`}),v?(0,_.jsxs)(r.Select,{value:c.trigger.conditionField??``,onValueChange:e=>u({conditionField:e}),children:[(0,_.jsx)(r.SelectTrigger,{children:(0,_.jsx)(r.SelectValue,{placeholder:`Field`})}),(0,_.jsx)(r.SelectContent,{children:Object.keys(v).map(e=>(0,_.jsx)(r.SelectItem,{value:e,children:e},e))})]}):(0,_.jsx)(r.Input,{value:c.trigger.conditionField??``,onChange:e=>u({conditionField:e.target.value}),placeholder:`e.g. status`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Operator`}),(0,_.jsxs)(r.Select,{value:c.trigger.conditionOperator??`equals`,onValueChange:e=>u({conditionOperator:e}),children:[(0,_.jsx)(r.SelectTrigger,{children:(0,_.jsx)(r.SelectValue,{placeholder:`Operator`})}),(0,_.jsx)(r.SelectContent,{children:Object.keys(E).map(e=>(0,_.jsx)(r.SelectItem,{value:e,children:E[e]},e))})]})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Value`}),(0,_.jsx)(r.Input,{value:c.trigger.conditionValue??``,onChange:e=>u({conditionValue:e.target.value}),placeholder:`e.g. urgent`})]})]})]})]})]}),(0,_.jsxs)(r.Card,{children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-sm`,children:[(0,_.jsx)(i.Settings,{className:`h-4 w-4`}),` Actions`,(0,_.jsx)(r.Badge,{variant:`secondary`,className:`ml-auto`,children:c.actions.length})]})}),(0,_.jsxs)(r.CardContent,{className:`space-y-3`,children:[c.actions.length>1&&(0,_.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Execution`}),(0,_.jsxs)(r.Select,{value:c.executionMode??`sequential`,onValueChange:e=>l(t=>({...t,executionMode:e})),children:[(0,_.jsx)(r.SelectTrigger,{className:`h-7 w-36`,children:(0,_.jsx)(r.SelectValue,{})}),(0,_.jsxs)(r.SelectContent,{children:[(0,_.jsx)(r.SelectItem,{value:`sequential`,children:`Sequential`}),(0,_.jsx)(r.SelectItem,{value:`parallel`,children:`Parallel`})]})]})]}),c.actions.map((e,t)=>(0,_.jsxs)(`div`,{className:`rounded-lg border p-3 space-y-3`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[T[e.type],(0,_.jsx)(`span`,{className:`text-sm font-medium`,children:c.actions.length>1&&(c.executionMode??`sequential`)===`sequential`?`Step ${t+1}`:`Action ${t+1}`}),t>0&&c.actions.length>1&&(c.executionMode??`sequential`)===`sequential`&&(0,_.jsx)(r.Badge,{variant:`outline`,className:`text-[10px] px-1`,children:`then`})]}),(0,_.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 text-red-500 hover:text-red-700`,onClick:()=>p(t),children:(0,_.jsx)(i.Trash2,{className:`h-4 w-4`})})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Action Type`}),(0,_.jsxs)(r.Select,{value:e.type,onValueChange:e=>f(t,{type:e,params:{}}),children:[(0,_.jsx)(r.SelectTrigger,{children:(0,_.jsx)(r.SelectValue,{})}),(0,_.jsx)(r.SelectContent,{children:Object.keys(w).map(e=>(0,_.jsx)(r.SelectItem,{value:e,children:w[e]},e))})]})]}),y(e,t)]},t)),(0,_.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`w-full`,onClick:d,children:[(0,_.jsx)(i.Plus,{className:`h-4 w-4 mr-2`}),` Add Action`]})]})]}),(0,_.jsxs)(r.Card,{children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsx)(r.CardTitle,{className:`text-sm`,children:`Summary`})}),(0,_.jsxs)(r.CardContent,{className:`space-y-4`,children:[(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Name`}),(0,_.jsx)(r.Input,{value:c.name,onChange:e=>l(t=>({...t,name:e.target.value})),placeholder:`Automation name`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Description`}),(0,_.jsx)(r.Input,{value:c.description??``,onChange:e=>l(t=>({...t,description:e.target.value})),placeholder:`Optional description`})]}),(0,_.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,_.jsx)(r.Label,{className:`text-sm`,children:`Enabled`}),(0,_.jsx)(r.Switch,{checked:c.enabled,onCheckedChange:e=>l(t=>({...t,enabled:e}))})]}),(0,_.jsx)(r.Separator,{}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[o&&(0,_.jsx)(r.Button,{variant:`outline`,size:`sm`,onClick:o,children:`Cancel`}),(0,_.jsxs)(r.Button,{size:`sm`,onClick:()=>a?.(c),children:[(0,_.jsx)(i.Zap,{className:`h-4 w-4 mr-2`}),` Save Automation`]})]})]})]})]})},A={success:`default`,failure:`destructive`,running:`secondary`,pending:`outline`},j={success:`Success`,failure:`Failed`,running:`Running`,pending:`Pending`};function M(e,t){if(!t)return`—`;let n=new Date(t).getTime()-new Date(e).getTime();if(n<1e3)return`${n}ms`;let r=Math.floor(n/1e3);return r<60?`${r}s`:`${Math.floor(r/60)}m ${r%60}s`}var N=({runs:e=[],className:t})=>(0,_.jsxs)(r.Card,{className:t,children:[(0,_.jsx)(r.CardHeader,{children:(0,_.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-sm`,children:[(0,_.jsx)(i.Clock,{className:`h-4 w-4`}),`Automation Run History`,(0,_.jsx)(r.Badge,{variant:`outline`,className:`ml-auto`,children:e.length})]})}),(0,_.jsx)(r.CardContent,{children:e.length===0?(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-6`,children:`No automation runs yet`}):(0,_.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,_.jsxs)(`div`,{className:`flex items-start gap-3 rounded-lg border p-3`,children:[(0,_.jsx)(r.Badge,{variant:A[e.status],children:j[e.status]}),(0,_.jsxs)(`div`,{className:`flex-1 min-w-0 space-y-1`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,_.jsx)(`span`,{className:`text-sm font-medium`,children:e.automationName}),e.triggerEvent&&(0,_.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`— `,e.triggerEvent]})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground`,children:[(0,_.jsx)(`span`,{children:new Date(e.startedAt).toLocaleString()}),(0,_.jsxs)(`span`,{children:[`Duration: `,M(e.startedAt,e.completedAt)]})]}),e.status===`failure`&&e.error&&(0,_.jsx)(`p`,{className:`text-xs text-red-600 mt-1`,children:e.error})]})]},e.id))})})]});function P(...e){return(0,o.twMerge)((0,a.clsx)(e))}var F=130,I=52,L={start:`Start`,end:`End`,task:`Task`,user_task:`User Task`,service_task:`Service Task`,script_task:`Script Task`,approval:`Approval`,condition:`Condition`,parallel_gateway:`Parallel Gateway`,join_gateway:`Join Gateway`,boundary_event:`Boundary Event`,delay:`Delay`,notification:`Notification`,webhook:`Webhook`},R={start:(0,_.jsx)(i.Play,{className:`h-3.5 w-3.5 text-green-500`}),end:(0,_.jsx)(i.Square,{className:`h-3.5 w-3.5 text-red-500`}),task:(0,_.jsx)(i.CheckCircle,{className:`h-3.5 w-3.5 text-blue-500`}),user_task:(0,_.jsx)(i.Users,{className:`h-3.5 w-3.5 text-blue-600`}),service_task:(0,_.jsx)(i.Settings,{className:`h-3.5 w-3.5 text-blue-400`}),script_task:(0,_.jsx)(i.Code,{className:`h-3.5 w-3.5 text-indigo-500`}),approval:(0,_.jsx)(i.Users,{className:`h-3.5 w-3.5 text-purple-500`}),condition:(0,_.jsx)(i.GitBranch,{className:`h-3.5 w-3.5 text-orange-500`}),parallel_gateway:(0,_.jsx)(i.GitBranch,{className:`h-3.5 w-3.5 text-teal-500`}),join_gateway:(0,_.jsx)(i.GitMerge,{className:`h-3.5 w-3.5 text-teal-600`}),boundary_event:(0,_.jsx)(i.AlertCircle,{className:`h-3.5 w-3.5 text-amber-500`}),delay:(0,_.jsx)(i.Clock,{className:`h-3.5 w-3.5 text-gray-500`}),notification:(0,_.jsx)(i.Bell,{className:`h-3.5 w-3.5 text-yellow-500`}),webhook:(0,_.jsx)(i.Globe,{className:`h-3.5 w-3.5 text-cyan-500`})},z={start:`border-green-400 bg-green-50 dark:bg-green-950`,end:`border-red-400 bg-red-50 dark:bg-red-950`,task:`border-blue-300 bg-blue-50 dark:bg-blue-950`,user_task:`border-blue-400 bg-blue-50 dark:bg-blue-950`,service_task:`border-blue-200 bg-slate-50 dark:bg-slate-900`,script_task:`border-indigo-300 bg-indigo-50 dark:bg-indigo-950`,approval:`border-purple-400 bg-purple-50 dark:bg-purple-950`,condition:`border-orange-400 bg-orange-50 dark:bg-orange-950`,parallel_gateway:`border-teal-400 bg-teal-50 dark:bg-teal-950`,join_gateway:`border-teal-500 bg-teal-50 dark:bg-teal-950`,boundary_event:`border-amber-400 bg-amber-50 dark:bg-amber-950 border-dashed`,delay:`border-gray-400 bg-gray-50 dark:bg-gray-900`,notification:`border-yellow-400 bg-yellow-50 dark:bg-yellow-950`,webhook:`border-cyan-400 bg-cyan-50 dark:bg-cyan-950`},B={pending:{color:`text-muted-foreground`,icon:(0,_.jsx)(i.Clock,{className:`h-3 w-3`})},running:{color:`text-blue-500`,icon:(0,_.jsx)(i.Loader2,{className:`h-3 w-3 animate-spin`})},completed:{color:`text-green-500`,icon:(0,_.jsx)(i.CheckCircle,{className:`h-3 w-3`})},failed:{color:`text-red-500`,icon:(0,_.jsx)(i.AlertCircle,{className:`h-3 w-3`})},skipped:{color:`text-gray-400`,icon:(0,_.jsx)(i.SkipForward,{className:`h-3 w-3`})}},ee=[`task`,`user_task`,`service_task`,`script_task`,`approval`,`condition`,`parallel_gateway`,`join_gateway`,`boundary_event`,`delay`,`notification`,`webhook`],te={allow:`Allow (run concurrently)`,forbid:`Forbid (skip new)`,replace:`Replace (cancel existing)`,queue:`Queue (run after current)`},V={condition:`Condition`,manual:`Manual`,webhook:`Webhook`,timer:`Timer`,signal:`Signal`},H=()=>[{id:`start-1`,type:`start`,label:`Start`,position:{x:80,y:200}},{id:`end-1`,type:`end`,label:`End`,position:{x:500,y:200}}],ne=()=>[];function re(e){let[t,r]=(0,n.useState)([e]),[i,a]=(0,n.useState)(0);return{current:t[i],push:(0,n.useCallback)(e=>{r(t=>[...t.slice(0,i+1),e]),a(e=>e+1)},[i]),undo:(0,n.useCallback)(()=>{a(e=>Math.max(0,e-1))},[]),redo:(0,n.useCallback)(()=>{r(e=>(a(t=>Math.min(e.length-1,t+1)),e))},[]),canUndo:i>0,canRedo:i<t.length-1}}function ie(e,t,n){let r=[],i=[`boundary_event`];e.forEach(e=>{i.includes(e.type)&&r.push(`Node "${e.label}" (${e.type}) has limited BPMN mapping.`)});let a=[`<?xml version="1.0" encoding="UTF-8"?>`,`<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"`,` xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"`,` targetNamespace="http://objectui.org/bpmn">`,` <process id="process-1" name="${n}" isExecutable="true">`,...e.map(e=>` <${U(e.type)} id="${e.id}" name="${e.label}" />`),...t.map(e=>` <sequenceFlow ${[`id="${e.id}"`,`sourceRef="${e.source}"`,`targetRef="${e.target}"`,e.condition?`conditionExpression="${e.condition}"`:``].filter(Boolean).join(` `)} />`),` </process>`,`</definitions>`].join(`
|
|
7
|
+
`);return{success:!0,nodeCount:e.length,edgeCount:t.length,warnings:r.length?r:void 0,bpmnXml:a}}function U(e){return{start:`startEvent`,end:`endEvent`,task:`task`,user_task:`userTask`,service_task:`serviceTask`,script_task:`scriptTask`,approval:`userTask`,condition:`exclusiveGateway`,parallel_gateway:`parallelGateway`,join_gateway:`parallelGateway`,boundary_event:`boundaryEvent`,delay:`intermediateCatchEvent`,notification:`sendTask`,webhook:`serviceTask`}[e]??`task`}function ae(e,t){let n=e.position.x+F,r=e.position.y+I/2,i=t.position.x,a=t.position.y+I/2,o=(n+i)/2;return{d:`M ${n} ${r} C ${o} ${r}, ${o} ${a}, ${i} ${a}`,labelX:o,labelY:(r+a)/2-8}}var oe=({node:e,isSelected:t,isConnectSource:n,connectMode:r,readOnly:a,showExecutionOverlay:o,onSelect:s,onDelete:c,onDragStart:l,onPortClick:u})=>{let d=e.executionStatus,f=d?B[d]:null;return(0,_.jsxs)(`div`,{className:`absolute select-none`,style:{left:e.position.x,top:e.position.y},draggable:!a&&!r,onDragStart:t=>l(t,e.id),onClick:t=>s(e.id,t.shiftKey),role:`group`,"aria-label":e.label,children:[(0,_.jsxs)(`div`,{className:P(`flex items-center gap-2 border-2 rounded px-3 py-2 min-h-[52px] transition-shadow cursor-pointer`,z[e.type],t&&`ring-2 ring-primary shadow-md`,n&&`ring-2 ring-blue-400 shadow-lg`,r&&!n&&`cursor-crosshair`,o&&d===`running`&&`ring-2 ring-blue-400`,o&&d===`failed`&&`ring-2 ring-red-400`,o&&d===`completed`&&`ring-2 ring-green-400`),style:{width:F,minHeight:I},children:[(0,_.jsx)(`span`,{className:`shrink-0`,children:R[e.type]}),(0,_.jsx)(`span`,{className:`text-xs font-medium leading-tight flex-1 truncate`,children:e.label}),o&&f&&(0,_.jsx)(`span`,{className:P(`shrink-0`,f.color),children:f.icon})]}),!a&&(t||r)&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-primary border-2 border-background shadow cursor-crosshair`,style:{right:-6,top:I/2-6},title:`Connect from this node`,onClick:t=>{t.stopPropagation(),u(e.id)}}),(0,_.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-muted-foreground border-2 border-background shadow cursor-crosshair`,style:{left:-6,top:I/2-6},title:`Connect to this node`,onClick:t=>{t.stopPropagation(),u(e.id)}})]}),!a&&t&&!r&&(0,_.jsx)(`button`,{className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,onClick:t=>{t.stopPropagation(),c(e.id)},"aria-label":`Delete node ${e.label}`,children:(0,_.jsx)(i.Trash2,{className:`h-3 w-3`})})]})},se=({node:e,edge:t,readOnly:n,onNodeChange:i,onEdgeChange:a})=>!e&&!t?(0,_.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Select a node or edge to edit its properties.`}):e?(0,_.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto`,children:[(0,_.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:`Node Properties`}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Label`}),(0,_.jsx)(r.Input,{value:e.label,onChange:t=>i({...e,label:t.target.value}),disabled:n,className:`h-7 text-xs`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Type`}),(0,_.jsxs)(r.Select,{value:e.type,onValueChange:t=>i({...e,type:t}),disabled:n,children:[(0,_.jsx)(r.SelectTrigger,{className:`h-7 text-xs`,children:(0,_.jsx)(r.SelectValue,{})}),(0,_.jsx)(r.SelectContent,{children:Object.keys(L).map(e=>(0,_.jsx)(r.SelectItem,{value:e,className:`text-xs`,children:L[e]},e))})]})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Description`}),(0,_.jsx)(r.Input,{value:e.description??``,onChange:t=>i({...e,description:t.target.value}),disabled:n,className:`h-7 text-xs`,placeholder:`Optional description`})]}),[`task`,`user_task`,`service_task`,`script_task`,`delay`,`webhook`].includes(e.type)&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r.Separator,{}),(0,_.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:`Executor`}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Executor Type`}),(0,_.jsx)(r.Input,{value:e.executor?.type??``,onChange:t=>i({...e,executor:{...e.executor,type:t.target.value}}),disabled:n,className:`h-7 text-xs`,placeholder:`e.g. http, script, email`})]}),e.type===`delay`&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Wait Event Type`}),(0,_.jsxs)(r.Select,{value:e.executor?.waitEventConfig?.eventType??`timer`,onValueChange:t=>i({...e,executor:{...e.executor,type:e.executor?.type??`wait`,waitEventConfig:{...e.executor?.waitEventConfig,eventType:t}}}),disabled:n,children:[(0,_.jsx)(r.SelectTrigger,{className:`h-7 text-xs`,children:(0,_.jsx)(r.SelectValue,{})}),(0,_.jsx)(r.SelectContent,{children:Object.keys(V).map(e=>(0,_.jsx)(r.SelectItem,{value:e,className:`text-xs`,children:V[e]},e))})]})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Timeout (ms)`}),(0,_.jsx)(r.Input,{type:`number`,value:e.executor?.timeoutMs??``,onChange:t=>i({...e,executor:{...e.executor,type:e.executor?.type??``,timeoutMs:t.target.value?Number(t.target.value):void 0}}),disabled:n,className:`h-7 text-xs`,placeholder:`e.g. 30000`})]})]}),e.type===`boundary_event`&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r.Separator,{}),(0,_.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:`Boundary Config`}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Attached To Node ID`}),(0,_.jsx)(r.Input,{value:e.boundaryConfig?.attachedToNodeId??``,onChange:t=>i({...e,boundaryConfig:{...e.boundaryConfig,attachedToNodeId:t.target.value,eventType:e.boundaryConfig?.eventType??`error`}}),disabled:n,className:`h-7 text-xs`,placeholder:`Host node id`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Event Type`}),(0,_.jsxs)(r.Select,{value:e.boundaryConfig?.eventType??`error`,onValueChange:t=>i({...e,boundaryConfig:{...e.boundaryConfig,attachedToNodeId:e.boundaryConfig?.attachedToNodeId??``,eventType:t}}),disabled:n,children:[(0,_.jsx)(r.SelectTrigger,{className:`h-7 text-xs`,children:(0,_.jsx)(r.SelectValue,{})}),(0,_.jsx)(r.SelectContent,{children:[`error`,`timer`,`message`,`signal`,`compensation`].map(e=>(0,_.jsx)(r.SelectItem,{value:e,className:`text-xs capitalize`,children:e},e))})]})]})]})]}):t?(0,_.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto`,children:[(0,_.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:`Edge Properties`}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Label`}),(0,_.jsx)(r.Input,{value:t.label??``,onChange:e=>a({...t,label:e.target.value}),disabled:n,className:`h-7 text-xs`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Type`}),(0,_.jsxs)(r.Select,{value:t.type??`default`,onValueChange:e=>a({...t,type:e}),disabled:n,children:[(0,_.jsx)(r.SelectTrigger,{className:`h-7 text-xs`,children:(0,_.jsx)(r.SelectValue,{})}),(0,_.jsxs)(r.SelectContent,{children:[(0,_.jsx)(r.SelectItem,{value:`default`,className:`text-xs`,children:`Default`}),(0,_.jsx)(r.SelectItem,{value:`conditional`,className:`text-xs`,children:`Conditional`}),(0,_.jsx)(r.SelectItem,{value:`timeout`,className:`text-xs`,children:`Timeout`})]})]})]}),t.type===`conditional`&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(r.Label,{className:`text-xs`,children:`Condition Expression`}),(0,_.jsx)(r.Input,{value:t.condition??``,onChange:e=>a({...t,condition:e.target.value}),disabled:n,className:`h-7 text-xs font-mono`,placeholder:`e.g. status === 'approved'`})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(`input`,{type:`checkbox`,id:`edge-isDefault`,checked:t.isDefault??!1,onChange:e=>a({...t,isDefault:e.target.checked}),disabled:n,className:`h-3.5 w-3.5`}),(0,_.jsx)(r.Label,{htmlFor:`edge-isDefault`,className:`text-xs`,children:`Default edge (isDefault)`})]})]}):null,ce=({versions:e})=>(0,_.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,_.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wide`,children:`Version History`}),e.length===0&&(0,_.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No version history available.`}),(0,_.jsx)(`div`,{className:`space-y-1.5`,children:e.map(e=>(0,_.jsxs)(`div`,{className:P(`rounded border p-2 text-xs`,e.isCurrent?`border-primary bg-primary/5`:`border-border bg-muted/30`),children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,_.jsxs)(`span`,{className:`font-medium`,children:[`v`,e.version]}),e.isCurrent&&(0,_.jsx)(r.Badge,{variant:`default`,className:`text-[10px] h-4`,children:`Current`})]}),e.changeNote&&(0,_.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:e.changeNote}),(0,_.jsxs)(`p`,{className:`text-muted-foreground mt-0.5`,children:[e.author&&(0,_.jsxs)(_.Fragment,{children:[e.author,` · `]}),new Date(e.createdAt).toLocaleDateString()]})]},e.version))})]}),W=({schema:e,onSave:t})=>{let{readOnly:a=!1,showToolbar:o=!0,showMinimap:s=!1,showVersionHistory:c=!1,showExecutionOverlay:l=!1,executionSteps:u=[],versionHistory:d=[],concurrencyPolicy:f,title:p=`New Flow`,description:m=``,status:h=`draft`}=e,[g,v]=(0,n.useState)(p),[y,b]=(0,n.useState)(m),{current:x,push:S,undo:C,redo:w,canUndo:T,canRedo:E}=re({nodes:e.nodes??H(),edges:e.edges??ne()}),D=x.nodes,O=x.edges,[k,A]=(0,n.useState)(null),[j,M]=(0,n.useState)(null),[N,P]=(0,n.useState)(!1),[F,I]=(0,n.useState)(null),[z,B]=(0,n.useState)(!0),[V,U]=(0,n.useState)(c),[W,le]=(0,n.useState)(null),[G,K]=(0,n.useState)(1),q=(0,n.useRef)(null),ue=(0,n.useMemo)(()=>D.find(e=>e.id===k)??null,[D,k]),de=(0,n.useMemo)(()=>O.find(e=>e.id===j)??null,[O,j]),J=(0,n.useMemo)(()=>{if(!l||u.length===0)return D;let e=new Map(u.map(e=>[e.nodeId,e.status]));return D.map(t=>e.has(t.id)?{...t,executionStatus:e.get(t.id)}:t)},[D,l,u]),fe=(0,n.useCallback)(e=>{if(a)return;let t={id:`${e}-${Date.now()}`,type:e,label:L[e],position:{x:200,y:80+D.length*70}};S({nodes:[...D,t],edges:O})},[a,D,O,S]),Y=(0,n.useCallback)(e=>{a||(S({nodes:D.filter(t=>t.id!==e),edges:O.filter(t=>t.source!==e&&t.target!==e)}),k===e&&A(null))},[a,D,O,S,k]),pe=(0,n.useCallback)(e=>{a||S({nodes:D.map(t=>t.id===e.id?e:t),edges:O})},[a,D,O,S]),X=(0,n.useCallback)(e=>{a||(S({nodes:D,edges:O.filter(t=>t.id!==e)}),j===e&&M(null))},[a,D,O,S,j]),me=(0,n.useCallback)(e=>{a||S({nodes:D,edges:O.map(t=>t.id===e.id?e:t)})},[a,D,O,S]),he=(0,n.useCallback)(e=>{if(!a){if(!N){P(!0),I(e);return}if(F&&F!==e){let t={id:`edge-${Date.now()}`,source:F,target:e};S({nodes:D,edges:[...O,t]})}P(!1),I(null)}},[a,N,F,D,O,S]),Z=(0,n.useRef)(null),Q=(0,n.useRef)(null),ge=(0,n.useCallback)((e,t)=>{Z.current=t;let n=D.find(e=>e.id===t);n&&(Q.current={mouseX:e.clientX,mouseY:e.clientY,nodeX:n.position.x,nodeY:n.position.y}),e.dataTransfer.effectAllowed=`move`},[D]),_e=(0,n.useCallback)(e=>{if(e.preventDefault(),!Z.current||!Q.current||!q.current)return;q.current.getBoundingClientRect();let t=(e.clientX-Q.current.mouseX)/G,n=(e.clientY-Q.current.mouseY)/G,r=Math.max(0,Q.current.nodeX+t),i=Math.max(0,Q.current.nodeY+n),a=Z.current;S({nodes:D.map(e=>e.id===a?{...e,position:{x:r,y:i}}:e),edges:O}),Z.current=null,Q.current=null},[D,O,S,G]),ve=(0,n.useCallback)(()=>{let e=ie(D,O,g);le(e);let t=new Blob([e.bpmnXml??``],{type:`application/xml`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${g.replace(/\s+/g,`-`).toLowerCase()}.bpmn`,r.click(),URL.revokeObjectURL(n)},[D,O,g]),$=(0,n.useCallback)(()=>{t?.(D,O)},[D,O,t]);return(0,_.jsxs)(r.Card,{className:`flex flex-col h-full min-h-[600px] outline-none`,tabIndex:0,onKeyDown:(0,n.useCallback)(e=>{let t=e.ctrlKey||e.metaKey;if(t&&e.key===`z`&&!e.shiftKey){e.preventDefault(),C();return}if(t&&(e.key===`y`||e.key===`z`&&e.shiftKey)){e.preventDefault(),w();return}if(t&&e.key===`s`){e.preventDefault(),$();return}e.key===`Escape`&&(P(!1),I(null),A(null),M(null)),(e.key===`Delete`||e.key===`Backspace`)&&(k?Y(k):j&&X(j))},[C,w,$,k,j,Y,X]),children:[(0,_.jsx)(r.CardHeader,{className:`py-2 px-4 border-b flex-shrink-0`,children:(0,_.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,_.jsx)(i.Zap,{className:`h-4 w-4 text-primary shrink-0`}),(0,_.jsx)(r.CardTitle,{className:`text-sm font-semibold`,children:a?(0,_.jsx)(`span`,{children:g}):(0,_.jsx)(r.Input,{value:g,onChange:e=>v(e.target.value),className:`h-6 text-sm font-semibold border-0 p-0 focus-visible:ring-0 bg-transparent`,"aria-label":`Flow title`})}),(0,_.jsx)(r.Badge,{variant:`outline`,className:`text-xs capitalize`,children:h}),f&&(0,_.jsx)(r.Badge,{variant:`secondary`,className:`text-xs`,children:te[f]}),(0,_.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[!a&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r.Button,{size:`icon`,variant:`ghost`,className:`h-7 w-7`,onClick:C,disabled:!T,title:`Undo (Ctrl+Z)`,children:(0,_.jsx)(i.Undo2,{className:`h-4 w-4`})}),(0,_.jsx)(r.Button,{size:`icon`,variant:`ghost`,className:`h-7 w-7`,onClick:w,disabled:!E,title:`Redo (Ctrl+Y)`,children:(0,_.jsx)(i.Redo2,{className:`h-4 w-4`})}),(0,_.jsx)(r.Separator,{orientation:`vertical`,className:`h-5 mx-1`})]}),(0,_.jsx)(r.Button,{size:`icon`,variant:`ghost`,className:`h-7 w-7`,onClick:()=>K(e=>Math.min(2,e+.1)),title:`Zoom in`,children:(0,_.jsx)(i.ZoomIn,{className:`h-4 w-4`})}),(0,_.jsx)(r.Button,{size:`icon`,variant:`ghost`,className:`h-7 w-7`,onClick:()=>K(1),title:`Reset zoom`,children:(0,_.jsx)(i.RotateCcw,{className:`h-4 w-4`})}),(0,_.jsx)(r.Button,{size:`icon`,variant:`ghost`,className:`h-7 w-7`,onClick:()=>K(e=>Math.max(.3,e-.1)),title:`Zoom out`,children:(0,_.jsx)(i.ZoomOut,{className:`h-4 w-4`})}),(0,_.jsx)(r.Separator,{orientation:`vertical`,className:`h-5 mx-1`}),d.length>0&&(0,_.jsx)(r.Button,{size:`icon`,variant:V?`secondary`:`ghost`,className:`h-7 w-7`,onClick:()=>U(e=>!e),title:`Version history`,children:(0,_.jsx)(i.History,{className:`h-4 w-4`})}),(0,_.jsx)(r.Button,{size:`icon`,variant:`ghost`,className:`h-7 w-7`,onClick:ve,title:`Export BPMN`,children:(0,_.jsx)(i.Download,{className:`h-4 w-4`})}),!a&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r.Button,{size:`icon`,variant:`ghost`,className:`h-7 w-7`,title:`Import BPMN (drag & drop)`,children:(0,_.jsx)(i.Upload,{className:`h-4 w-4`})}),(0,_.jsxs)(r.Button,{size:`sm`,variant:`default`,className:`h-7 text-xs gap-1`,onClick:$,title:`Save (Ctrl+S)`,children:[(0,_.jsx)(i.Save,{className:`h-3.5 w-3.5`}),` Save`]})]}),(0,_.jsx)(r.Button,{size:`icon`,variant:`ghost`,className:`h-7 w-7`,onClick:()=>B(e=>!e),title:z?`Hide properties`:`Show properties`,children:z?(0,_.jsx)(i.PanelRightClose,{className:`h-4 w-4`}):(0,_.jsx)(i.PanelRightOpen,{className:`h-4 w-4`})})]})]})}),(0,_.jsxs)(r.CardContent,{className:`flex flex-1 p-0 overflow-hidden`,children:[o&&!a&&(0,_.jsxs)(`div`,{className:`w-36 border-r bg-muted/30 flex-shrink-0 overflow-y-auto py-2 px-2`,children:[(0,_.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-2 px-1`,children:`Add Node`}),(0,_.jsx)(`div`,{className:`space-y-1`,children:ee.map(e=>(0,_.jsxs)(`button`,{className:`w-full flex items-center gap-2 text-xs px-2 py-1.5 rounded hover:bg-muted transition-colors text-left`,onClick:()=>fe(e),title:`Add ${L[e]}`,children:[R[e],(0,_.jsx)(`span`,{className:`truncate`,children:L[e]})]},e))}),N&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r.Separator,{className:`my-2`}),(0,_.jsxs)(`div`,{className:`px-1`,children:[(0,_.jsx)(`p`,{className:`text-[10px] text-blue-600 font-medium`,children:`Connect mode`}),(0,_.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Click a target node port to connect.`}),(0,_.jsx)(r.Button,{size:`sm`,variant:`outline`,className:`h-6 text-xs mt-1 w-full`,onClick:()=>{P(!1),I(null)},children:`Cancel`})]})]})]}),(0,_.jsx)(`div`,{className:`flex-1 overflow-auto relative bg-dot-pattern`,children:(0,_.jsxs)(`div`,{ref:q,className:`relative`,style:{width:1200,height:700,transform:`scale(${G})`,transformOrigin:`top left`},onDrop:_e,onDragOver:e=>e.preventDefault(),onClick:e=>{e.target===q.current&&(A(null),M(null))},children:[(0,_.jsxs)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:1200,height:700,style:{overflow:`visible`},children:[(0,_.jsxs)(`defs`,{children:[(0,_.jsx)(`marker`,{id:`fd-arrowhead`,markerWidth:`10`,markerHeight:`7`,refX:`9`,refY:`3.5`,orient:`auto`,children:(0,_.jsx)(`polygon`,{points:`0 0, 10 3.5, 0 7`,fill:`hsl(var(--foreground) / 0.5)`})}),(0,_.jsx)(`marker`,{id:`fd-arrowhead-selected`,markerWidth:`10`,markerHeight:`7`,refX:`9`,refY:`3.5`,orient:`auto`,children:(0,_.jsx)(`polygon`,{points:`0 0, 10 3.5, 0 7`,fill:`hsl(var(--primary))`})}),(0,_.jsx)(`marker`,{id:`fd-arrowhead-conditional`,markerWidth:`10`,markerHeight:`7`,refX:`9`,refY:`3.5`,orient:`auto`,children:(0,_.jsx)(`polygon`,{points:`0 0, 10 3.5, 0 7`,fill:`hsl(var(--foreground) / 0.6)`})})]}),O.map(e=>{let t=J.find(t=>t.id===e.source),n=J.find(t=>t.id===e.target);if(!t||!n)return null;let{d:r,labelX:i,labelY:a}=ae(t,n),o=e.id===j,s=e.type===`conditional`,c=e.isDefault;return(0,_.jsxs)(`g`,{className:`pointer-events-auto cursor-pointer`,onClick:t=>{t.stopPropagation(),M(e.id),A(null)},children:[(0,_.jsx)(`path`,{d:r,fill:`none`,stroke:o?`hsl(var(--primary))`:s?`hsl(var(--foreground) / 0.6)`:`hsl(var(--foreground) / 0.4)`,strokeWidth:o?2.5:2,strokeDasharray:s?`6 3`:c?`3 3`:void 0,markerEnd:`url(#fd-arrowhead${o?`-selected`:s?`-conditional`:``})`}),(e.label||c)&&(0,_.jsx)(`text`,{x:i,y:a,textAnchor:`middle`,className:`text-[10px] fill-muted-foreground`,style:{fontSize:10},children:e.label??(c?`(default)`:``)}),e.condition&&(0,_.jsx)(`text`,{x:i,y:a+12,textAnchor:`middle`,className:`text-[9px] fill-orange-500`,style:{fontSize:9},children:e.condition.length>24?e.condition.slice(0,24)+`…`:e.condition}),(0,_.jsx)(`path`,{d:r,fill:`none`,stroke:`transparent`,strokeWidth:12})]},e.id)})]}),J.map(e=>(0,_.jsx)(oe,{node:e,isSelected:k===e.id,isConnectSource:F===e.id,connectMode:N,readOnly:a,showExecutionOverlay:l,onSelect:(e,t)=>{t||M(null),A(e)},onDelete:Y,onDragStart:ge,onPortClick:he},e.id)),N&&F&&(0,_.jsxs)(`div`,{className:`absolute bottom-4 left-1/2 -translate-x-1/2 bg-blue-600 text-white text-xs px-3 py-1.5 rounded shadow-lg pointer-events-none`,children:[(0,_.jsx)(i.Link,{className:`h-3 w-3 inline mr-1`}),`Click a node port to complete the connection — Esc to cancel`]}),D.length===0&&(0,_.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-muted-foreground text-sm`,children:`No nodes yet. Use the toolbar to add nodes.`})]})}),V&&d.length>0&&(0,_.jsx)(`div`,{className:`w-48 border-l bg-background flex-shrink-0 overflow-y-auto`,children:(0,_.jsx)(ce,{versions:d})}),z&&(0,_.jsxs)(`div`,{className:`w-52 border-l bg-background flex-shrink-0 overflow-y-auto`,children:[(0,_.jsx)(se,{node:ue,edge:de,readOnly:a,onNodeChange:pe,onEdgeChange:me}),W&&(0,_.jsxs)(`div`,{className:`p-3 border-t`,children:[(0,_.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1`,children:`BPMN Export`}),(0,_.jsx)(r.Badge,{variant:W.success?`default`:`destructive`,className:`text-[10px]`,children:W.success?`Exported ${W.nodeCount} nodes`:`Export failed`}),W.warnings?.map((e,t)=>(0,_.jsx)(`p`,{className:`text-[10px] text-amber-600 mt-0.5`,children:e},t))]})]})]})]})};t.ComponentRegistry.register(`workflow-designer`,x,{label:`Workflow Designer`,category:`Enterprise`,inputs:[{name:`workflow`,type:`code`,label:`Initial Workflow Definition`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`showMinimap`,type:`boolean`,label:`Show Minimap`,defaultValue:!1}]}),t.ComponentRegistry.register(`approval-process`,S,{label:`Approval Process`,category:`Enterprise`,inputs:[{name:`workflowId`,type:`string`,label:`Workflow ID`},{name:`instanceId`,type:`string`,label:`Instance ID`},{name:`currentNodeId`,type:`string`,label:`Current Node ID`},{name:`approvalRule`,type:`code`,label:`Approval Rule`},{name:`history`,type:`code`,label:`History`},{name:`showHistory`,type:`boolean`,label:`Show History`,defaultValue:!0},{name:`showComments`,type:`boolean`,label:`Show Comments`,defaultValue:!0}]}),t.ComponentRegistry.register(`automation-builder`,k,{label:`Automation Builder`,category:`Enterprise`,inputs:[{name:`automation`,type:`code`,label:`Automation Definition`},{name:`objects`,type:`code`,label:`Available Objects`}]}),t.ComponentRegistry.register(`automation-run-history`,N,{label:`Automation Run History`,category:`Enterprise`,inputs:[{name:`runs`,type:`code`,label:`Run History`}]}),t.ComponentRegistry.register(`flow-designer`,W,{label:`Flow Designer`,category:`Enterprise`,inputs:[{name:`nodes`,type:`code`,label:`Flow Nodes`},{name:`edges`,type:`code`,label:`Flow Edges`},{name:`title`,type:`string`,label:`Flow Title`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`showMinimap`,type:`boolean`,label:`Show Minimap`,defaultValue:!1},{name:`showVersionHistory`,type:`boolean`,label:`Show Version History`,defaultValue:!1},{name:`showExecutionOverlay`,type:`boolean`,label:`Show Execution Overlay`,defaultValue:!1},{name:`concurrencyPolicy`,type:`string`,label:`Concurrency Policy`},{name:`versionHistory`,type:`code`,label:`Version History`},{name:`executionSteps`,type:`code`,label:`Execution Steps`}]}),e.ApprovalProcess=S,e.AutomationBuilder=k,e.AutomationRunHistory=N,e.FlowDesigner=W,e.WorkflowDesigner=x});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-workflow",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.umd.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
"clsx": "^2.1.1",
|
|
24
24
|
"lucide-react": "^0.577.0",
|
|
25
25
|
"tailwind-merge": "^3.5.0",
|
|
26
|
-
"@object-ui/components": "3.1.
|
|
27
|
-
"@object-ui/core": "3.1.
|
|
28
|
-
"@object-ui/react": "3.1.
|
|
29
|
-
"@object-ui/types": "3.1.
|
|
26
|
+
"@object-ui/components": "3.1.5",
|
|
27
|
+
"@object-ui/core": "3.1.5",
|
|
28
|
+
"@object-ui/react": "3.1.5",
|
|
29
|
+
"@object-ui/types": "3.1.5"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^25.
|
|
32
|
+
"@types/node": "^25.5.0",
|
|
33
33
|
"@types/react": "19.2.14",
|
|
34
34
|
"@types/react-dom": "19.2.3",
|
|
35
|
-
"@vitejs/plugin-react": "^
|
|
36
|
-
"vite": "^
|
|
35
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
36
|
+
"vite": "^8.0.1",
|
|
37
37
|
"vite-plugin-dts": "^4.5.4",
|
|
38
|
-
"vitest": "^4.0
|
|
38
|
+
"vitest": "^4.1.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "vite build",
|