UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

112 lines (111 loc) 3.6 kB
import { jsx as n, jsxs as p } from "react/jsx-runtime"; import { Position as i, MarkerType as m, ConnectionLineType as u } from "reactflow"; import { ActivityNodeLabel as f } from "./ActivityNodeLabel.js"; import { EntityNodeLabel as h } from "./EntityNodeLabel.js"; import { ExpandGraphNodeLabel as y } from "./ExpandGraphNodeLabel.js"; import { ExternalGraphNodeLabel as b } from "./ExternalGraphNodeLabel.js"; import N from "dagre"; import { differenceWith as g, isEqual as x } from "lodash-es"; import { UndefinedNodeLabel as L } from "./UndefinedNodeLabel.js"; import { EntityPlaceholderNodeLabel as $ } from "./EntityPlaceholderNodeLabel.js"; var P = /* @__PURE__ */ ((e) => (e.ENTITY = "EntityNode", e.ENTITY_PLACEHOLDER = "EntityPlaceholderNode", e.EXTERNAL = "ExternalNode", e.ACTIVITY = "ActivityNode", e.EXPAND = "ExpandNode", e.UNDEFINED = "UndefinedNode", e))(P || {}); const C = (e) => { const { type: a, data: t } = e; let o; switch (a) { case "EntityNode": o = /* @__PURE__ */ n(h, { ...t }); break; case "EntityPlaceholderNode": o = /* @__PURE__ */ n($, { ...t }); break; case "ExternalNode": o = /* @__PURE__ */ n(b, { ...t }); break; case "ActivityNode": o = /* @__PURE__ */ n(f, { ...t }); break; case "ExpandNode": o = /* @__PURE__ */ n(y, { ...t }); break; case "UndefinedNode": o = /* @__PURE__ */ n(L, {}); break; default: o = /* @__PURE__ */ p("p", { children: [ "Unrecognized node type: ", a ] }); break; } const r = { label: o, props: t, type: a }; return { id: s(e), position: { x: 100, y: 100 }, // hard coded, let graph layout library figure this out data: r, connectable: !1, draggable: !1, // selectable: false, // like to make unselectable, but node contents become non-interactive className: `${a}` }; }, R = (e, a) => { const t = s(e), o = s(a); return { id: `${t}-${o}`, source: t, target: o, animated: !0, type: u.SimpleBezier, markerEnd: { type: m.ArrowClosed } }; }, s = (e) => { const { type: a, data: t } = e; switch (a) { case "EntityNode": return `${t.id}.${t.versionNumber ?? "latest"}`; case "EntityPlaceholderNode": return `${t.targetId}.${t.targetVersionNumber ?? "latest"}`; case "ExternalNode": return `${t.url}`; case "ActivityNode": return `${t.id}`; case "ExpandNode": return `expand.node.${t.entityHeader.id}.${t.entityHeader.versionNumber ?? "latest"}`; case "UndefinedNode": return `undefined.dummy.node.${t.id}.${t.versionNumber ?? "latest"}`; } }, d = new N.graphlib.Graph(); d.setDefaultEdgeLabel(() => ({})); const l = (e) => e.data.type == "ExpandNode" ? 30 : 100, E = (e) => e.data.type == "ExpandNode" ? 30 : 172, z = (e, a, t) => { const o = t === "LR"; return d.setGraph({ rankdir: t }), e.forEach((r) => { d.setNode(r.id, { width: E(r), height: l(r) }); }), a.forEach((r) => { d.setEdge(r.source, r.target); }), N.layout(d), e.forEach((r) => { const c = d.node(r.id); return r.targetPosition = o ? i.Left : i.Top, r.sourcePosition = o ? i.Right : i.Bottom, r.position = { x: c.x - E(r) / 2, y: c.y - l(r) / 2 }, r; }), { nodes: e, edges: a }; }, W = (e, a) => g(e, a, x).length == 0; export { P as NodeType, z as getLayoutedElements, s as getNodeId, R as getProvenanceEdge, C as getProvenanceNode, W as isArrayEqual }; //# sourceMappingURL=ProvenanceUtils.js.map