@eventcatalog/visualiser 5.0.0 → 5.0.1

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.
@@ -239,6 +239,10 @@ var layoutWithElk = async ({ nodes, edges }, { sizeOf = getNodeSize } = {}) => {
239
239
  const elkNode = laidOut.get(nodeId);
240
240
  return { x: offset.x + (elkNode?.x ?? 0), y: offset.y + (elkNode?.y ?? 0) };
241
241
  };
242
+ const laidOutAt = (nodeId) => ({
243
+ ...absolute(nodeId),
244
+ height: laidOut.get(nodeId)?.height
245
+ });
242
246
  const routes = /* @__PURE__ */ new Map();
243
247
  (layout.edges || []).forEach((elkEdge) => {
244
248
  const section = elkEdge.sections?.[0];
@@ -255,8 +259,8 @@ var layoutWithElk = async ({ nodes, edges }, { sizeOf = getNodeSize } = {}) => {
255
259
  x: (label.x ?? 0) + (label.width ?? 0) / 2,
256
260
  y: (label.y ?? 0) + (label.height ?? 0) / 2
257
261
  } : void 0,
258
- source: absolute(edge.source),
259
- target: absolute(edge.target)
262
+ source: laidOutAt(edge.source),
263
+ target: laidOutAt(edge.target)
260
264
  });
261
265
  });
262
266
  const depth = (node) => {
@@ -461,4 +465,4 @@ export {
461
465
  hideNodes,
462
466
  hideMessageNodes
463
467
  };
464
- //# sourceMappingURL=chunk-Z3G354GF.mjs.map
468
+ //# sourceMappingURL=chunk-NOHQEQD7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/nodes/node-types.ts","../src/utils/utils/utils.ts","../src/utils/elk-layout.ts","../src/utils/hide-messages.ts"],"sourcesContent":["export const SERVICE = [\"service\", \"services\"];\nexport const AGENT = [\"agent\", \"agents\"];\nexport const AGENT_TOOL = [\"agentTool\", \"agent-tool\"];\nexport const EVENT = [\"event\", \"events\"];\nexport const QUERY = [\"queries\", \"query\", \"querie\"];\nexport const COMMAND = [\"command\", \"commands\"];\nexport const CHANNEL = [\"channel\", \"channels\"];\nexport const ACTOR = [\"actor\", \"actors\"];\nexport const DATA = [\"data\"];\nexport const VIEW = [\"view\"];\n\nexport const MESSAGE = [...EVENT, ...COMMAND, ...QUERY];\n","// Can't use the CollectionEntry type from astro:content because a client component is using this util\n\nimport { MarkerType, Position, type Edge, type Node } from \"@xyflow/react\";\n\ninterface BaseCollectionData {\n id: string;\n version: string;\n}\n\ninterface CollectionItem {\n collection: string;\n data: BaseCollectionData;\n}\n\ninterface MessageCollectionItem extends CollectionItem {\n collection: \"commands\" | \"events\" | \"queries\";\n}\n\nexport const generateIdForNode = (node: CollectionItem) => {\n return `${node.data.id}-${node.data.version}`;\n};\nexport const generateIdForNodes = (nodes: any) => {\n return nodes\n .map((node: any) => `${node.data.id}-${node.data.version}`)\n .join(\"-\");\n};\nexport const generatedIdForEdge = (\n source: CollectionItem,\n target: CollectionItem,\n) => {\n return `${source.data.id}-${source.data.version}-${target.data.id}-${target.data.version}`;\n};\n\nexport const getColorFromString = (id: string) => {\n // Takes the given id (string) and returns a custom hex color based on the id\n // Create a hash from the string\n let hash = 0;\n for (let i = 0; i < id.length; i++) {\n hash = id.charCodeAt(i) + ((hash << 5) - hash);\n }\n\n // Convert the hash into a hex color\n let color = \"#\";\n for (let i = 0; i < 3; i++) {\n const value = (hash >> (i * 8)) & 0xff;\n color += value.toString(16).padStart(2, \"0\");\n }\n\n return color;\n};\n\nexport const getEdgeLabelForServiceAsTarget = (data: MessageCollectionItem) => {\n const type = data.collection;\n switch (type) {\n case \"commands\":\n return \"invokes\";\n case \"events\":\n return \"publishes \\nevent\";\n case \"queries\":\n return \"requests\";\n default:\n return \"sends to\";\n }\n};\nexport const getEdgeLabelForMessageAsSource = (\n data: MessageCollectionItem,\n throughChannel = false,\n) => {\n const type = data.collection;\n switch (type) {\n case \"commands\":\n return \"accepts\";\n case \"events\":\n return throughChannel ? \"subscribed to\" : \"subscribed by\";\n case \"queries\":\n return \"accepts\";\n default:\n return \"sends to\";\n }\n};\n\n/**\n * Rough size of an edge label, so the layout can leave room for it on its edge\n */\nexport const getEdgeLabelSize = (label: unknown) => {\n if (typeof label !== \"string\" || !label.trim())\n return { width: 0, height: 0 };\n const lines = label.split(\"\\n\");\n const longestLine = Math.max(...lines.map((line) => line.trim().length));\n return { width: longestLine * 6 + 20, height: lines.length * 14 + 12 };\n};\n\nexport const createEdge = (edgeOptions: Edge): Edge => {\n return {\n label: \"subscribed by\",\n animated: false,\n // markerStart: {\n // type: MarkerType.Arrow,\n // width: 40,\n // height: 40,\n // },\n markerEnd: {\n type: MarkerType.ArrowClosed,\n width: 40,\n height: 40,\n color: \"rgb(var(--ec-page-text-muted))\",\n },\n style: {\n strokeWidth: 1.5,\n stroke: \"rgb(var(--ec-page-text-muted))\",\n strokeDasharray: \"5 5\",\n },\n ...edgeOptions,\n };\n};\n\nexport const createNode = (values: Node): Node => {\n return {\n sourcePosition: Position.Right,\n targetPosition: Position.Left,\n ...values,\n };\n};\n","import type { Edge, Node } from \"@xyflow/react\";\nimport type {\n ELK,\n ElkExtendedEdge,\n ElkNode,\n ElkPort,\n LayoutOptions,\n} from \"elkjs/lib/elk-api\";\nimport { getEdgeLabelSize } from \"./utils/utils\";\n\nexport type LayoutGraph = { nodes: Node[]; edges: Edge[] };\nexport type LayoutSize = { width: number; height: number };\nexport type EdgeRoute = {\n points: { x: number; y: number }[];\n label?: { x: number; y: number };\n /**\n * Where the edge's source and target were laid out (top-left, in the flow),\n * and how tall: nodes often render shorter than the layout estimated\n */\n source?: { x: number; y: number; height?: number };\n target?: { x: number; y: number; height?: number };\n};\n\n/**\n * A route copied to another canvas (e.g. a diagram opened in Studio), which\n * places the nodes itself: where it goes, and how tall its nodes were laid out\n */\nexport type CopiedEdgeRoute = Pick<EdgeRoute, \"points\" | \"label\"> & {\n sourceHeight?: number;\n targetHeight?: number;\n};\n\n// The size each node type renders at (at most), for nodes that haven't been\n// rendered (and measured) yet, e.g. when laying a graph out on the server\nconst DEFAULT_SIZE: LayoutSize = { width: 240, height: 112 };\nconst NODE_SIZES: Record<string, LayoutSize> = {\n events: { width: 240, height: 104 },\n commands: { width: 240, height: 126 },\n queries: { width: 240, height: 126 },\n services: { width: 240, height: 112 },\n data: { width: 240, height: 108 },\n systems: { width: 240, height: 120 },\n system: { width: 240, height: 120 },\n \"context-domain\": { width: 240, height: 112 },\n \"context-actor\": { width: 180, height: 80 },\n actor: { width: 180, height: 80 },\n note: { width: 200, height: 150 },\n step: { width: 240, height: 80 },\n // Groups with nothing in them (groups with children are sized to fit them)\n \"domain-group\": { width: 320, height: 160 },\n \"system-group\": { width: 320, height: 160 },\n};\n\n// Nodes sized by their style, like groups: an empty one needs a size too\nconst GROUP_TYPES = new Set([\"domain-group\", \"system-group\", \"group\"]);\n\n/** The size a node is laid out at: as rendered, or an estimate for its type */\nexport const getNodeSize = (node: Node): LayoutSize => {\n if (node.measured?.width && node.measured?.height) {\n return { width: node.measured.width, height: node.measured.height };\n }\n if (typeof node.width === \"number\" && typeof node.height === \"number\") {\n return { width: node.width, height: node.height };\n }\n // Domains list their services, so grow with them\n if (node.type === \"domains\" || node.type === \"domain\") {\n const services = (node.data as any)?.domain?.data?.services || [];\n return { width: 260, height: 60 + services.length * 40 };\n }\n return NODE_SIZES[node.type || \"\"] ?? DEFAULT_SIZE;\n};\n\n// Room for a group's header above its children\nconst GROUP_PADDING = \"[top=100,left=40,bottom=40,right=40]\";\n\n// Space between nodes and edges. Set on every group as well as the graph, as\n// groups don't take it from the graph (they'd use ELK's much tighter defaults)\nconst SPACING = {\n \"elk.layered.spacing.nodeNodeBetweenLayers\": \"60\",\n \"elk.spacing.nodeNode\": \"40\",\n \"elk.spacing.edgeNode\": \"25\",\n \"elk.spacing.edgeEdge\": \"15\",\n};\n\n// Large graphs (e.g. a big domain) use cheaper settings: the nicest node\n// placement takes minutes on a few thousand edges, these take a second or two\nconst LARGE_GRAPH_NODES = 80;\nconst LARGE_GRAPH_EDGES = 200;\nconst LARGE_GRAPH_OPTIONS: LayoutOptions = {\n \"elk.layered.nodePlacement.strategy\": \"BRANDES_KOEPF\",\n \"elk.layered.thoroughness\": \"1\",\n \"elk.layered.crossingMinimization.greedySwitch.type\": \"OFF\",\n};\n\nlet elk: ELK | undefined;\n// Loaded when first needed, so pages that never lay out in the browser don't download it\nconst getElk = async () => {\n if (!elk) {\n const { default: ELK } = await import(\"elkjs/lib/elk.bundled.js\");\n elk = new ELK();\n }\n return elk;\n};\n\n/**\n * Lays a graph out with ELK (left to right). Nested groups (nodes other nodes\n * have as their `parentId`) are laid out in one pass with their children.\n * Edges are routed at right angles around nodes, each edge with its own\n * connection point so edges don't run on top of each other, and labels are\n * placed on their edge. Each edge keeps its type and gets its route (and label\n * position) in `data.route`, which the visualiser's edges are drawn along.\n *\n * Node positions are top-left corners (nodes get `origin: [0, 0]`), children\n * relative to their group. Groups are sized to fit their children.\n */\nexport const layoutWithElk = async (\n { nodes, edges }: LayoutGraph,\n { sizeOf = getNodeSize }: { sizeOf?: (node: Node) => LayoutSize } = {},\n): Promise<LayoutGraph> => {\n const nodesById = new Map(nodes.map((node) => [node.id, node]));\n const groupIds = new Set(\n nodes\n .map((node) => node.parentId)\n .filter((id): id is string => !!id && nodesById.has(id)),\n );\n const parentOf = (node: Node) =>\n node.parentId && groupIds.has(node.parentId) ? node.parentId : undefined;\n\n // Each edge gets its own port, leaving from the right of its source and\n // arriving at the left of its target, so ELK spreads edges out along a\n // node's side rather than routing them all through one point. Edges to a\n // specific handle (e.g. a service listed in a domain) share that handle's port.\n const layoutEdges = edges.filter(\n (edge) => nodesById.has(edge.source) && nodesById.has(edge.target),\n );\n const ports = new Map<string, ElkPort[]>();\n const addPort = (\n nodeId: string,\n id: string,\n side: \"EAST\" | \"WEST\",\n ): string => {\n const nodePorts = ports.get(nodeId) || [];\n if (!nodePorts.some((port) => port.id === id)) {\n ports.set(nodeId, [\n ...nodePorts,\n { id, layoutOptions: { \"elk.port.side\": side } },\n ]);\n }\n return id;\n };\n const edgePorts = layoutEdges.map((edge, index) => ({\n source: addPort(\n edge.source,\n edge.sourceHandle\n ? `${edge.source}__${edge.sourceHandle}`\n : `e${index}__out`,\n \"EAST\",\n ),\n target: addPort(\n edge.target,\n edge.targetHandle\n ? `${edge.target}__${edge.targetHandle}`\n : `e${index}__in`,\n \"WEST\",\n ),\n }));\n\n const toElkNode = (node: Node): ElkNode => ({\n id: node.id,\n ...(groupIds.has(node.id)\n ? {\n children: nodes\n .filter((child) => parentOf(child) === node.id)\n .map(toElkNode),\n }\n : sizeOf(node)),\n layoutOptions: {\n \"elk.portConstraints\": \"FIXED_SIDE\",\n ...(groupIds.has(node.id)\n ? { \"elk.padding\": GROUP_PADDING, ...SPACING }\n : {}),\n // A node's own options (e.g. a group's padding) win\n ...((node.data as { layoutOptions?: LayoutOptions } | undefined)\n ?.layoutOptions ?? {}),\n },\n ports: ports.get(node.id) || [],\n });\n\n const layout = await (\n await getElk()\n ).layout({\n id: \"root\",\n layoutOptions: {\n \"elk.algorithm\": \"layered\",\n \"elk.direction\": \"RIGHT\",\n \"elk.hierarchyHandling\": \"INCLUDE_CHILDREN\",\n \"elk.edgeRouting\": \"ORTHOGONAL\",\n // Edge routes in absolute coordinates (node positions stay relative to their parent)\n \"elk.json.edgeCoords\": \"ROOT\",\n \"elk.edgeLabels.placement\": \"CENTER\",\n ...SPACING,\n ...(nodes.length >= LARGE_GRAPH_NODES || edges.length >= LARGE_GRAPH_EDGES\n ? LARGE_GRAPH_OPTIONS\n : { \"elk.layered.nodePlacement.strategy\": \"NETWORK_SIMPLEX\" }),\n },\n children: nodes.filter((node) => !parentOf(node)).map(toElkNode),\n edges: layoutEdges.map((edge, index) => ({\n id: `e${index}`,\n sources: [edgePorts[index].source],\n targets: [edgePorts[index].target],\n // Labels sit on their edge, rather than beside it (only works set per label)\n labels: edge.label\n ? [\n {\n text: String(edge.label),\n ...getEdgeLabelSize(edge.label),\n layoutOptions: { \"elk.edgeLabels.inline\": \"true\" },\n },\n ]\n : [],\n })),\n });\n\n const laidOut = new Map<string, ElkNode>();\n const collect = (elkNode: ElkNode) =>\n (elkNode.children || []).forEach((child) => {\n laidOut.set(child.id, child);\n collect(child);\n });\n collect(layout);\n\n // Where a node was laid out in the flow (ELK positions are relative to the parent)\n const absolute = (nodeId: string): { x: number; y: number } => {\n const node = nodesById.get(nodeId);\n const parent = node && parentOf(node);\n const offset = parent ? absolute(parent) : { x: 0, y: 0 };\n const elkNode = laidOut.get(nodeId);\n return { x: offset.x + (elkNode?.x ?? 0), y: offset.y + (elkNode?.y ?? 0) };\n };\n\n const laidOutAt = (nodeId: string) => ({\n ...absolute(nodeId),\n height: laidOut.get(nodeId)?.height,\n });\n\n const routes = new Map<Edge, EdgeRoute>();\n (layout.edges || []).forEach((elkEdge: ElkExtendedEdge) => {\n const section = elkEdge.sections?.[0];\n if (!section) return;\n const label = elkEdge.labels?.[0];\n const edge = layoutEdges[Number(elkEdge.id.slice(1))];\n routes.set(edge, {\n points: [\n section.startPoint,\n ...(section.bendPoints || []),\n section.endPoint,\n ],\n label: label\n ? {\n x: (label.x ?? 0) + (label.width ?? 0) / 2,\n y: (label.y ?? 0) + (label.height ?? 0) / 2,\n }\n : undefined,\n source: laidOutAt(edge.source),\n target: laidOutAt(edge.target),\n });\n });\n\n const depth = (node?: Node): number => {\n const parent = node && parentOf(node);\n return parent ? depth(nodesById.get(parent)) + 1 : 0;\n };\n\n return {\n // Parents must come before their children in the array for React Flow\n nodes: [...nodes]\n .sort((a, b) => depth(a) - depth(b))\n .map((node) => {\n const elkNode = laidOut.get(node.id);\n if (!elkNode) return node;\n return {\n ...node,\n origin: [0, 0] as [number, number],\n position: { x: elkNode.x ?? 0, y: elkNode.y ?? 0 },\n ...(groupIds.has(node.id) ||\n (GROUP_TYPES.has(node.type || \"\") &&\n typeof node.style?.width !== \"number\")\n ? {\n style: {\n ...node.style,\n width: elkNode.width,\n height: elkNode.height,\n },\n // Re-measured at its new size\n measured: undefined,\n }\n : {}),\n };\n }),\n edges: edges.map((edge) => {\n const route = routes.get(edge);\n return route ? { ...edge, data: { ...edge.data, route } } : edge;\n }),\n };\n};\n","import { MarkerType, type Edge, type Node } from \"@xyflow/react\";\nimport { COMMAND, EVENT, MESSAGE, QUERY } from \"../nodes/node-types\";\nimport { createEdge } from \"./utils/utils\";\nimport type { EdgeRoute } from \"./elk-layout\";\n\nconst MESSAGE_NODE_TYPES = [...MESSAGE, \"messageGroup\", \"messageGroupExpanded\"];\n\nexport const isMessageNode = (node: Node) =>\n MESSAGE_NODE_TYPES.includes(node.type || \"\");\n\nconst getCollection = (type = \"\") => {\n if (EVENT.includes(type)) return \"events\";\n if (COMMAND.includes(type)) return \"commands\";\n if (QUERY.includes(type)) return \"queries\";\n return \"messages\";\n};\n\n// Returns the messages a node represents, as [name, collection] pairs\nconst getMessages = (node: Node): [string, string][] => {\n const data = node.data as any;\n if (node.type === \"messageGroup\") {\n return (data?.messages || []).map(({ message }: any) => [\n message?.data?.name || message?.data?.id,\n getCollection(message?.collection),\n ]);\n }\n const message = data?.message;\n return message\n ? [[message.name || message.id, getCollection(node.type)]]\n : [];\n};\n\nconst VERBS: Record<string, string> = {\n events: \"publishes\",\n commands: \"invokes\",\n queries: \"requests\",\n};\n\n/**\n * Label for an edge carrying messages (name -> collection), e.g.\n * \"publishes\\nProduct Created\", \"publishes\\n3 events\", \"sends\\n3 messages\"\n */\nexport const getMessagesLabel = (messages: Map<string, string>) => {\n if (messages.size === 0) return undefined;\n const collections = new Set(messages.values());\n const collection =\n collections.size === 1 ? Array.from(collections)[0] : \"messages\";\n const verb = VERBS[collection] || \"sends\";\n const sent =\n messages.size === 1\n ? Array.from(messages.keys())[0]\n : `${messages.size} ${collection}`;\n return `${verb}\\n${sent}`;\n};\n\n// Messages and channels carry what's sent between the nodes either side of them\nexport const isCarrier = (node: Node) =>\n isMessageNode(node) || node.type === \"channels\";\n\nconst isCrossDomain = (edge: Edge) =>\n !!(edge.data as { crossDomain?: boolean } | undefined)?.crossDomain;\n\nconst getRoute = (edge: Edge) =>\n (edge.data as { route?: EdgeRoute } | undefined)?.route;\n\n/**\n * The route of an edge bridging hidden nodes: along the routes of the edges it\n * replaces (through where the hidden nodes were), labelled where the first\n * hidden node was. None unless they're all laid out.\n */\nconst joinRoutes = (routes: (EdgeRoute | undefined)[]) => {\n if (!routes.every((route) => route && route.points.length > 0)) return;\n const laidOut = routes as EdgeRoute[];\n const arrives = laidOut[0].points[laidOut[0].points.length - 1];\n const leaves = laidOut[1].points[0];\n return {\n points: laidOut.flatMap((route) => route.points),\n label: { x: (arrives.x + leaves.x) / 2, y: (arrives.y + leaves.y) / 2 },\n source: laidOut[0].source,\n target: laidOut[laidOut.length - 1].target,\n };\n};\n\n/**\n * Removes the nodes `isHidden` picks. Messages and channels removed are\n * bridged: the nodes either side of them are connected directly, labelled with\n * the messages between them. Other edges to removed nodes go with them.\n * e.g. hiding events, ServiceA -> OrderPlaced -> ServiceB becomes ServiceA -> ServiceB\n */\nexport const hideNodes = (\n nodes: Node[],\n edges: Edge[],\n isHidden: (node: Node) => boolean,\n) => {\n const hiddenNodes = new Map(\n nodes.filter(isHidden).map((node) => [node.id, node]),\n );\n if (hiddenNodes.size === 0) return { nodes, edges };\n\n const outgoingEdges = new Map<string, Edge[]>();\n for (const edge of edges) {\n const outgoing = outgoingEdges.get(edge.source) || [];\n outgoing.push(edge);\n outgoingEdges.set(edge.source, outgoing);\n }\n\n const keptEdges: Edge[] = [];\n const bridgedEdges = new Map<\n string,\n {\n source: string;\n target: string;\n messages: Map<string, string>;\n route?: EdgeRoute;\n crossDomain: boolean;\n }\n >();\n\n for (const edge of edges) {\n if (hiddenNodes.has(edge.source)) continue;\n const target = hiddenNodes.get(edge.target);\n if (!target) {\n keptEdges.push(edge);\n continue;\n }\n if (!isCarrier(target)) continue;\n\n // Follow the edge through hidden messages and channels until we reach\n // visible nodes, collecting the names of the messages along the way\n const stack = [\n {\n id: edge.target,\n messages: [] as [string, string][],\n routes: [getRoute(edge)],\n crossDomain: isCrossDomain(edge),\n },\n ];\n const visited = new Set<string>();\n while (stack.length > 0) {\n const current = stack.pop()!;\n if (visited.has(current.id)) continue;\n visited.add(current.id);\n const messages = [\n ...current.messages,\n ...getMessages(hiddenNodes.get(current.id)!),\n ];\n\n for (const next of outgoingEdges.get(current.id) || []) {\n const routes = [...current.routes, getRoute(next)];\n const crossDomain = current.crossDomain || isCrossDomain(next);\n const nextNode = hiddenNodes.get(next.target);\n if (nextNode) {\n if (isCarrier(nextNode))\n stack.push({ id: next.target, messages, routes, crossDomain });\n continue;\n }\n if (next.target === edge.source) continue;\n\n // Prefixed, so it can't clash with an edge directly between the two\n const id = `bridged-${edge.source}-${next.target}`;\n const bridged = bridgedEdges.get(id) || {\n source: edge.source,\n target: next.target,\n messages: new Map<string, string>(),\n route: joinRoutes(routes),\n crossDomain: false,\n };\n bridged.crossDomain ||= crossDomain;\n messages.forEach(([name, collection]) =>\n bridged.messages.set(name, collection),\n );\n bridgedEdges.set(id, bridged);\n }\n }\n }\n\n const newEdges = Array.from(bridgedEdges, ([id, bridged]) =>\n createEdge({\n id,\n source: bridged.source,\n target: bridged.target,\n label: getMessagesLabel(bridged.messages),\n // The same size arrow as the rest of the graph's edges\n markerEnd: {\n type: MarkerType.ArrowClosed,\n width: 20,\n height: 20,\n color: \"rgb(var(--ec-page-text-muted))\",\n },\n // Along the same route, and crossing domains if any edge it replaces did\n data: {\n ...(bridged.route ? { route: bridged.route } : {}),\n ...(bridged.crossDomain ? { crossDomain: true } : {}),\n },\n }),\n );\n\n return {\n nodes: nodes.filter((node) => !hiddenNodes.has(node.id)),\n edges: [...keptEdges, ...newEdges],\n };\n};\n\n/**\n * Removes message nodes (events, commands, queries) and the channels they\n * travel through, connecting the nodes on either side directly.\n * e.g. ServiceA -> OrderPlaced -> orders-topic -> ServiceB becomes ServiceA -> ServiceB\n */\nexport const hideMessageNodes = (nodes: Node[], edges: Edge[]) =>\n hideNodes(nodes, edges, isCarrier);\n"],"mappings":";AAAO,IAAM,UAAU,CAAC,WAAW,UAAU;AACtC,IAAM,QAAQ,CAAC,SA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19
  };
20
- /** Where the edge's source and target were laid out (top-left, in the flow) */
20
+ /**
21
+ * Where the edge's source and target were laid out (top-left, in the flow),
22
+ * and how tall: nodes often render shorter than the layout estimated
23
+ */
21
24
  source?: {
22
25
  x: number;
23
26
  y: number;
27
+ height?: number;
24
28
  };
25
29
  target?: {
26
30
  x: number;
27
31
  y: number;
32
+ height?: number;
28
33
  };
29
34
  };
35
+ /**
36
+ * A route copied to another canvas (e.g. a diagram opened in Studio), which
37
+ * places the nodes itself: where it goes, and how tall its nodes were laid out
38
+ */
39
+ type CopiedEdgeRoute = Pick<EdgeRoute, "points" | "label"> & {
40
+ sourceHeight?: number;
41
+ targetHeight?: number;
42
+ };
30
43
  /** The size a node is laid out at: as rendered, or an estimate for its type */
31
44
  declare const getNodeSize: (node: Node) => LayoutSize;
32
45
  /**
@@ -44,4 +57,4 @@ declare const layoutWithElk: ({ nodes, edges }: LayoutGraph, { sizeOf }?: {
44
57
  sizeOf?: (node: Node) => LayoutSize;
45
58
  }) => Promise<LayoutGraph>;
46
59
 
47
- export { type EdgeRoute as E, type LayoutGraph as L, type LayoutSize as a, getNodeSize as g, layoutWithElk as l };
60
+ export { type CopiedEdgeRoute as C, type EdgeRoute as E, type LayoutGraph as L, type LayoutSize as a, getNodeSize as g, layoutWithElk as l };
@@ -17,16 +17,29 @@ type EdgeRoute = {
17
17
  x: number;
18
18
  y: number;
19
19
  };
20
- /** Where the edge's source and target were laid out (top-left, in the flow) */
20
+ /**
21
+ * Where the edge's source and target were laid out (top-left, in the flow),
22
+ * and how tall: nodes often render shorter than the layout estimated
23
+ */
21
24
  source?: {
22
25
  x: number;
23
26
  y: number;
27
+ height?: number;
24
28
  };
25
29
  target?: {
26
30
  x: number;
27
31
  y: number;
32
+ height?: number;
28
33
  };
29
34
  };
35
+ /**
36
+ * A route copied to another canvas (e.g. a diagram opened in Studio), which
37
+ * places the nodes itself: where it goes, and how tall its nodes were laid out
38
+ */
39
+ type CopiedEdgeRoute = Pick<EdgeRoute, "points" | "label"> & {
40
+ sourceHeight?: number;
41
+ targetHeight?: number;
42
+ };
30
43
  /** The size a node is laid out at: as rendered, or an estimate for its type */
31
44
  declare const getNodeSize: (node: Node) => LayoutSize;
32
45
  /**
@@ -44,4 +57,4 @@ declare const layoutWithElk: ({ nodes, edges }: LayoutGraph, { sizeOf }?: {
44
57
  sizeOf?: (node: Node) => LayoutSize;
45
58
  }) => Promise<LayoutGraph>;
46
59
 
47
- export { type EdgeRoute as E, type LayoutGraph as L, type LayoutSize as a, getNodeSize as g, layoutWithElk as l };
60
+ export { type CopiedEdgeRoute as C, type EdgeRoute as E, type LayoutGraph as L, type LayoutSize as a, getNodeSize as g, layoutWithElk as l };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _xyflow_react from '@xyflow/react';
2
2
  import { Node, Connection, MarkerType, Edge, NodeTypes, EdgeTypes, NodeProps, EdgeProps, ReactFlowJsonObject } from '@xyflow/react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
- import { E as EdgeRoute } from './elk-layout-BVUJjv6i.mjs';
4
+ import { C as CopiedEdgeRoute } from './elk-layout-CpbZ6hB9.mjs';
5
5
  import * as react from 'react';
6
6
  import react__default, { ReactNode, ComponentType } from 'react';
7
7
 
@@ -363,8 +363,11 @@ type VisualiserSnapshot = {
363
363
  source: string;
364
364
  target: string;
365
365
  label?: string;
366
- /** How it's drawn: the points it goes through on the diagram, and where its label is (from the layout) */
367
- route?: Pick<EdgeRoute, "points" | "label">;
366
+ /**
367
+ * How it's drawn: the points it goes through on the diagram, where its label is, and how tall its nodes were
368
+ * (from the layout)
369
+ */
370
+ route?: CopiedEdgeRoute;
368
371
  }[];
