@jsonflowjs/core
v0.2.1
Published
JSON-first diagram model, validation and layout engine.
Readme
@jsonflowjs/core
JSON-first diagram model, validation, SCC-aware layout, ports, edge routing and connection rules.
Interactive checks live in validateConnection, connectNodes, disconnectNodes and reconnectNodes. Host rules receive the nodes and their opaque data. See docs/connections.md.
import {
validateDiagram,
layoutDiagram,
exportDiagramJson,
parseDiagram,
type Diagram,
} from "@jsonflowjs/core";
const diagram: Diagram = {
direction: "LR",
nodes: [
{
id: "a",
label: "A",
ports: [{ id: "out", side: "right" }],
data: { fields: [] },
},
{ id: "b", label: "B", ports: [{ id: "in", side: "left" }] },
],
edges: [{ from: "a", fromPort: "out", to: "b", toPort: "in" }],
};
validateDiagram(diagram);
const layout = layoutDiagram(diagram, { routing: "orthogonal" });
const json = exportDiagramJson(diagram);
const again = parseDiagram(json);parseDiagram accepts a JSON string or a parsed value. withNodePositions returns a new diagram with absolute coordinates. moveNodes reroutes an existing layout after a drag. See /docs/graph-model.md for identifiers, ports, positions, groups and subgraphs.
