epic-designer-gold
Version:
基于vue3的设计器,可视化开发页面表单
5 lines (4 loc) • 11.9 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./mermaid.core-amipJqhv.cjs"),P=require("./graph-CxxKh2B7.cjs"),R=require("./layout-BtHFUxYL.cjs"),_=require("./_baseUniq-DeWnvPnf.cjs"),M=require("./clone-C6ujOTzW.cjs"),O=require("./_basePickBy-B5X14NqN.cjs");function E(e){var o={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:q(e),edges:j(e)};return _.isUndefined(e.graph())||(o.value=M.clone(e.graph())),o}function q(e){return O.map(e.nodes(),function(o){var n=e.node(o),s=e.parent(o),c={v:o};return _.isUndefined(n)||(c.value=n),_.isUndefined(s)||(c.parent=s),c})}function j(e){return O.map(e.edges(),function(o){var n=e.edge(o),s={v:o.v,w:o.w};return _.isUndefined(o.name)||(s.name=o.name),_.isUndefined(n)||(s.value=n),s})}var f=new Map,b=new Map,k=new Map,U=t.__name(()=>{b.clear(),k.clear(),f.clear()},"clear"),x=t.__name((e,o)=>{const n=b.get(o)||[];return t.log.trace("In isDescendant",o," ",e," = ",n.includes(e)),n.includes(e)},"isDescendant"),F=t.__name((e,o)=>{const n=b.get(o)||[];return t.log.info("Descendants of ",o," is ",n),t.log.info("Edge is ",e),e.v===o||e.w===o?!1:n?n.includes(e.v)||x(e.v,o)||x(e.w,o)||n.includes(e.w):(t.log.debug("Tilt, ",o,",not in descendants"),!1)},"edgeInCluster"),B=t.__name((e,o,n,s)=>{t.log.warn("Copying children of ",e,"root",s,"data",o.node(e),s);const c=o.children(e)||[];e!==s&&c.push(e),t.log.warn("Copying (nodes) clusterId",e,"nodes",c),c.forEach(l=>{if(o.children(l).length>0)B(l,o,n,s);else{const r=o.node(l);t.log.info("cp ",l," to ",s," with parent ",e),n.setNode(l,r),s!==o.parent(l)&&(t.log.warn("Setting parent",l,o.parent(l)),n.setParent(l,o.parent(l))),e!==s&&l!==e?(t.log.debug("Setting parent",l,e),n.setParent(l,e)):(t.log.info("In copy ",e,"root",s,"data",o.node(e),s),t.log.debug("Not Setting parent for node=",l,"cluster!==rootId",e!==s,"node!==clusterId",l!==e));const g=o.edges(l);t.log.debug("Copying Edges",g),g.forEach(d=>{t.log.info("Edge",d);const v=o.edge(d.v,d.w,d.name);t.log.info("Edge data",v,s);try{F(d,s)?(t.log.info("Copying as ",d.v,d.w,v,d.name),n.setEdge(d.v,d.w,v,d.name),t.log.info("newGraph edges ",n.edges(),n.edge(n.edges()[0]))):t.log.info("Skipping copy of edge ",d.v,"-->",d.w," rootId: ",s," clusterId:",e)}catch(p){t.log.error(p)}})}t.log.debug("Removing node",l),o.removeNode(l)})},"copy"),A=t.__name((e,o)=>{const n=o.children(e);let s=[...n];for(const c of n)k.set(c,e),s=[...s,...A(c,o)];return s},"extractDescendants"),Y=t.__name((e,o,n)=>{const s=e.edges().filter(d=>d.v===o||d.w===o),c=e.edges().filter(d=>d.v===n||d.w===n),l=s.map(d=>({v:d.v===o?n:d.v,w:d.w===o?o:d.w})),r=c.map(d=>({v:d.v,w:d.w}));return l.filter(d=>r.some(v=>d.v===v.v&&d.w===v.w))},"findCommonEdges"),S=t.__name((e,o,n)=>{const s=o.children(e);if(t.log.trace("Searching children of id ",e,s),s.length<1)return e;let c;for(const l of s){const r=S(l,o,n),g=Y(o,n,r);if(r)if(g.length>0)c=r;else return r}return c},"findNonClusterChild"),D=t.__name(e=>!f.has(e)||!f.get(e).externalConnections?e:f.has(e)?f.get(e).id:e,"getAnchorId"),H=t.__name((e,o)=>{if(!e||o>10){t.log.debug("Opting out, no graph ");return}else t.log.debug("Opting in, graph ");e.nodes().forEach(function(n){e.children(n).length>0&&(t.log.warn("Cluster identified",n," Replacement id in edges: ",S(n,e,n)),b.set(n,A(n,e)),f.set(n,{id:S(n,e,n),clusterData:e.node(n)}))}),e.nodes().forEach(function(n){const s=e.children(n),c=e.edges();s.length>0?(t.log.debug("Cluster identified",n,b),c.forEach(l=>{const r=x(l.v,n),g=x(l.w,n);r^g&&(t.log.warn("Edge: ",l," leaves cluster ",n),t.log.warn("Descendants of XXX ",n,": ",b.get(n)),f.get(n).externalConnections=!0)})):t.log.debug("Not a cluster ",n,b)});for(let n of f.keys()){const s=f.get(n).id,c=e.parent(s);c!==n&&f.has(c)&&!f.get(c).externalConnections&&(f.get(n).id=c)}e.edges().forEach(function(n){const s=e.edge(n);t.log.warn("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(n)),t.log.warn("Edge "+n.v+" -> "+n.w+": "+JSON.stringify(e.edge(n)));let c=n.v,l=n.w;if(t.log.warn("Fix XXX",f,"ids:",n.v,n.w,"Translating: ",f.get(n.v)," --- ",f.get(n.w)),f.get(n.v)||f.get(n.w)){if(t.log.warn("Fixing and trying - removing XXX",n.v,n.w,n.name),c=D(n.v),l=D(n.w),e.removeEdge(n.v,n.w,n.name),c!==n.v){const r=e.parent(c);f.get(r).externalConnections=!0,s.fromCluster=n.v}if(l!==n.w){const r=e.parent(l);f.get(r).externalConnections=!0,s.toCluster=n.w}t.log.warn("Fix Replacing with XXX",c,l,n.name),e.setEdge(c,l,s,n.name)}}),t.log.warn("Adjusted Graph",E(e)),J(e,0),t.log.trace(f)},"adjustClustersAndEdges"),J=t.__name((e,o)=>{var c,l;if(t.log.warn("extractor - ",o,E(e),e.children("D")),o>10){t.log.error("Bailing out");return}let n=e.nodes(),s=!1;for(const r of n){const g=e.children(r);s=s||g.length>0}if(!s){t.log.debug("Done, no node has children",e.nodes());return}t.log.debug("Nodes = ",n,o);for(const r of n)if(t.log.debug("Extracting node",r,f,f.has(r)&&!f.get(r).externalConnections,!e.parent(r),e.node(r),e.children("D")," Depth ",o),!f.has(r))t.log.debug("Not a cluster",r,o);else if(!f.get(r).externalConnections&&e.children(r)&&e.children(r).length>0){t.log.warn("Cluster without external connections, without a parent and with children",r,o);let d=e.graph().rankdir==="TB"?"LR":"TB";(l=(c=f.get(r))==null?void 0:c.clusterData)!=null&&l.dir&&(d=f.get(r).clusterData.dir,t.log.warn("Fixing dir",f.get(r).clusterData.dir,d));const v=new P.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:d,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});t.log.warn("Old graph before copy",E(e)),B(r,e,v,r),e.setNode(r,{clusterNode:!0,id:r,clusterData:f.get(r).clusterData,label:f.get(r).label,graph:v}),t.log.warn("New graph after copy node: (",r,")",E(v)),t.log.debug("Old graph after copy",E(e))}else t.log.warn("Cluster ** ",r," **not meeting the criteria !externalConnections:",!f.get(r).externalConnections," no parent: ",!e.parent(r)," children ",e.children(r)&&e.children(r).length>0,e.children("D"),o),t.log.debug(f);n=e.nodes(),t.log.warn("New list of nodes",n);for(const r of n){const g=e.node(r);t.log.warn(" Now next level",r,g),g!=null&&g.clusterNode&&J(g.graph,o+1)}},"extractor"),T=t.__name((e,o)=>{if(o.length===0)return[];let n=Object.assign([],o);return o.forEach(s=>{const c=e.children(s),l=T(e,c);n=[...n,...l]}),n},"sorter"),V=t.__name(e=>T(e,e.children()),"sortNodesByHierarchy"),G=t.__name(async(e,o,n,s,c,l)=>{t.log.warn("Graph in recursive render:XAX",E(o),c);const r=o.graph().rankdir;t.log.trace("Dir in recursive render - dir:",r);const g=e.insert("g").attr("class","root");o.nodes()?t.log.info("Recursive render XXX",o.nodes()):t.log.info("No nodes found for",o),o.edges().length>0&&t.log.info("Recursive edges",o.edge(o.edges()[0]));const d=g.insert("g").attr("class","clusters"),v=g.insert("g").attr("class","edgePaths"),p=g.insert("g").attr("class","edgeLabels"),u=g.insert("g").attr("class","nodes");await Promise.all(o.nodes().map(async function(a){const i=o.node(a);if(c!==void 0){const w=JSON.parse(JSON.stringify(c.clusterData));t.log.trace(`Setting data for parent cluster XXX
Node.id = `,a,`
data=`,w.height,`
Parent cluster`,c.height),o.setNode(c.id,w),o.parent(a)||(t.log.trace("Setting parent",a,c.id),o.setParent(a,c.id,w))}if(t.log.info("(Insert) Node XXX"+a+": "+JSON.stringify(o.node(a))),i!=null&&i.clusterNode){t.log.info("Cluster identified XBX",a,i.width,o.node(a));const{ranksep:w,nodesep:m}=o.graph();i.graph.setGraph({...i.graph.graph(),ranksep:w+25,nodesep:m});const N=await G(u,i.graph,n,s,o.node(a),l),C=N.elem;t.updateNodeBounds(i,C),i.diff=N.diff||0,t.log.info("New compound node after recursive render XAX",a,"width",i.width,"height",i.height),t.setNodeElem(C,i)}else o.children(a).length>0?(t.log.trace("Cluster - the non recursive path XBX",a,i.id,i,i.width,"Graph:",o),t.log.trace(S(i.id,o)),f.set(i.id,{id:S(i.id,o),node:i})):(t.log.trace("Node - the non recursive path XAX",a,u,o.node(a),r),await t.insertNode(u,o.node(a),{config:l,dir:r}))})),await t.__name(async()=>{const a=o.edges().map(async function(i){const w=o.edge(i.v,i.w,i.name);t.log.info("Edge "+i.v+" -> "+i.w+": "+JSON.stringify(i)),t.log.info("Edge "+i.v+" -> "+i.w+": ",i," ",JSON.stringify(o.edge(i))),t.log.info("Fix",f,"ids:",i.v,i.w,"Translating: ",f.get(i.v),f.get(i.w)),await t.insertEdgeLabel(p,w)});await Promise.all(a)},"processEdges")(),t.log.info("Graph before layout:",JSON.stringify(E(o))),t.log.info("############################################# XXX"),t.log.info("### Layout ### XXX"),t.log.info("############################################# XXX"),R.layout(o),t.log.info("Graph after layout:",JSON.stringify(E(o)));let X=0,{subGraphTitleTotalMargin:y}=t.getSubGraphTitleMargins(l);return await Promise.all(V(o).map(async function(a){var w;const i=o.node(a);if(t.log.info("Position XBX => "+a+": ("+i.x,","+i.y,") width: ",i.width," height: ",i.height),i!=null&&i.clusterNode)i.y+=y,t.log.info("A tainted cluster node XBX1",a,i.id,i.width,i.height,i.x,i.y,o.parent(a)),f.get(i.id).node=i,t.positionNode(i);else if(o.children(a).length>0){t.log.info("A pure cluster node XBX1",a,i.id,i.x,i.y,i.width,i.height,o.parent(a)),i.height+=y,o.node(i.parentId);const m=(i==null?void 0:i.padding)/2||0,N=((w=i==null?void 0:i.labelBBox)==null?void 0:w.height)||0,C=N-m||0;t.log.debug("OffsetY",C,"labelHeight",N,"halfPadding",m),await t.insertCluster(d,i),f.get(i.id).node=i}else{const m=o.node(i.parentId);i.y+=y/2,t.log.info("A regular node XBX1 - using the padding",i.id,"parent",i.parentId,i.width,i.height,i.x,i.y,"offsetY",i.offsetY,"parent",m,m==null?void 0:m.offsetY,i),t.positionNode(i)}})),o.edges().forEach(function(a){const i=o.edge(a);t.log.info("Edge "+a.v+" -> "+a.w+": "+JSON.stringify(i),i),i.points.forEach(C=>C.y+=y/2);const w=o.node(a.v);var m=o.node(a.w);const N=t.insertEdge(v,i,f,n,w,m,s);t.positionEdgeLabel(i,N)}),o.nodes().forEach(function(a){const i=o.node(a);t.log.info(a,i.type,i.diff),i.isGroup&&(X=i.diff)}),t.log.warn("Returning from recursive render XAX",g,X),{elem:g,diff:X}},"recursiveRender"),z=t.__name(async(e,o)=>{var l,r,g,d,v,p;const n=new P.Graph({multigraph:!0,compound:!0}).setGraph({rankdir:e.direction,nodesep:((l=e.config)==null?void 0:l.nodeSpacing)||((g=(r=e.config)==null?void 0:r.flowchart)==null?void 0:g.nodeSpacing)||e.nodeSpacing,ranksep:((d=e.config)==null?void 0:d.rankSpacing)||((p=(v=e.config)==null?void 0:v.flowchart)==null?void 0:p.rankSpacing)||e.rankSpacing,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}}),s=o.select("g");t.markers_default(s,e.markers,e.type,e.diagramId),t.clear2(),t.clear$1(),t.clear$2(),U(),e.nodes.forEach(u=>{n.setNode(u.id,{...u}),u.parentId&&n.setParent(u.id,u.parentId)}),t.log.debug("Edges:",e.edges),e.edges.forEach(u=>{if(u.start===u.end){const h=u.start,X=h+"---"+h+"---1",y=h+"---"+h+"---2",a=n.node(h);n.setNode(X,{domId:X,id:X,parentId:a.parentId,labelStyle:"",label:"",padding:0,shape:"labelRect",style:"",width:10,height:10}),n.setParent(X,a.parentId),n.setNode(y,{domId:y,id:y,parentId:a.parentId,labelStyle:"",padding:0,shape:"labelRect",label:"",style:"",width:10,height:10}),n.setParent(y,a.parentId);const i=structuredClone(u),w=structuredClone(u),m=structuredClone(u);i.label="",i.arrowTypeEnd="none",i.id=h+"-cyclic-special-1",w.arrowTypeStart="none",w.arrowTypeEnd="none",w.id=h+"-cyclic-special-mid",m.label="",a.isGroup&&(i.fromCluster=h,m.toCluster=h),m.id=h+"-cyclic-special-2",m.arrowTypeStart="none",n.setEdge(h,X,i,h+"-cyclic-special-0"),n.setEdge(X,y,w,h+"-cyclic-special-1"),n.setEdge(y,h,m,h+"-cyc<lic-special-2")}else n.setEdge(u.start,u.end,{...u},u.id)}),t.log.warn("Graph at first:",JSON.stringify(E(n))),H(n),t.log.warn("Graph after XAX:",JSON.stringify(E(n)));const c=t.getConfig2();await G(s,n,e.type,e.diagramId,void 0,c)},"render");exports.render=z;