369
372
  /**
370
373
  * Levels 1 and 2 as the diagram shows them (laid out, positions relative to their parents), for Studio to show
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _xyflow_react from '@xyflow/react';
2
2
  import { Node, Connection, MarkerType, Edge, NodeTypes, EdgeTypes, NodeProps, EdgeProps, ReactFlowJsonObject } from '@xyflow/react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
- import { E as EdgeRoute } from './elk-layout-BVUJjv6i.js';
4
+ import { C as CopiedEdgeRoute } from './elk-layout-CpbZ6hB9.js';
5
5
  import * as react from 'react';
6
6
  import react__default, { ReactNode, ComponentType } from 'react';
7
7
 
@@ -363,8 +363,11 @@ type VisualiserSnapshot = {
363
363
  source: string;
364
364
  target: string;
365
365
  label?: string;
366
- /** How it's drawn: the points it goes through on the diagram, and where its label is (from the layout) */
367
- route?: Pick<EdgeRoute, "points" | "label">;
366
+ /**
367
+ * How it's drawn: the points it goes through on the diagram, where its label is, and how tall its nodes were
368
+ * (from the layout)
369
+ */
370
+ route?: CopiedEdgeRoute;
368
371
  }[];
369
372
  /**
370
373
  * Levels 1 and 2 as the diagram shows them (laid out, positions relative to their parents), for Studio to show
package/dist/index.js CHANGED
@@ -7177,6 +7177,10 @@ var layoutWithElk = async ({ nodes, edges }, { sizeOf = getNodeSize } = {}) => {
7177
7177
  const elkNode = laidOut.get(nodeId);
7178
7178
  return { x: offset.x + (elkNode?.x ?? 0), y: offset.y + (elkNode?.y ?? 0) };
7179
7179
  };
7180
+ const laidOutAt = (nodeId) => ({
7181
+ ...absolute(nodeId),
7182
+ height: laidOut.get(nodeId)?.height
7183
+ });
7180
7184
  const routes = /* @__PURE__ */ new Map();
7181
7185
  (layout.edges || []).forEach((elkEdge) => {
7182
7186
  const section = elkEdge.sections?.[0];
@@ -7193,8 +7197,8 @@ var layoutWithElk = async ({ nodes, edges }, { sizeOf = getNodeSize } = {}) => {
7193
7197
  x: (label.x ?? 0) + (label.width ?? 0) / 2,
7194
7198
  y: (label.y ?? 0) + (label.height ?? 0) / 2
7195
7199
  } : void 0,
7196
- source: absolute(edge.source),
7197
- target: absolute(edge.target)
7200
+ source: laidOutAt(edge.source),
7201
+ target: laidOutAt(edge.target)
7198
7202
  });
7199
7203
  });
7200
7204
  const depth = (node) => {
@@ -8025,6 +8029,16 @@ var ROUTE_TOLERANCE = { x: 60, y: 400 };
8025
8029
  var isStraight = (a, b) => a.x === b.x || a.y === b.y;
8026
8030
  var add = (a, b) => ({ x: a.x + b.x, y: a.y + b.y });
8027
8031
  var NOT_MOVED = { x: 0, y: 0 };
8032
+ var END_INSET = 8;
8033
+ var alongSide = (end, node, height) => {
8034
+ if (!node?.height || !height) return end;
8035
+ const fromMiddle = end.y - (node.y + node.height / 2);
8036
+ const furthest = Math.max(height / 2 - END_INSET, 0);
8037
+ return {
8038
+ x: end.x,
8039
+ y: node.y + height / 2 + Math.min(Math.max(fromMiddle, -furthest), furthest)
8040
+ };
8041
+ };
8028
8042
  var getRoutePath = (route, source, target, {
8029
8043
  // Ends at a specific handle (e.g. a service listed in a domain) go exactly
8030
8044
  // to it, rather than where the layout spread them along the node's side
@@ -8032,13 +8046,22 @@ var getRoutePath = (route, source, target, {
8032
8046
  toTargetHandle = false,
8033
8047
  // How far the source and target have moved since they were laid out
8034
8048
  sourceMoved = NOT_MOVED,
8035
- targetMoved = NOT_MOVED
8049
+ targetMoved = NOT_MOVED,
8050
+ // How tall the source and target render
8051
+ sourceHeight,
8052
+ targetHeight
8036
8053
  } = {}) => {
8037
8054
  const { points } = route;
8038
8055
  if (points.length < 2) return void 0;
8039
8056
  const last = points.length - 1;
8040
- const start = add(points[0], sourceMoved);
8041
- const end = add(points[last], targetMoved);
8057
+ const start = add(
8058
+ alongSide(points[0], route.source, sourceHeight),
8059
+ sourceMoved
8060
+ );
8061
+ const end = add(
8062
+ alongSide(points[last], route.target, targetHeight),
8063
+ targetMoved
8064
+ );
8042
8065
  const fits = (a, b) => Math.abs(a.x - b.x) <= ROUTE_TOLERANCE.x && Math.abs(a.y - b.y) <= ROUTE_TOLERANCE.y;
8043
8066
  if (!fits(start, source) || !fits(end, target)) return void 0;
8044
8067
  const movedTogether = Math.abs(sourceMoved.x - targetMoved.x) < 1 && Math.abs(sourceMoved.y - targetMoved.y) < 1;
@@ -8099,7 +8122,7 @@ var getMoved = (state, nodeId, at) => {
8099
8122
  return position && { x: position.x - at.x, y: position.y - at.y };
8100
8123
  };
8101
8124
  var isSamePoint = (a, b) => a.x === b.x && a.y === b.y;
8102
- var isSameEdgeState = (a, b) => a.zIndex === b.zIndex && (a.moved === b.moved || !!a.moved && !!b.moved && isSamePoint(a.moved[0], b.moved[0]) && isSamePoint(a.moved[1], b.moved[1]));
8125
+ var isSameEdgeState = (a, b) => a.zIndex === b.zIndex && a.heights?.[0] === b.heights?.[0] && a.heights?.[1] === b.heights?.[1] && (a.moved === b.moved || !!a.moved && !!b.moved && isSamePoint(a.moved[0], b.moved[0]) && isSamePoint(a.moved[1], b.moved[1]));
8103
8126
  var useRoute = ({
8104
8127
  data,
8105
8128
  source,
@@ -8112,7 +8135,7 @@ var useRoute = ({
8112
8135
  targetHandleId
8113
8136
  }, [path, labelX, labelY]) => {
8114
8137
  const route = data?.route;
8115
- const { moved, zIndex } = (0, import_react74.useStore)(
8138
+ const { moved, heights, zIndex } = (0, import_react74.useStore)(
8116
8139
  (0, import_react73.useCallback)(
8117
8140
  (state) => {
8118
8141
  const z = (nodeId) => {
@@ -8123,9 +8146,11 @@ var useRoute = ({
8123
8146
  if (!route?.source || !route.target) return { zIndex: zIndex2 };
8124
8147
  const sourceMoved = getMoved(state, source, route.source);
8125
8148
  const targetMoved = getMoved(state, target, route.target);
8149
+ const height = (nodeId) => state.nodeLookup.get(nodeId)?.measured.height;
8126
8150
  return {
8127
8151
  zIndex: zIndex2,
8128
- moved: sourceMoved && targetMoved ? [sourceMoved, targetMoved] : void 0
8152
+ moved: sourceMoved && targetMoved ? [sourceMoved, targetMoved] : void 0,
8153
+ heights: [height(source), height(target)]
8129
8154
  };
8130
8155
  },
8131
8156
  [route, source, target]
@@ -8140,7 +8165,9 @@ var useRoute = ({
8140
8165
  toSourceHandle: !!sourceHandleId,
8141
8166
  toTargetHandle: !!targetHandleId,
8142
8167
  sourceMoved: moved[0],
8143
- targetMoved: moved[1]
8168
+ targetMoved: moved[1],
8169
+ sourceHeight: heights?.[0],
8170
+ targetHeight: heights?.[1]
8144
8171
  }
8145
8172
  );
8146
8173
  if (!routed) return [path, labelX, labelY, zIndex];
@@ -13837,7 +13864,14 @@ var toSnapshot = (nodes, edges, place) => {
13837
13864
  source: edge.source,
13838
13865
  target: edge.target,
13839
13866
  ...typeof edge.label === "string" && { label: edge.label },
13840
- ...route && { route: { points: route.points, label: route.label } }
13867
+ ...route && {
13868
+ route: {
13869
+ points: route.points,
13870
+ label: route.label,
13871
+ sourceHeight: route.source?.height,
13872
+ targetHeight: route.target?.height
13873
+ }
13874
+ }
13841
13875
  };
13842
13876
  })
13843
13877
  };