@oscherbakov/react-flow-automated-layout 1.3.3 → 1.3.4
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.
|
@@ -227,7 +227,7 @@ function ne({
|
|
|
227
227
|
}, [t, r, e, o]), V(() => {
|
|
228
228
|
t.length !== s && d(t.length);
|
|
229
229
|
}, [t]), V(() => {
|
|
230
|
-
f.size > 0 && p.size > 0 &&
|
|
230
|
+
f.size > 0 && p.size > 0 && (x || N(!0), E(!0));
|
|
231
231
|
}, [f, p, x]), V(() => {
|
|
232
232
|
const w = {};
|
|
233
233
|
p.forEach((g, C) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(M,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react"),require("@xyflow/react"),require("@dagrejs/dagre")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@xyflow/react","@dagrejs/dagre"],n):(M=typeof globalThis<"u"?globalThis:M||self,n(M.reactFlowAutomatedLayout={},M.jsxRuntime,M.React,M.ReactFlow,M.dagre))})(this,function(M,n,k,B,rt){"use strict";const st=k.createContext(void 0);function P(){const t=k.useContext(st);if(t===void 0)throw new Error("useLayoutContext must be used within a LayoutProvider");return t}const ot=t=>{switch(t){case"DOWN":return"TB";case"RIGHT":return"LR";case"UP":return"BT";case"LEFT":return"RL";default:return"TB"}},nt=t=>{switch(t){case"TB":return"DOWN";case"LR":return"RIGHT";case"BT":return"UP";case"RL":return"LEFT";default:return"DOWN"}},Et={enabled:!0,padding:{horizontal:80,vertical:48},respectHeaderHeight:!0,minWidth:200,minHeight:100},vt=t=>{switch(t){case"DOWN":return B.Position.Bottom;case"RIGHT":return B.Position.Right;case"UP":return B.Position.Top;case"LEFT":return B.Position.Left;default:return B.Position.Bottom}},Nt=t=>{switch(t){case"DOWN":return B.Position.Top;case"RIGHT":return B.Position.Left;case"UP":return B.Position.Bottom;case"LEFT":return B.Position.Right;default:return B.Position.Top}};function kt(t,r,e){if(e)return{nodes:t,edges:r};const o=t.filter(h=>!h.hidden),s=new Set(o.map(h=>h.id)),i=r.filter(h=>s.has(h.source)&&s.has(h.target));return{nodes:o,edges:i}}const Bt=172,St=36,V=async(t,r,e,o=0,s=50,i=50,h=Bt,a=St,d=!1)=>{const l=new rt.graphlib.Graph().setDefaultEdgeLabel(()=>({}));l.setGraph({rankdir:e,marginx:o,marginy:o,nodesep:s,ranksep:i,edgesep:Math.max(20,s/4),ranker:"tight-tree"});const c=d?t:t.filter(f=>!f.hidden);if(c.length===0)return{nodes:[],edges:[],width:0,height:0};c.forEach(f=>{var w,y;const g=Number((w=f.style)==null?void 0:w.width)||h,b=Number((y=f.style)==null?void 0:y.height)||a;l.setNode(f.id,{width:g,height:b})}),r.forEach(f=>{var L,C;const g=f.sourceHandle,b=f.targetHandle,w=!!((L=f.data)!=null&&L.isReciprocal),y=!!((C=f.data)!=null&&C.isSyntheticBridge);let p={};w?p={constraint:!1,minlen:1,weight:5}:y?p={constraint:!0,minlen:1,weight:4}:g==="right"&&b==="left"?p={constraint:!1,minlen:1}:g==="bottom"&&b==="top"?p={constraint:!0,minlen:1}:p={constraint:!0,minlen:2},l.setEdge(f.source,f.target,p)}),rt.layout(l);const u=l.graph().width||0,x=l.graph().height||0,N=vt(nt(e)),E=Nt(nt(e));return{nodes:c.map(f=>{var C;const g=l.node(f.id),{width:b,height:w}=g,y={...f,sourcePosition:N,targetPosition:E,selected:!1},p=g.x,L=g.y;switch((C=f.data)==null?void 0:C.positionType){case"center":y.position={x:p,y:L};break;case"topRight":y.position={x:p+b/2,y:L-w/2};break;case"bottomLeft":y.position={x:p-b/2,y:L+w/2};break;case"bottomRight":y.position={x:p+b/2,y:L+w/2};break;case"topLeft":default:y.position={x:p-b/2,y:L-w/2}}return y}),edges:r,width:u,height:x}},it={calculate:async(t,r,e)=>{const o=e.nodes||t,s=e.edges||r,h=e.dagreDirection||typeof e.direction=="string"&&(e.direction==="RIGHT"||e.direction==="LEFT"?"LR":"TB")||"TB",a=e.margin??(typeof e.padding=="number"?e.padding:0),d=e.nodeSpacing??50,l=e.layerSpacing??50,c=e.nodeWidth??172,u=e.nodeHeight??36,x=e.layoutHidden??!1;return V(o,s,h,a,d,l,c,u,x)}},ct={dagre:it};function Tt({initialDirection:t="DOWN",initialAlgorithm:r="layered",initialAutoLayout:e=!0,initialPadding:o=50,initialSpacing:s={node:50,layer:50},initialNodeDimensions:i={width:172,height:36},initialParentResizingOptions:h,includeHidden:a=!1,layoutEngines:d}){const[l,c]=k.useState(t),[u,x]=k.useState(r),[N,E]=k.useState(e),[v,f]=k.useState(!1),[g,b]=k.useState(a),[w,y]=k.useState({...ct,...d}),[p,L]=k.useState({}),[C,D]=k.useState(o),[G,m]=k.useState(s.node||150),[T,S]=k.useState(s.layer||180),[O,A]=k.useState(i.width||100),[_,W]=k.useState(i.height||100),[$,K]=k.useState({...Et,...h,enabled:e}),[Y,R]=k.useState([]);return{direction:l,algorithm:u,autoLayout:N,layoutInProgress:v,layoutHidden:g,layoutEngines:w,layoutEngineOptions:p,padding:C,nodeSpacing:G,layerSpacing:T,nodeWidth:O,nodeHeight:_,parentResizingOptions:$,selectedNodes:Y,setDirection:c,setAlgorithm:x,setAutoLayout:E,setLayoutInProgress:f,setLayoutHidden:b,setLayoutEngines:y,setLayoutEngineOptions:L,setPadding:D,setNodeSpacing:m,setLayerSpacing:S,setNodeWidth:A,setNodeHeight:W,setParentResizingOptionsState:K,setSelectedNodes:R}}function Mt({nodes:t,externalNodeIdWithNode:r,externalNodeParentIdMapWithChildIdSet:e,noParentKey:o="no-parent"}){const[s,i]=k.useState(new Map),[h,a]=k.useState(new Map),[d,l]=k.useState({}),[c,u]=k.useState(t.length),[x,N]=k.useState(!1),[E,v]=k.useState(!1),f=r||s,g=e||h,b=f.size;return k.useEffect(()=>{if(!r||!e){const w=new Map,y=new Map;v(!1),t.forEach(p=>{var C;w.set(p.id,p);const L=p.parentId||o;y.has(L)||y.set(L,new Set),(C=y.get(L))==null||C.add(p.id)}),r||i(w),e||a(y)}},[t,r,e,o]),k.useEffect(()=>{t.length!==c&&u(t.length)},[t]),k.useEffect(()=>{f.size>0&&g.size>0&&!x&&(N(!0),v(!0))},[f,g,x]),k.useEffect(()=>{const w={};g.forEach((p,L)=>{w[L]=p.size});let y=!1;for(const p in w)if(!d.hasOwnProperty(p)||w[p]!==d[p]){y=!0;break}y&&l(w)},[g]),{nodeIdWithNode:f,nodeParentIdMapWithChildIdSet:g,numberOfNodes:b,nodesLength:c,nodesInitialized:E,childrenInitialized:x,parentChildStructure:d}}function Dt({nodes:t,edges:r,selectedNodes:e,layoutHidden:o,calculateLayout:s,calculateContainerLayout:i,updateNodes:h,updateEdges:a,setLayoutInProgress:d,setNodeSpacing:l,setLayerSpacing:c}){const u=B.useReactFlow(),x=k.useRef(null),N=k.useRef(null),E=k.useCallback(async(f=[],g=[])=>{x.current&&x.current.abort();const b=new AbortController;x.current=b;const w=f.length>0?f:t,y=g.length>0?g:r;if(w.length===0)return{nodes:w,edges:y};try{if(d(!0),b.signal.aborted)return{nodes:w,edges:y};const{nodes:p,edges:L}=kt(w,y,o),C=await s(p,L,e,b.signal);return b.signal.aborted?{nodes:w,edges:y}:(x.current===b&&(h?h(C.nodes):u!=null&&u.setNodes&&u.setNodes(C.nodes),a?a(C.edges):u!=null&&u.setEdges&&u.setEdges(C.edges),N.current&&(N.current.node!==void 0&&l(N.current.node),N.current.layer!==void 0&&c(N.current.layer),N.current=null)),C)}catch(p){return b.signal.aborted||console.error("Error applying layout:",p),{nodes:w,edges:y}}finally{x.current===b&&(d(!1),x.current=null)}},[t,r,e,s,h,a,u,o,d,l,c]),v=k.useCallback(async f=>{x.current&&x.current.abort();const g=new AbortController;if(x.current=g,t.length===0)return{nodes:t,edges:r};try{if(d(!0),g.signal.aborted)return{nodes:t,edges:r};const b=await i(f,t,r,g.signal);return g.signal.aborted?{nodes:t,edges:r}:(x.current===g&&(h?h(b.nodes):u!=null&&u.setNodes&&u.setNodes(b.nodes),a?a(b.edges):u!=null&&u.setEdges&&u.setEdges(b.edges)),b)}catch(b){return g.signal.aborted||console.error("Error applying container layout:",b),{nodes:t,edges:r}}finally{x.current===g&&(d(!1),x.current=null)}},[t,r,i,h,a,u,d]);return{applyLayout:E,applyContainerLayout:v,pendingSpacingUpdateRef:N}}const Ot=(t,r,e="no-parent")=>{const o=new Set,s=new Map;t.forEach((a,d)=>{const l=r.get(d);l&&s.set(d,{id:d,node:l,children:[],depth:0})});const i=(a,d)=>{if(o.has(a)||!t.has(a)||!r.get(a))return null;o.add(a);const c=s.get(a);c.depth=d;const u=t.get(a)||new Set;for(const x of u)if(t.has(x)&&r.get(x)){const E=i(x,d+1);E&&c.children.push(E)}return c},h=[];return t.forEach((a,d)=>{const l=r.get(d);if(l){const c=l.parentId;if(!c||c===e){const u=i(d,0);u&&h.push(u)}}}),h};function j(t,r,e="no-parent"){const o=[];let s=t;const i=new Set;for(;s&&s!==e;){if(i.has(s)){console.warn(`Cycle detected in ancestor path for node ${t}`);break}i.add(s),o.push(s);const h=r.get(s);if(!h||!h.parentId){s=e;break}s=h.parentId}return s===e&&o.push(e),o}function z(t,r,e,o="no-parent"){if(t===r)return t;const s=j(t,e,o),i=s.indexOf(r);return i===-1?null:i===0?t:s[i-1]||null}function U(t,r,e,o="no-parent"){const s=j(t,e,o),i=j(r,e,o),h=new Set(i);let a=null,d=-1;for(let x=0;x<s.length;x++)if(h.has(s[x])){a=s[x],d=x;break}if(!a)return{lca:null,sourceChild:null,targetChild:null};const l=i.indexOf(a),c=d>0?s[d-1]:t,u=l>0?i[l-1]:r;return{lca:a,sourceChild:c,targetChild:u}}const At=t=>JSON.parse(JSON.stringify(t)),at=(t,r,e,o,s)=>{const i=At(t);return i.source=r,i.target=e,i.id=o,i.data={...i.data,...s},i},zt=t=>{for(const r of t.values()){const e=new Map;r.forEach(s=>{const i=`${s.source}->${s.target}`,h=e.get(i)||[];h.push(s),e.set(i,h)});const o=new Set;r.forEach(s=>{const i=`${s.source}->${s.target}`,h=`${s.target}->${s.source}`;if(o.has(i)||o.has(h))return;const a=e.get(h);if(!a||a.length===0)return;[...e.get(i)||[],...a].forEach(l=>{l.data={...l.data,isReciprocal:!0}}),o.add(i),o.add(h)})}},mt=(t,r,e,o)=>{const s=new Map,i=new Map;t.forEach(a=>{const d=s.get(a.target)||[];d.push(a),s.set(a.target,d);const l=i.get(a.source)||[];l.push(a),i.set(a.source,l)});const h=new Set;i.forEach((a,d)=>{const l=s.get(d)||[];l.length!==0&&l.forEach(c=>{a.forEach(u=>{if(c.source===u.target)return;const{lca:x,sourceChild:N,targetChild:E}=U(c.source,u.target,r,o),v=U(c.source,d,r,o).lca,f=U(d,u.target,r,o).lca;if(!v||v!==f)return;const g=z(c.source,v,r,o),b=z(u.target,v,r,o),w=z(d,v,r,o);if(!g||!b||!w||g!==b||g===w)return;const y=g,p=z(c.source,y,r,o),L=z(u.target,y,r,o);if(!x||!N||!E||!p||!L||p===L)return;const C=`synthetic_bridge_${c.id}_${d}_${u.id}_${y}`;if(h.has(C))return;const D=at(c,p,L,C,{isTemporary:!0,isSyntheticBridge:!0,bridgeNode:d,bridgeBranch:w,anchorBranch:g,originalSource:c.source,originalTarget:u.target});e.has(y)||e.set(y,[]),e.get(y).push(D),h.add(C)})})})};function X(t,r,e="no-parent"){const o=new Map;for(const s of t){const{lca:i,sourceChild:h,targetChild:a}=U(s.source,s.target,r,e);if(i&&h&&a&&h!==a){const d=at(s,h,a,`temp_${s.id}_${i}`,{isTemporary:!0,originalSource:s.source,originalTarget:s.target});o.has(i)||o.set(i,[]),o.get(i).push(d)}}return mt(t,r,o,e),zt(o),o}const q=10,lt=(t,r)=>t.find(e=>e.id===r),ht=(t,r,e)=>{var a,d;const o=e.get(t);if(!o)return null;let s=o.position.x+(o.width||Number((a=o.style)==null?void 0:a.width)||172)/2,i=o.position.y+(o.height||Number((d=o.style)==null?void 0:d.height)||36)/2,h=o.parentId;for(;h&&h!==r;){const l=e.get(h);if(!l)break;s+=l.position.x,i+=l.position.y,h=l.parentId}return{x:s,y:i}},H=t=>{var r,e;return{width:t.width||Number((r=t.style)==null?void 0:r.width)||172,height:t.height||Number((e=t.style)==null?void 0:e.height)||36}},dt=t=>{const{width:r,height:e}=H(t);return{x:t.position.x+r/2,y:t.position.y+e/2}},Gt=(t,r)=>{if(t.length===0)return{nodes:t,width:0,height:0};let e=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;t.forEach(c=>{const{width:u,height:x}=H(c);e=Math.min(e,c.position.x),o=Math.min(o,c.position.y),s=Math.max(s,c.position.x+u),i=Math.max(i,c.position.y+x)});const h=r-e,a=r-o;t.forEach(c=>{c.position={x:c.position.x+h,y:c.position.y+a}});const d=s-e+r*2,l=i-o+r*2;return{nodes:t,width:d,height:l}},_t=(t,r,e,o)=>{if(!(t.length<2||o.size===0))if(r==="TB"||r==="BT"){const s=[...t].sort((i,h)=>i.position.x-h.position.x);s.forEach((i,h)=>{if(!o.has(i.id))return;let a=i.position.x+H(i).width;for(let d=h+1;d<s.length;d++){const l=s[d],{width:c}=H(l),u=a+e;l.position.x<u&&(l.position.x=u),a=l.position.x+c}})}else{const s=[...t].sort((i,h)=>i.position.y-h.position.y);s.forEach((i,h)=>{if(!o.has(i.id))return;let a=i.position.y+H(i).height;for(let d=h+1;d<s.length;d++){const l=s[d],{height:c}=H(l),u=a+e;l.position.y<u&&(l.position.y=u),a=l.position.y+c}})}},Ht=(t,r,e,o)=>{const s=new Map,i=new Map;r.forEach(a=>{const d=s.get(a.target)||[];d.push(a),s.set(a.target,d);const l=i.get(a.source)||[];l.push(a),i.set(a.source,l)});const h=new Map;return i.forEach((a,d)=>{const l=s.get(d)||[];l.length!==0&&l.forEach(c=>{a.forEach(u=>{if(c.source===u.target)return;const x=U(c.source,d,e,o).lca,N=U(d,u.target,e,o).lca;if(x!==t||N!==t)return;const E=z(c.source,t,e,o),v=z(u.target,t,e,o),f=z(d,t,e,o);if(!E||!v||!f||E!==v||E===f)return;const g=z(c.source,E,e,o),b=z(u.target,E,e,o);if(!g||!b||g===b)return;const w=`${E}:${f}:${g}:${b}`;h.set(w,{anchorContainerId:E,bridgeContainerId:f,sourceNodeId:g,targetNodeId:b})})})}),[...h.values()]},Ft=(t,r,e,o,s,i,h)=>{const a=Ht(r,s,i,h),d=new Set;return a.forEach(l=>{const c=lt(t,l.anchorContainerId),u=lt(t,l.bridgeContainerId);if(!c||!u)return;const x=ht(l.sourceNodeId,r,i),N=ht(l.targetNodeId,r,i);if(!x||!N)return;const{width:E,height:v}=H(u),{width:f,height:g}=H(c),b=dt(c),w=dt(u);if(e==="TB"||e==="BT"){const y=(x.y+N.y)/2;u.position.y=y-v/2;const p=w.x>=b.x,L=p?u.position.x-(c.position.x+f):c.position.x-(u.position.x+E),C=Math.max(o,L);u.position.x=p?c.position.x+f+C:c.position.x-E-C}else{const y=(x.x+N.x)/2;u.position.x=y-E/2;const p=w.y>=b.y,L=p?u.position.y-(c.position.y+g):c.position.y-(u.position.y+v),C=Math.max(o,L);u.position.y=p?c.position.y+g+C:c.position.y-v-C}d.add(u.id)}),d},ut=async(t,r,e,o,s,i=q,h=50,a=50,d=172,l=36,c=V,u=!1,x="no-parent")=>{const N=X(s,o,x),{updatedNodes:E}=await I(t,r,e,o,s,i,h,a,d,l,c,u,N,x),v=o.get(t);if(!v)return{updatedNodes:E,updatedEdges:s};const{updatedNodes:f}=await ut(v.parentId||x,r,e,o,s,i,h,a,d,l,c,u,x);return{updatedNodes:[...f,...E],updatedEdges:s}},I=async(t,r,e,o,s,i=q,h=50,a=50,d=172,l=36,c=V,u=!1,x=new Map,N="no-parent")=>{const E=e.get(t);if(!E||E.size===0)return{updatedNodes:[]};const v=[];if(E.forEach(C=>{const D=o.get(C);D&&v.push(D)}),v.length===0)return{updatedNodes:[]};let f=r;const g=o.get(t);g&&g.data.layoutDirection&&(f=g.data.layoutDirection);const b=x.get(t)||[],{nodes:w,edges:y}=await c(v,b,f,i,h,a,d,l,u);w.forEach(C=>{o.set(C.id,C)});const p=Ft(w,t,f,h,s,o,N);_t(w,f,h,p),w.forEach(C=>{o.set(C.id,C)});const L=Gt(w,i);return L.nodes.forEach(C=>{o.set(C.id,C)}),g&&L.width&&L.height&&Pt(g,L.width,L.height),{updatedNodes:[...L.nodes],udpatedParentNode:g||void 0}},Pt=(t,r,e)=>(t.style||(t.style={}),t.width=r,t.height=e,t.measured={width:r,height:e},t.style.width=r,t.style.height=e,t),Ut=async(t,r,e,o,s,i=q,h=50,a=50,d=172,l=36,c=V,u=!1,x="no-parent")=>{let N=[];const E=X(s,o,x),v=new Map;let f=0;const g=(w,y)=>{y>f&&(f=y);for(const p of w)v.has(y)||v.set(y,[]),v.get(y).push(p.id),p.children.length>0&&g(p.children,y+1)};g(t,0);for(let w=f;w>=0;w--){const y=v.get(w)||[],p=await Promise.all(y.map(L=>I(L,r,e,o,s,i,h,a,d,l,c,u,E,x)));for(const{updatedNodes:L}of p)N=[...L,...N]}const{updatedNodes:b}=await I(x,r,e,o,s,i,h,a,d,l,c,u,E,x);return N=[...b,...N],{updatedNodes:N,updatedEdges:s}},Vt=(t,r,e,o="no-parent")=>{const s=t.map(l=>l.id),i=t.map(l=>{var c;return((c=e.get(l.id))==null?void 0:c.parentId)||l.parentId}).filter(l=>!!l),a=Array.from(new Set([...s,...i])).filter(l=>r.has(l)),d=a.filter(l=>{const c=e.get(l);return c?!c.parentId||!a.includes(c.parentId):!0});return d.length===0?[o]:d},It=async(t,r,e)=>{const{dagreDirection:o,nodeParentIdMapWithChildIdSet:s,nodeIdWithNode:i,nodes:h,edges:a,margin:d,nodeSpacing:l,layerSpacing:c,nodeWidth:u,nodeHeight:x,layoutHidden:N=!1,noParentKey:E="no-parent"}=r,v=Vt(t,s,i,E);if(v.length===0)return{nodes:h,edges:a};const f=new Map,g=new Map;if(e!=null&&e.aborted)return{nodes:h,edges:a};(await Promise.all(v.map(async p=>e!=null&&e.aborted?{updatedNodes:[],updatedEdges:[]}:ut(p,o,s,i,a,d,l,c,u,x,void 0,N)))).forEach(({updatedNodes:p,updatedEdges:L})=>{p.forEach(C=>{f.set(C.id,C)}),L.forEach(C=>{g.set(C.id,C)})});const w=h.map(p=>f.has(p.id)?f.get(p.id):p),y=a.map(p=>g.has(p.id)?g.get(p.id):p);return{nodes:w,edges:y}},Yt=(t,r,e,o,s,i,h,a,d=172,l=36,c=!1,u="no-parent")=>{const x=k.useCallback(async(E,v,f,g)=>{if(!(t[e]||t.dagre))return console.error(`Layout engine "${e}" not found`),{nodes:E,edges:v};const w=c?E:E.filter(T=>!T.hidden),y=new Set(w.map(T=>T.id)),p=c?v:v.filter(T=>y.has(T.source)&&y.has(T.target)),L=ot(r),C=o.padding.horizontal;let D=[],G=[];if(f&&f.length>0){const T=c?f:f.filter(O=>!O.hidden),S=await It(T,{dagreDirection:L,nodeParentIdMapWithChildIdSet:s,nodeIdWithNode:i,nodes:w,edges:p,margin:C,nodeSpacing:h,layerSpacing:a,nodeWidth:d,nodeHeight:l,layoutHidden:c,noParentKey:u},g);D=S.nodes,G=S.edges}else{if(g!=null&&g.aborted)return{nodes:E,edges:v};const T=Ot(s,i,u),S=await Ut(T,L,s,i,p,C,h,a,d,l,void 0,c,u);D=S.updatedNodes,G=S.updatedEdges}return{nodes:E.map(T=>!c&&T.hidden?T:D.find(O=>O.id===T.id)||T),edges:G}},[e,r,t,o.padding.horizontal,s,i,h,a,d,l,c,u]),N=k.useCallback(async(E,v,f,g)=>{if(g!=null&&g.aborted)return{nodes:v,edges:f};const b=ot(r),w=o.padding.horizontal,y=c?v:v.filter(S=>!S.hidden),p=new Set(y.map(S=>S.id)),L=c?f:f.filter(S=>p.has(S.source)&&p.has(S.target)),C=X(L,i,u),D=S=>{const O=[],A=s.get(S);if(A)for(const _ of A)s.has(_)&&O.push(...D(_));return O.push(S),O},G=D(E),m=new Map;for(const S of G){if(g!=null&&g.aborted)return{nodes:v,edges:f};const{updatedNodes:O,udpatedParentNode:A}=await I(S,b,s,i,L,w,h,a,d,l,void 0,c,C,u);O.forEach(_=>m.set(_.id,_)),A&&m.set(A.id,{...A})}return{nodes:v.map(S=>m.get(S.id)??S),edges:f}},[r,o.padding.horizontal,s,i,h,a,d,l,c,u]);return{calculateLayout:x,calculateContainerLayout:N}};function jt({children:t,initialDirection:r="DOWN",initialAlgorithm:e="layered",initialAutoLayout:o=!0,initialPadding:s=50,initialSpacing:i={node:50,layer:50},initialNodeDimensions:h={width:172,height:36},initialParentResizingOptions:a,includeHidden:d=!1,layoutEngines:l,updateNodes:c,updateEdges:u,nodeParentIdMapWithChildIdSet:x,nodeIdWithNode:N,noParentKey:E="no-parent",disableAutoLayoutEffect:v=!1}){const f=B.useNodes(),g=B.useEdges(),{direction:b,algorithm:w,autoLayout:y,layoutInProgress:p,layoutHidden:L,layoutEngines:C,layoutEngineOptions:D,padding:G,nodeSpacing:m,layerSpacing:T,nodeWidth:S,nodeHeight:O,parentResizingOptions:A,selectedNodes:_,setDirection:W,setAlgorithm:$,setAutoLayout:K,setLayoutInProgress:Y,setLayoutHidden:R,setLayoutEngines:gt,setLayoutEngineOptions:qt,setPadding:Jt,setNodeSpacing:pt,setLayerSpacing:yt,setNodeWidth:Zt,setNodeHeight:Qt,setParentResizingOptionsState:xt,setSelectedNodes:wt}=Tt({initialDirection:r,initialAlgorithm:e,initialAutoLayout:o,initialPadding:s,initialSpacing:i,initialNodeDimensions:h,initialParentResizingOptions:a,includeHidden:d,layoutEngines:l}),{nodeIdWithNode:tt,nodeParentIdMapWithChildIdSet:bt,numberOfNodes:Wt,nodesLength:$t,childrenInitialized:Ct,nodesInitialized:Kt,parentChildStructure:Rt}=Mt({nodes:f,externalNodeIdWithNode:N,externalNodeParentIdMapWithChildIdSet:x,noParentKey:E}),te=k.useCallback(({nodes:F})=>{wt(F)},[wt]);B.useOnSelectionChange({onChange:te});const{calculateLayout:ee,calculateContainerLayout:re}=Yt(C,b,w,A,bt,tt,m,T,S,O,L,E),{applyLayout:Lt,applyContainerLayout:se}=Dt({nodes:f,edges:g,selectedNodes:_,layoutHidden:L,calculateLayout:ee,calculateContainerLayout:re,updateNodes:c,updateEdges:u,setLayoutInProgress:Y,setNodeSpacing:pt,setLayerSpacing:yt}),oe=k.useCallback((F,et)=>{gt(ce=>({...ce,[F]:et}))},[gt]),ne=k.useCallback(F=>{xt(et=>({...et,...F,enabled:y}))},[y,xt]);k.useEffect(()=>{var F;v||tt.has((F=f[f.length-1])==null?void 0:F.id)&&Ct&&y&&Lt()},[Ct,y,b,Wt,m,T,Rt,$t]);const ie={direction:b,algorithm:w,autoLayout:y,layoutInProgress:p,nodesInitialized:Kt,padding:G,nodeSpacing:m,layerSpacing:T,nodeWidth:S,nodeHeight:O,layoutHidden:L,parentResizingOptions:A,layoutEngines:C,layoutEngineOptions:D,nodeParentIdMapWithChildIdSet:bt,nodeIdWithNode:tt,noParentKey:E,updateNodes:c,updateEdges:u,setDirection:W,setAlgorithm:$,setAutoLayout:K,setLayoutInProgress:Y,setPadding:Jt,setNodeSpacing:pt,setLayerSpacing:yt,setNodeWidth:Zt,setNodeHeight:Qt,setLayoutHidden:R,setParentResizingOptions:ne,setLayoutEngineOptions:qt,applyLayout:Lt,applyContainerLayout:se,clearLayoutCache:()=>{},registerLayoutEngine:oe};return n.jsx(st.Provider,{value:ie,children:t})}const J=({compact:t=!1})=>{const{direction:r,setDirection:e,clearLayoutCache:o}=P(),s=i=>{e(i),o&&o()};return t?n.jsx(B.ControlButton,{onClick:()=>s(r==="DOWN"?"RIGHT":"DOWN"),title:`Switch to ${r==="DOWN"?"horizontal":"vertical"} layout`,children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:r==="DOWN"?n.jsx("path",{d:"M4 12h16M16 6l6 6-6 6"}):n.jsx("path",{d:"M12 4v16M6 16l6 6 6-6"})})}):n.jsxs(n.Fragment,{children:[n.jsx(B.ControlButton,{onClick:()=>s("DOWN"),className:r==="DOWN"?"selected":"",title:"Top to Bottom",children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:n.jsx("path",{d:"M12 4v16M6 16l6 6 6-6"})})}),n.jsx(B.ControlButton,{onClick:()=>s("RIGHT"),className:r==="RIGHT"?"selected":"",title:"Left to Right",children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:n.jsx("path",{d:"M4 12h16M16 6l6 6-6 6"})})}),n.jsx(B.ControlButton,{onClick:()=>s("LEFT"),className:r==="LEFT"?"selected":"",title:"Right to Left",children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:n.jsx("path",{d:"M20 12H4M8 6L2 12l6 6"})})}),n.jsx(B.ControlButton,{onClick:()=>s("UP"),className:r==="UP"?"selected":"",title:"Bottom to Top",children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:n.jsx("path",{d:"M12 20V4M6 8l6-6 6 6"})})})]})},Z=({compact:t=!1})=>{const{nodeSpacing:r,layerSpacing:e,setNodeSpacing:o,setLayerSpacing:s,clearLayoutCache:i}=P(),[h,a]=k.useState(!1),d=c=>{o(c),i&&i()},l=c=>{s(c),i&&i()};return t?n.jsxs("div",{style:{position:"relative"},children:[n.jsx(B.ControlButton,{onClick:()=>a(!h),title:"Adjust node and layer spacing",children:n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("path",{d:"M7 10v4M17 10v4M10 7h4M10 17h4"})]})}),h&&n.jsxs("div",{className:"react-flow-spacing-dropdown",style:{position:"absolute",right:"0",top:"100%",marginTop:"8px",background:"white",border:"1px solid #ddd",borderRadius:"4px",padding:"8px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)",zIndex:10,minWidth:"200px"},children:[n.jsxs("div",{style:{marginBottom:"12px"},children:[n.jsxs("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:["Node Spacing: ",r,"px"]}),n.jsx("div",{style:{display:"flex",gap:"4px"},children:[50,100,150,200].map(c=>n.jsx("button",{onClick:()=>d(c),style:{background:r===c?"#0041d0":"#f5f5f5",color:r===c?"white":"inherit",border:"1px solid #ddd",borderRadius:"4px",padding:"4px 8px",cursor:"pointer"},children:c},c))})]}),n.jsxs("div",{children:[n.jsxs("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:["Layer Spacing: ",e,"px"]}),n.jsx("div",{style:{display:"flex",gap:"4px"},children:[50,100,150,200].map(c=>n.jsx("button",{onClick:()=>l(c),style:{background:e===c?"#0041d0":"#f5f5f5",color:e===c?"white":"inherit",border:"1px solid #ddd",borderRadius:"4px",padding:"4px 8px",cursor:"pointer"},children:c},c))})]}),n.jsx("div",{style:{marginTop:"12px",textAlign:"right"},children:n.jsx("button",{onClick:()=>a(!1),style:{background:"#f5f5f5",border:"1px solid #ddd",borderRadius:"4px",padding:"4px 8px",cursor:"pointer"},children:"Close"})})]})]}):n.jsxs("div",{className:"spacing-controls",children:[n.jsxs(B.ControlButton,{onClick:()=>d(Math.max(50,r-25)),title:"Decrease node spacing",children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("line",{x1:"7",y1:"10",x2:"7",y2:"14"}),n.jsx("line",{x1:"17",y1:"10",x2:"17",y2:"14"}),n.jsx("line",{x1:"10",y1:"7",x2:"14",y2:"7"}),n.jsx("line",{x1:"10",y1:"17",x2:"14",y2:"17"})]}),n.jsx("span",{style:{marginLeft:"4px"},children:"-"})]}),n.jsxs("div",{style:{display:"inline-flex",alignItems:"center",padding:"5px 10px",fontSize:"12px",background:"#f8f8f8",borderRadius:"4px",margin:"0 4px",border:"1px solid #ddd"},children:[r,"px"]}),n.jsxs(B.ControlButton,{onClick:()=>d(Math.min(300,r+25)),title:"Increase node spacing",children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("line",{x1:"7",y1:"10",x2:"7",y2:"14"}),n.jsx("line",{x1:"17",y1:"10",x2:"17",y2:"14"}),n.jsx("line",{x1:"10",y1:"7",x2:"14",y2:"7"}),n.jsx("line",{x1:"10",y1:"17",x2:"14",y2:"17"})]}),n.jsx("span",{style:{marginLeft:"4px"},children:"+"})]}),n.jsx("div",{style:{display:"inline-block",width:"1px",height:"24px",background:"#ddd",margin:"0 10px"}}),n.jsxs(B.ControlButton,{onClick:()=>l(Math.max(50,e-25)),title:"Decrease layer spacing",children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),n.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),n.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),n.jsx("span",{style:{marginLeft:"4px"},children:"-"})]}),n.jsxs("div",{style:{display:"inline-flex",alignItems:"center",padding:"5px 10px",fontSize:"12px",background:"#f8f8f8",borderRadius:"4px",margin:"0 4px",border:"1px solid #ddd"},children:[e,"px"]}),n.jsxs(B.ControlButton,{onClick:()=>l(Math.min(300,e+25)),title:"Increase layer spacing",children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),n.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),n.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),n.jsx("span",{style:{marginLeft:"4px"},children:"+"})]})]})},Q=({compact:t=!1})=>{const{autoLayout:r,setAutoLayout:e}=P(),o=()=>{e(!r)};return n.jsx(B.ControlButton,{onClick:o,className:r?"selected":"",title:r?"Disable automatic layout":"Enable automatic layout",style:{color:r?"green":"inherit"},children:t?n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"1.5",fill:"none",children:[n.jsx("rect",{x:"4",y:"4",width:"4",height:"4",rx:"1"}),n.jsx("rect",{x:"4",y:"16",width:"4",height:"4",rx:"1"}),n.jsx("rect",{x:"16",y:"10",width:"4",height:"4",rx:"1"}),n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M8 6c6 0 3 8 8 6"}),n.jsx("path",{d:"M8 18c3-3 2-8 6-6"})]})]}):n.jsxs(n.Fragment,{children:["Auto-Layout ",r?"ON":"OFF"]})})},ft=({compact:t=!1})=>{const{layoutInProgress:r,setLayoutInProgress:e,applyLayout:o}=P(),s=async()=>{if(!r)try{e(!0),await o()}catch(i){console.error("Error applying layout:",i)}};return n.jsxs(B.ControlButton,{onClick:s,title:"Apply layout",disabled:r,style:{color:r?"#999":"#000"},children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"1.5",fill:"none",children:[n.jsx("rect",{x:"3",y:"3",width:"5",height:"5",rx:"1"}),n.jsx("rect",{x:"16",y:"3",width:"5",height:"5",rx:"1"}),n.jsx("rect",{x:"3",y:"16",width:"5",height:"5",rx:"1"}),n.jsx("rect",{x:"16",y:"16",width:"5",height:"5",rx:"1"}),n.jsx("path",{d:"M8 5.5h8M5.5 8v8M18.5 8v8M8 18.5h8"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"}),n.jsx("path",{d:"M11 10.5v3l2-1.5z",fill:"currentColor"})]}),!t&&n.jsx("span",{style:{marginLeft:"4px"},children:"Apply Layout"})]})},Xt=({showDirectionControls:t=!0,showSpacingControls:r=!0,showAutoLayoutToggle:e=!0,showApplyLayoutButton:o=!0,standalone:s=!1,position:i="top-right"})=>{const h=P(),{autoLayout:a}=h;return s?n.jsxs(B.Controls,{position:i,showZoom:!1,showFitView:!1,showInteractive:!1,children:[o&&!a&&n.jsx(ft,{compact:!0}),t&&n.jsx(J,{compact:!0}),r&&n.jsx(Z,{compact:!0}),e&&n.jsx(Q,{compact:!0})]}):n.jsxs(n.Fragment,{children:[o&&!a&&n.jsx(ft,{compact:!0}),t&&n.jsx(J,{compact:!0}),r&&n.jsx(Z,{compact:!0}),e&&n.jsx(Q,{compact:!0})]})};M.AutoLayoutToggle=Q,M.DagreEngine=it,M.DirectionControls=J,M.LayoutControls=Xt,M.LayoutProvider=jt,M.SpacingControls=Z,M.engines=ct,M.useLayoutContext=P,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(M,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react"),require("@xyflow/react"),require("@dagrejs/dagre")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@xyflow/react","@dagrejs/dagre"],n):(M=typeof globalThis<"u"?globalThis:M||self,n(M.reactFlowAutomatedLayout={},M.jsxRuntime,M.React,M.ReactFlow,M.dagre))})(this,function(M,n,k,B,rt){"use strict";const st=k.createContext(void 0);function P(){const t=k.useContext(st);if(t===void 0)throw new Error("useLayoutContext must be used within a LayoutProvider");return t}const ot=t=>{switch(t){case"DOWN":return"TB";case"RIGHT":return"LR";case"UP":return"BT";case"LEFT":return"RL";default:return"TB"}},nt=t=>{switch(t){case"TB":return"DOWN";case"LR":return"RIGHT";case"BT":return"UP";case"RL":return"LEFT";default:return"DOWN"}},Et={enabled:!0,padding:{horizontal:80,vertical:48},respectHeaderHeight:!0,minWidth:200,minHeight:100},vt=t=>{switch(t){case"DOWN":return B.Position.Bottom;case"RIGHT":return B.Position.Right;case"UP":return B.Position.Top;case"LEFT":return B.Position.Left;default:return B.Position.Bottom}},Nt=t=>{switch(t){case"DOWN":return B.Position.Top;case"RIGHT":return B.Position.Left;case"UP":return B.Position.Bottom;case"LEFT":return B.Position.Right;default:return B.Position.Top}};function kt(t,r,e){if(e)return{nodes:t,edges:r};const o=t.filter(h=>!h.hidden),s=new Set(o.map(h=>h.id)),i=r.filter(h=>s.has(h.source)&&s.has(h.target));return{nodes:o,edges:i}}const Bt=172,St=36,V=async(t,r,e,o=0,s=50,i=50,h=Bt,a=St,d=!1)=>{const l=new rt.graphlib.Graph().setDefaultEdgeLabel(()=>({}));l.setGraph({rankdir:e,marginx:o,marginy:o,nodesep:s,ranksep:i,edgesep:Math.max(20,s/4),ranker:"tight-tree"});const c=d?t:t.filter(f=>!f.hidden);if(c.length===0)return{nodes:[],edges:[],width:0,height:0};c.forEach(f=>{var w,y;const g=Number((w=f.style)==null?void 0:w.width)||h,b=Number((y=f.style)==null?void 0:y.height)||a;l.setNode(f.id,{width:g,height:b})}),r.forEach(f=>{var L,C;const g=f.sourceHandle,b=f.targetHandle,w=!!((L=f.data)!=null&&L.isReciprocal),y=!!((C=f.data)!=null&&C.isSyntheticBridge);let p={};w?p={constraint:!1,minlen:1,weight:5}:y?p={constraint:!0,minlen:1,weight:4}:g==="right"&&b==="left"?p={constraint:!1,minlen:1}:g==="bottom"&&b==="top"?p={constraint:!0,minlen:1}:p={constraint:!0,minlen:2},l.setEdge(f.source,f.target,p)}),rt.layout(l);const u=l.graph().width||0,x=l.graph().height||0,N=vt(nt(e)),E=Nt(nt(e));return{nodes:c.map(f=>{var C;const g=l.node(f.id),{width:b,height:w}=g,y={...f,sourcePosition:N,targetPosition:E,selected:!1},p=g.x,L=g.y;switch((C=f.data)==null?void 0:C.positionType){case"center":y.position={x:p,y:L};break;case"topRight":y.position={x:p+b/2,y:L-w/2};break;case"bottomLeft":y.position={x:p-b/2,y:L+w/2};break;case"bottomRight":y.position={x:p+b/2,y:L+w/2};break;case"topLeft":default:y.position={x:p-b/2,y:L-w/2}}return y}),edges:r,width:u,height:x}},it={calculate:async(t,r,e)=>{const o=e.nodes||t,s=e.edges||r,h=e.dagreDirection||typeof e.direction=="string"&&(e.direction==="RIGHT"||e.direction==="LEFT"?"LR":"TB")||"TB",a=e.margin??(typeof e.padding=="number"?e.padding:0),d=e.nodeSpacing??50,l=e.layerSpacing??50,c=e.nodeWidth??172,u=e.nodeHeight??36,x=e.layoutHidden??!1;return V(o,s,h,a,d,l,c,u,x)}},ct={dagre:it};function Tt({initialDirection:t="DOWN",initialAlgorithm:r="layered",initialAutoLayout:e=!0,initialPadding:o=50,initialSpacing:s={node:50,layer:50},initialNodeDimensions:i={width:172,height:36},initialParentResizingOptions:h,includeHidden:a=!1,layoutEngines:d}){const[l,c]=k.useState(t),[u,x]=k.useState(r),[N,E]=k.useState(e),[v,f]=k.useState(!1),[g,b]=k.useState(a),[w,y]=k.useState({...ct,...d}),[p,L]=k.useState({}),[C,D]=k.useState(o),[G,m]=k.useState(s.node||150),[T,S]=k.useState(s.layer||180),[O,A]=k.useState(i.width||100),[_,W]=k.useState(i.height||100),[$,K]=k.useState({...Et,...h,enabled:e}),[Y,R]=k.useState([]);return{direction:l,algorithm:u,autoLayout:N,layoutInProgress:v,layoutHidden:g,layoutEngines:w,layoutEngineOptions:p,padding:C,nodeSpacing:G,layerSpacing:T,nodeWidth:O,nodeHeight:_,parentResizingOptions:$,selectedNodes:Y,setDirection:c,setAlgorithm:x,setAutoLayout:E,setLayoutInProgress:f,setLayoutHidden:b,setLayoutEngines:y,setLayoutEngineOptions:L,setPadding:D,setNodeSpacing:m,setLayerSpacing:S,setNodeWidth:A,setNodeHeight:W,setParentResizingOptionsState:K,setSelectedNodes:R}}function Mt({nodes:t,externalNodeIdWithNode:r,externalNodeParentIdMapWithChildIdSet:e,noParentKey:o="no-parent"}){const[s,i]=k.useState(new Map),[h,a]=k.useState(new Map),[d,l]=k.useState({}),[c,u]=k.useState(t.length),[x,N]=k.useState(!1),[E,v]=k.useState(!1),f=r||s,g=e||h,b=f.size;return k.useEffect(()=>{if(!r||!e){const w=new Map,y=new Map;v(!1),t.forEach(p=>{var C;w.set(p.id,p);const L=p.parentId||o;y.has(L)||y.set(L,new Set),(C=y.get(L))==null||C.add(p.id)}),r||i(w),e||a(y)}},[t,r,e,o]),k.useEffect(()=>{t.length!==c&&u(t.length)},[t]),k.useEffect(()=>{f.size>0&&g.size>0&&(x||N(!0),v(!0))},[f,g,x]),k.useEffect(()=>{const w={};g.forEach((p,L)=>{w[L]=p.size});let y=!1;for(const p in w)if(!d.hasOwnProperty(p)||w[p]!==d[p]){y=!0;break}y&&l(w)},[g]),{nodeIdWithNode:f,nodeParentIdMapWithChildIdSet:g,numberOfNodes:b,nodesLength:c,nodesInitialized:E,childrenInitialized:x,parentChildStructure:d}}function Dt({nodes:t,edges:r,selectedNodes:e,layoutHidden:o,calculateLayout:s,calculateContainerLayout:i,updateNodes:h,updateEdges:a,setLayoutInProgress:d,setNodeSpacing:l,setLayerSpacing:c}){const u=B.useReactFlow(),x=k.useRef(null),N=k.useRef(null),E=k.useCallback(async(f=[],g=[])=>{x.current&&x.current.abort();const b=new AbortController;x.current=b;const w=f.length>0?f:t,y=g.length>0?g:r;if(w.length===0)return{nodes:w,edges:y};try{if(d(!0),b.signal.aborted)return{nodes:w,edges:y};const{nodes:p,edges:L}=kt(w,y,o),C=await s(p,L,e,b.signal);return b.signal.aborted?{nodes:w,edges:y}:(x.current===b&&(h?h(C.nodes):u!=null&&u.setNodes&&u.setNodes(C.nodes),a?a(C.edges):u!=null&&u.setEdges&&u.setEdges(C.edges),N.current&&(N.current.node!==void 0&&l(N.current.node),N.current.layer!==void 0&&c(N.current.layer),N.current=null)),C)}catch(p){return b.signal.aborted||console.error("Error applying layout:",p),{nodes:w,edges:y}}finally{x.current===b&&(d(!1),x.current=null)}},[t,r,e,s,h,a,u,o,d,l,c]),v=k.useCallback(async f=>{x.current&&x.current.abort();const g=new AbortController;if(x.current=g,t.length===0)return{nodes:t,edges:r};try{if(d(!0),g.signal.aborted)return{nodes:t,edges:r};const b=await i(f,t,r,g.signal);return g.signal.aborted?{nodes:t,edges:r}:(x.current===g&&(h?h(b.nodes):u!=null&&u.setNodes&&u.setNodes(b.nodes),a?a(b.edges):u!=null&&u.setEdges&&u.setEdges(b.edges)),b)}catch(b){return g.signal.aborted||console.error("Error applying container layout:",b),{nodes:t,edges:r}}finally{x.current===g&&(d(!1),x.current=null)}},[t,r,i,h,a,u,d]);return{applyLayout:E,applyContainerLayout:v,pendingSpacingUpdateRef:N}}const Ot=(t,r,e="no-parent")=>{const o=new Set,s=new Map;t.forEach((a,d)=>{const l=r.get(d);l&&s.set(d,{id:d,node:l,children:[],depth:0})});const i=(a,d)=>{if(o.has(a)||!t.has(a)||!r.get(a))return null;o.add(a);const c=s.get(a);c.depth=d;const u=t.get(a)||new Set;for(const x of u)if(t.has(x)&&r.get(x)){const E=i(x,d+1);E&&c.children.push(E)}return c},h=[];return t.forEach((a,d)=>{const l=r.get(d);if(l){const c=l.parentId;if(!c||c===e){const u=i(d,0);u&&h.push(u)}}}),h};function j(t,r,e="no-parent"){const o=[];let s=t;const i=new Set;for(;s&&s!==e;){if(i.has(s)){console.warn(`Cycle detected in ancestor path for node ${t}`);break}i.add(s),o.push(s);const h=r.get(s);if(!h||!h.parentId){s=e;break}s=h.parentId}return s===e&&o.push(e),o}function z(t,r,e,o="no-parent"){if(t===r)return t;const s=j(t,e,o),i=s.indexOf(r);return i===-1?null:i===0?t:s[i-1]||null}function U(t,r,e,o="no-parent"){const s=j(t,e,o),i=j(r,e,o),h=new Set(i);let a=null,d=-1;for(let x=0;x<s.length;x++)if(h.has(s[x])){a=s[x],d=x;break}if(!a)return{lca:null,sourceChild:null,targetChild:null};const l=i.indexOf(a),c=d>0?s[d-1]:t,u=l>0?i[l-1]:r;return{lca:a,sourceChild:c,targetChild:u}}const At=t=>JSON.parse(JSON.stringify(t)),at=(t,r,e,o,s)=>{const i=At(t);return i.source=r,i.target=e,i.id=o,i.data={...i.data,...s},i},zt=t=>{for(const r of t.values()){const e=new Map;r.forEach(s=>{const i=`${s.source}->${s.target}`,h=e.get(i)||[];h.push(s),e.set(i,h)});const o=new Set;r.forEach(s=>{const i=`${s.source}->${s.target}`,h=`${s.target}->${s.source}`;if(o.has(i)||o.has(h))return;const a=e.get(h);if(!a||a.length===0)return;[...e.get(i)||[],...a].forEach(l=>{l.data={...l.data,isReciprocal:!0}}),o.add(i),o.add(h)})}},mt=(t,r,e,o)=>{const s=new Map,i=new Map;t.forEach(a=>{const d=s.get(a.target)||[];d.push(a),s.set(a.target,d);const l=i.get(a.source)||[];l.push(a),i.set(a.source,l)});const h=new Set;i.forEach((a,d)=>{const l=s.get(d)||[];l.length!==0&&l.forEach(c=>{a.forEach(u=>{if(c.source===u.target)return;const{lca:x,sourceChild:N,targetChild:E}=U(c.source,u.target,r,o),v=U(c.source,d,r,o).lca,f=U(d,u.target,r,o).lca;if(!v||v!==f)return;const g=z(c.source,v,r,o),b=z(u.target,v,r,o),w=z(d,v,r,o);if(!g||!b||!w||g!==b||g===w)return;const y=g,p=z(c.source,y,r,o),L=z(u.target,y,r,o);if(!x||!N||!E||!p||!L||p===L)return;const C=`synthetic_bridge_${c.id}_${d}_${u.id}_${y}`;if(h.has(C))return;const D=at(c,p,L,C,{isTemporary:!0,isSyntheticBridge:!0,bridgeNode:d,bridgeBranch:w,anchorBranch:g,originalSource:c.source,originalTarget:u.target});e.has(y)||e.set(y,[]),e.get(y).push(D),h.add(C)})})})};function X(t,r,e="no-parent"){const o=new Map;for(const s of t){const{lca:i,sourceChild:h,targetChild:a}=U(s.source,s.target,r,e);if(i&&h&&a&&h!==a){const d=at(s,h,a,`temp_${s.id}_${i}`,{isTemporary:!0,originalSource:s.source,originalTarget:s.target});o.has(i)||o.set(i,[]),o.get(i).push(d)}}return mt(t,r,o,e),zt(o),o}const q=10,lt=(t,r)=>t.find(e=>e.id===r),ht=(t,r,e)=>{var a,d;const o=e.get(t);if(!o)return null;let s=o.position.x+(o.width||Number((a=o.style)==null?void 0:a.width)||172)/2,i=o.position.y+(o.height||Number((d=o.style)==null?void 0:d.height)||36)/2,h=o.parentId;for(;h&&h!==r;){const l=e.get(h);if(!l)break;s+=l.position.x,i+=l.position.y,h=l.parentId}return{x:s,y:i}},H=t=>{var r,e;return{width:t.width||Number((r=t.style)==null?void 0:r.width)||172,height:t.height||Number((e=t.style)==null?void 0:e.height)||36}},dt=t=>{const{width:r,height:e}=H(t);return{x:t.position.x+r/2,y:t.position.y+e/2}},Gt=(t,r)=>{if(t.length===0)return{nodes:t,width:0,height:0};let e=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;t.forEach(c=>{const{width:u,height:x}=H(c);e=Math.min(e,c.position.x),o=Math.min(o,c.position.y),s=Math.max(s,c.position.x+u),i=Math.max(i,c.position.y+x)});const h=r-e,a=r-o;t.forEach(c=>{c.position={x:c.position.x+h,y:c.position.y+a}});const d=s-e+r*2,l=i-o+r*2;return{nodes:t,width:d,height:l}},_t=(t,r,e,o)=>{if(!(t.length<2||o.size===0))if(r==="TB"||r==="BT"){const s=[...t].sort((i,h)=>i.position.x-h.position.x);s.forEach((i,h)=>{if(!o.has(i.id))return;let a=i.position.x+H(i).width;for(let d=h+1;d<s.length;d++){const l=s[d],{width:c}=H(l),u=a+e;l.position.x<u&&(l.position.x=u),a=l.position.x+c}})}else{const s=[...t].sort((i,h)=>i.position.y-h.position.y);s.forEach((i,h)=>{if(!o.has(i.id))return;let a=i.position.y+H(i).height;for(let d=h+1;d<s.length;d++){const l=s[d],{height:c}=H(l),u=a+e;l.position.y<u&&(l.position.y=u),a=l.position.y+c}})}},Ht=(t,r,e,o)=>{const s=new Map,i=new Map;r.forEach(a=>{const d=s.get(a.target)||[];d.push(a),s.set(a.target,d);const l=i.get(a.source)||[];l.push(a),i.set(a.source,l)});const h=new Map;return i.forEach((a,d)=>{const l=s.get(d)||[];l.length!==0&&l.forEach(c=>{a.forEach(u=>{if(c.source===u.target)return;const x=U(c.source,d,e,o).lca,N=U(d,u.target,e,o).lca;if(x!==t||N!==t)return;const E=z(c.source,t,e,o),v=z(u.target,t,e,o),f=z(d,t,e,o);if(!E||!v||!f||E!==v||E===f)return;const g=z(c.source,E,e,o),b=z(u.target,E,e,o);if(!g||!b||g===b)return;const w=`${E}:${f}:${g}:${b}`;h.set(w,{anchorContainerId:E,bridgeContainerId:f,sourceNodeId:g,targetNodeId:b})})})}),[...h.values()]},Ft=(t,r,e,o,s,i,h)=>{const a=Ht(r,s,i,h),d=new Set;return a.forEach(l=>{const c=lt(t,l.anchorContainerId),u=lt(t,l.bridgeContainerId);if(!c||!u)return;const x=ht(l.sourceNodeId,r,i),N=ht(l.targetNodeId,r,i);if(!x||!N)return;const{width:E,height:v}=H(u),{width:f,height:g}=H(c),b=dt(c),w=dt(u);if(e==="TB"||e==="BT"){const y=(x.y+N.y)/2;u.position.y=y-v/2;const p=w.x>=b.x,L=p?u.position.x-(c.position.x+f):c.position.x-(u.position.x+E),C=Math.max(o,L);u.position.x=p?c.position.x+f+C:c.position.x-E-C}else{const y=(x.x+N.x)/2;u.position.x=y-E/2;const p=w.y>=b.y,L=p?u.position.y-(c.position.y+g):c.position.y-(u.position.y+v),C=Math.max(o,L);u.position.y=p?c.position.y+g+C:c.position.y-v-C}d.add(u.id)}),d},ut=async(t,r,e,o,s,i=q,h=50,a=50,d=172,l=36,c=V,u=!1,x="no-parent")=>{const N=X(s,o,x),{updatedNodes:E}=await I(t,r,e,o,s,i,h,a,d,l,c,u,N,x),v=o.get(t);if(!v)return{updatedNodes:E,updatedEdges:s};const{updatedNodes:f}=await ut(v.parentId||x,r,e,o,s,i,h,a,d,l,c,u,x);return{updatedNodes:[...f,...E],updatedEdges:s}},I=async(t,r,e,o,s,i=q,h=50,a=50,d=172,l=36,c=V,u=!1,x=new Map,N="no-parent")=>{const E=e.get(t);if(!E||E.size===0)return{updatedNodes:[]};const v=[];if(E.forEach(C=>{const D=o.get(C);D&&v.push(D)}),v.length===0)return{updatedNodes:[]};let f=r;const g=o.get(t);g&&g.data.layoutDirection&&(f=g.data.layoutDirection);const b=x.get(t)||[],{nodes:w,edges:y}=await c(v,b,f,i,h,a,d,l,u);w.forEach(C=>{o.set(C.id,C)});const p=Ft(w,t,f,h,s,o,N);_t(w,f,h,p),w.forEach(C=>{o.set(C.id,C)});const L=Gt(w,i);return L.nodes.forEach(C=>{o.set(C.id,C)}),g&&L.width&&L.height&&Pt(g,L.width,L.height),{updatedNodes:[...L.nodes],udpatedParentNode:g||void 0}},Pt=(t,r,e)=>(t.style||(t.style={}),t.width=r,t.height=e,t.measured={width:r,height:e},t.style.width=r,t.style.height=e,t),Ut=async(t,r,e,o,s,i=q,h=50,a=50,d=172,l=36,c=V,u=!1,x="no-parent")=>{let N=[];const E=X(s,o,x),v=new Map;let f=0;const g=(w,y)=>{y>f&&(f=y);for(const p of w)v.has(y)||v.set(y,[]),v.get(y).push(p.id),p.children.length>0&&g(p.children,y+1)};g(t,0);for(let w=f;w>=0;w--){const y=v.get(w)||[],p=await Promise.all(y.map(L=>I(L,r,e,o,s,i,h,a,d,l,c,u,E,x)));for(const{updatedNodes:L}of p)N=[...L,...N]}const{updatedNodes:b}=await I(x,r,e,o,s,i,h,a,d,l,c,u,E,x);return N=[...b,...N],{updatedNodes:N,updatedEdges:s}},Vt=(t,r,e,o="no-parent")=>{const s=t.map(l=>l.id),i=t.map(l=>{var c;return((c=e.get(l.id))==null?void 0:c.parentId)||l.parentId}).filter(l=>!!l),a=Array.from(new Set([...s,...i])).filter(l=>r.has(l)),d=a.filter(l=>{const c=e.get(l);return c?!c.parentId||!a.includes(c.parentId):!0});return d.length===0?[o]:d},It=async(t,r,e)=>{const{dagreDirection:o,nodeParentIdMapWithChildIdSet:s,nodeIdWithNode:i,nodes:h,edges:a,margin:d,nodeSpacing:l,layerSpacing:c,nodeWidth:u,nodeHeight:x,layoutHidden:N=!1,noParentKey:E="no-parent"}=r,v=Vt(t,s,i,E);if(v.length===0)return{nodes:h,edges:a};const f=new Map,g=new Map;if(e!=null&&e.aborted)return{nodes:h,edges:a};(await Promise.all(v.map(async p=>e!=null&&e.aborted?{updatedNodes:[],updatedEdges:[]}:ut(p,o,s,i,a,d,l,c,u,x,void 0,N)))).forEach(({updatedNodes:p,updatedEdges:L})=>{p.forEach(C=>{f.set(C.id,C)}),L.forEach(C=>{g.set(C.id,C)})});const w=h.map(p=>f.has(p.id)?f.get(p.id):p),y=a.map(p=>g.has(p.id)?g.get(p.id):p);return{nodes:w,edges:y}},Yt=(t,r,e,o,s,i,h,a,d=172,l=36,c=!1,u="no-parent")=>{const x=k.useCallback(async(E,v,f,g)=>{if(!(t[e]||t.dagre))return console.error(`Layout engine "${e}" not found`),{nodes:E,edges:v};const w=c?E:E.filter(T=>!T.hidden),y=new Set(w.map(T=>T.id)),p=c?v:v.filter(T=>y.has(T.source)&&y.has(T.target)),L=ot(r),C=o.padding.horizontal;let D=[],G=[];if(f&&f.length>0){const T=c?f:f.filter(O=>!O.hidden),S=await It(T,{dagreDirection:L,nodeParentIdMapWithChildIdSet:s,nodeIdWithNode:i,nodes:w,edges:p,margin:C,nodeSpacing:h,layerSpacing:a,nodeWidth:d,nodeHeight:l,layoutHidden:c,noParentKey:u},g);D=S.nodes,G=S.edges}else{if(g!=null&&g.aborted)return{nodes:E,edges:v};const T=Ot(s,i,u),S=await Ut(T,L,s,i,p,C,h,a,d,l,void 0,c,u);D=S.updatedNodes,G=S.updatedEdges}return{nodes:E.map(T=>!c&&T.hidden?T:D.find(O=>O.id===T.id)||T),edges:G}},[e,r,t,o.padding.horizontal,s,i,h,a,d,l,c,u]),N=k.useCallback(async(E,v,f,g)=>{if(g!=null&&g.aborted)return{nodes:v,edges:f};const b=ot(r),w=o.padding.horizontal,y=c?v:v.filter(S=>!S.hidden),p=new Set(y.map(S=>S.id)),L=c?f:f.filter(S=>p.has(S.source)&&p.has(S.target)),C=X(L,i,u),D=S=>{const O=[],A=s.get(S);if(A)for(const _ of A)s.has(_)&&O.push(...D(_));return O.push(S),O},G=D(E),m=new Map;for(const S of G){if(g!=null&&g.aborted)return{nodes:v,edges:f};const{updatedNodes:O,udpatedParentNode:A}=await I(S,b,s,i,L,w,h,a,d,l,void 0,c,C,u);O.forEach(_=>m.set(_.id,_)),A&&m.set(A.id,{...A})}return{nodes:v.map(S=>m.get(S.id)??S),edges:f}},[r,o.padding.horizontal,s,i,h,a,d,l,c,u]);return{calculateLayout:x,calculateContainerLayout:N}};function jt({children:t,initialDirection:r="DOWN",initialAlgorithm:e="layered",initialAutoLayout:o=!0,initialPadding:s=50,initialSpacing:i={node:50,layer:50},initialNodeDimensions:h={width:172,height:36},initialParentResizingOptions:a,includeHidden:d=!1,layoutEngines:l,updateNodes:c,updateEdges:u,nodeParentIdMapWithChildIdSet:x,nodeIdWithNode:N,noParentKey:E="no-parent",disableAutoLayoutEffect:v=!1}){const f=B.useNodes(),g=B.useEdges(),{direction:b,algorithm:w,autoLayout:y,layoutInProgress:p,layoutHidden:L,layoutEngines:C,layoutEngineOptions:D,padding:G,nodeSpacing:m,layerSpacing:T,nodeWidth:S,nodeHeight:O,parentResizingOptions:A,selectedNodes:_,setDirection:W,setAlgorithm:$,setAutoLayout:K,setLayoutInProgress:Y,setLayoutHidden:R,setLayoutEngines:gt,setLayoutEngineOptions:qt,setPadding:Jt,setNodeSpacing:pt,setLayerSpacing:yt,setNodeWidth:Zt,setNodeHeight:Qt,setParentResizingOptionsState:xt,setSelectedNodes:wt}=Tt({initialDirection:r,initialAlgorithm:e,initialAutoLayout:o,initialPadding:s,initialSpacing:i,initialNodeDimensions:h,initialParentResizingOptions:a,includeHidden:d,layoutEngines:l}),{nodeIdWithNode:tt,nodeParentIdMapWithChildIdSet:bt,numberOfNodes:Wt,nodesLength:$t,childrenInitialized:Ct,nodesInitialized:Kt,parentChildStructure:Rt}=Mt({nodes:f,externalNodeIdWithNode:N,externalNodeParentIdMapWithChildIdSet:x,noParentKey:E}),te=k.useCallback(({nodes:F})=>{wt(F)},[wt]);B.useOnSelectionChange({onChange:te});const{calculateLayout:ee,calculateContainerLayout:re}=Yt(C,b,w,A,bt,tt,m,T,S,O,L,E),{applyLayout:Lt,applyContainerLayout:se}=Dt({nodes:f,edges:g,selectedNodes:_,layoutHidden:L,calculateLayout:ee,calculateContainerLayout:re,updateNodes:c,updateEdges:u,setLayoutInProgress:Y,setNodeSpacing:pt,setLayerSpacing:yt}),oe=k.useCallback((F,et)=>{gt(ce=>({...ce,[F]:et}))},[gt]),ne=k.useCallback(F=>{xt(et=>({...et,...F,enabled:y}))},[y,xt]);k.useEffect(()=>{var F;v||tt.has((F=f[f.length-1])==null?void 0:F.id)&&Ct&&y&&Lt()},[Ct,y,b,Wt,m,T,Rt,$t]);const ie={direction:b,algorithm:w,autoLayout:y,layoutInProgress:p,nodesInitialized:Kt,padding:G,nodeSpacing:m,layerSpacing:T,nodeWidth:S,nodeHeight:O,layoutHidden:L,parentResizingOptions:A,layoutEngines:C,layoutEngineOptions:D,nodeParentIdMapWithChildIdSet:bt,nodeIdWithNode:tt,noParentKey:E,updateNodes:c,updateEdges:u,setDirection:W,setAlgorithm:$,setAutoLayout:K,setLayoutInProgress:Y,setPadding:Jt,setNodeSpacing:pt,setLayerSpacing:yt,setNodeWidth:Zt,setNodeHeight:Qt,setLayoutHidden:R,setParentResizingOptions:ne,setLayoutEngineOptions:qt,applyLayout:Lt,applyContainerLayout:se,clearLayoutCache:()=>{},registerLayoutEngine:oe};return n.jsx(st.Provider,{value:ie,children:t})}const J=({compact:t=!1})=>{const{direction:r,setDirection:e,clearLayoutCache:o}=P(),s=i=>{e(i),o&&o()};return t?n.jsx(B.ControlButton,{onClick:()=>s(r==="DOWN"?"RIGHT":"DOWN"),title:`Switch to ${r==="DOWN"?"horizontal":"vertical"} layout`,children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:r==="DOWN"?n.jsx("path",{d:"M4 12h16M16 6l6 6-6 6"}):n.jsx("path",{d:"M12 4v16M6 16l6 6 6-6"})})}):n.jsxs(n.Fragment,{children:[n.jsx(B.ControlButton,{onClick:()=>s("DOWN"),className:r==="DOWN"?"selected":"",title:"Top to Bottom",children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:n.jsx("path",{d:"M12 4v16M6 16l6 6 6-6"})})}),n.jsx(B.ControlButton,{onClick:()=>s("RIGHT"),className:r==="RIGHT"?"selected":"",title:"Left to Right",children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:n.jsx("path",{d:"M4 12h16M16 6l6 6-6 6"})})}),n.jsx(B.ControlButton,{onClick:()=>s("LEFT"),className:r==="LEFT"?"selected":"",title:"Right to Left",children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:n.jsx("path",{d:"M20 12H4M8 6L2 12l6 6"})})}),n.jsx(B.ControlButton,{onClick:()=>s("UP"),className:r==="UP"?"selected":"",title:"Bottom to Top",children:n.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:n.jsx("path",{d:"M12 20V4M6 8l6-6 6 6"})})})]})},Z=({compact:t=!1})=>{const{nodeSpacing:r,layerSpacing:e,setNodeSpacing:o,setLayerSpacing:s,clearLayoutCache:i}=P(),[h,a]=k.useState(!1),d=c=>{o(c),i&&i()},l=c=>{s(c),i&&i()};return t?n.jsxs("div",{style:{position:"relative"},children:[n.jsx(B.ControlButton,{onClick:()=>a(!h),title:"Adjust node and layer spacing",children:n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("path",{d:"M7 10v4M17 10v4M10 7h4M10 17h4"})]})}),h&&n.jsxs("div",{className:"react-flow-spacing-dropdown",style:{position:"absolute",right:"0",top:"100%",marginTop:"8px",background:"white",border:"1px solid #ddd",borderRadius:"4px",padding:"8px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)",zIndex:10,minWidth:"200px"},children:[n.jsxs("div",{style:{marginBottom:"12px"},children:[n.jsxs("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:["Node Spacing: ",r,"px"]}),n.jsx("div",{style:{display:"flex",gap:"4px"},children:[50,100,150,200].map(c=>n.jsx("button",{onClick:()=>d(c),style:{background:r===c?"#0041d0":"#f5f5f5",color:r===c?"white":"inherit",border:"1px solid #ddd",borderRadius:"4px",padding:"4px 8px",cursor:"pointer"},children:c},c))})]}),n.jsxs("div",{children:[n.jsxs("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:["Layer Spacing: ",e,"px"]}),n.jsx("div",{style:{display:"flex",gap:"4px"},children:[50,100,150,200].map(c=>n.jsx("button",{onClick:()=>l(c),style:{background:e===c?"#0041d0":"#f5f5f5",color:e===c?"white":"inherit",border:"1px solid #ddd",borderRadius:"4px",padding:"4px 8px",cursor:"pointer"},children:c},c))})]}),n.jsx("div",{style:{marginTop:"12px",textAlign:"right"},children:n.jsx("button",{onClick:()=>a(!1),style:{background:"#f5f5f5",border:"1px solid #ddd",borderRadius:"4px",padding:"4px 8px",cursor:"pointer"},children:"Close"})})]})]}):n.jsxs("div",{className:"spacing-controls",children:[n.jsxs(B.ControlButton,{onClick:()=>d(Math.max(50,r-25)),title:"Decrease node spacing",children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("line",{x1:"7",y1:"10",x2:"7",y2:"14"}),n.jsx("line",{x1:"17",y1:"10",x2:"17",y2:"14"}),n.jsx("line",{x1:"10",y1:"7",x2:"14",y2:"7"}),n.jsx("line",{x1:"10",y1:"17",x2:"14",y2:"17"})]}),n.jsx("span",{style:{marginLeft:"4px"},children:"-"})]}),n.jsxs("div",{style:{display:"inline-flex",alignItems:"center",padding:"5px 10px",fontSize:"12px",background:"#f8f8f8",borderRadius:"4px",margin:"0 4px",border:"1px solid #ddd"},children:[r,"px"]}),n.jsxs(B.ControlButton,{onClick:()=>d(Math.min(300,r+25)),title:"Increase node spacing",children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"}),n.jsx("line",{x1:"7",y1:"10",x2:"7",y2:"14"}),n.jsx("line",{x1:"17",y1:"10",x2:"17",y2:"14"}),n.jsx("line",{x1:"10",y1:"7",x2:"14",y2:"7"}),n.jsx("line",{x1:"10",y1:"17",x2:"14",y2:"17"})]}),n.jsx("span",{style:{marginLeft:"4px"},children:"+"})]}),n.jsx("div",{style:{display:"inline-block",width:"1px",height:"24px",background:"#ddd",margin:"0 10px"}}),n.jsxs(B.ControlButton,{onClick:()=>l(Math.max(50,e-25)),title:"Decrease layer spacing",children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),n.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),n.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),n.jsx("span",{style:{marginLeft:"4px"},children:"-"})]}),n.jsxs("div",{style:{display:"inline-flex",alignItems:"center",padding:"5px 10px",fontSize:"12px",background:"#f8f8f8",borderRadius:"4px",margin:"0 4px",border:"1px solid #ddd"},children:[e,"px"]}),n.jsxs(B.ControlButton,{onClick:()=>l(Math.min(300,e+25)),title:"Increase layer spacing",children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"2",fill:"none",children:[n.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),n.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),n.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),n.jsx("span",{style:{marginLeft:"4px"},children:"+"})]})]})},Q=({compact:t=!1})=>{const{autoLayout:r,setAutoLayout:e}=P(),o=()=>{e(!r)};return n.jsx(B.ControlButton,{onClick:o,className:r?"selected":"",title:r?"Disable automatic layout":"Enable automatic layout",style:{color:r?"green":"inherit"},children:t?n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"1.5",fill:"none",children:[n.jsx("rect",{x:"4",y:"4",width:"4",height:"4",rx:"1"}),n.jsx("rect",{x:"4",y:"16",width:"4",height:"4",rx:"1"}),n.jsx("rect",{x:"16",y:"10",width:"4",height:"4",rx:"1"}),n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M8 6c6 0 3 8 8 6"}),n.jsx("path",{d:"M8 18c3-3 2-8 6-6"})]})]}):n.jsxs(n.Fragment,{children:["Auto-Layout ",r?"ON":"OFF"]})})},ft=({compact:t=!1})=>{const{layoutInProgress:r,setLayoutInProgress:e,applyLayout:o}=P(),s=async()=>{if(!r)try{e(!0),await o()}catch(i){console.error("Error applying layout:",i)}};return n.jsxs(B.ControlButton,{onClick:s,title:"Apply layout",disabled:r,style:{color:r?"#999":"#000"},children:[n.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16",stroke:"currentColor",strokeWidth:"1.5",fill:"none",children:[n.jsx("rect",{x:"3",y:"3",width:"5",height:"5",rx:"1"}),n.jsx("rect",{x:"16",y:"3",width:"5",height:"5",rx:"1"}),n.jsx("rect",{x:"3",y:"16",width:"5",height:"5",rx:"1"}),n.jsx("rect",{x:"16",y:"16",width:"5",height:"5",rx:"1"}),n.jsx("path",{d:"M8 5.5h8M5.5 8v8M18.5 8v8M8 18.5h8"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"}),n.jsx("path",{d:"M11 10.5v3l2-1.5z",fill:"currentColor"})]}),!t&&n.jsx("span",{style:{marginLeft:"4px"},children:"Apply Layout"})]})},Xt=({showDirectionControls:t=!0,showSpacingControls:r=!0,showAutoLayoutToggle:e=!0,showApplyLayoutButton:o=!0,standalone:s=!1,position:i="top-right"})=>{const h=P(),{autoLayout:a}=h;return s?n.jsxs(B.Controls,{position:i,showZoom:!1,showFitView:!1,showInteractive:!1,children:[o&&!a&&n.jsx(ft,{compact:!0}),t&&n.jsx(J,{compact:!0}),r&&n.jsx(Z,{compact:!0}),e&&n.jsx(Q,{compact:!0})]}):n.jsxs(n.Fragment,{children:[o&&!a&&n.jsx(ft,{compact:!0}),t&&n.jsx(J,{compact:!0}),r&&n.jsx(Z,{compact:!0}),e&&n.jsx(Q,{compact:!0})]})};M.AutoLayoutToggle=Q,M.DagreEngine=it,M.DirectionControls=J,M.LayoutControls=Xt,M.LayoutProvider=jt,M.SpacingControls=Z,M.engines=ct,M.useLayoutContext=P,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED