React Flow compatible flow-diagram engine and React host implemented in MoonBit.
| 包 | 职责 |
|---|---|
| geometry | 五种边路径、包围盒、视口、可见性、标记、边与矩形相交 |
| graph | 不可变变更、查询、删除范围、父子坐标、extent |
| interaction | 单步交互状态机、点击连线、重连、缩放、键盘及自动平移步长 |
| jsapi | JSON 文本接口,编译到 _build/js/debug/build/jsapi/jsapi.js |
moon add 2d5rrr333/reactflowimport {
"2d5rrr333/reactflow@0.1.1",
}moon run cmd/mainfn main {
let nodes = [
@graph.FlowNode::at("a", 0.0, 0.0),
@graph.FlowNode::at("b", 240.0, 120.0),
]
let edges = [@graph.FlowEdge::between("a", "b", "a-b")]
let nodes = @graph.apply_node_changes(
nodes,
[@graph.NodeChange::Position(id="a", x=40.0, y=60.0, dragging=false)],
)
println("node a: (\{nodes[0].x}, \{nodes[0].y})")
let path = @geometry.bezier_path(
@geometry.Point::{ x: 100.0, y: 80.0 },
@geometry.Right,
@geometry.Point::{ x: 300.0, y: 200.0 },
@geometry.Left,
0.25,
)
println("edge path: \{path.path}")
let editor = @interaction.Editor::fresh(nodes, edges)
let step = @interaction.pointer_down(
editor,
40.0,
60.0,
0,
"",
false,
false,
"",
)
println("mode after pointer down: \{step.editor.mode}")
}# 1. 构建 MoonBit JS 模块
moon build --target js
# 2. 安装宿主依赖并启动演示
npm ci --prefix host
npm run dev --prefix hostimport { ReactFlow, Background, Controls, MiniMap } from "./host/src"
export function Editor() {
return (
<ReactFlow
defaultNodes={[
{ id: "a", position: { x: 40, y: 60 }, data: { label: "Start" }, width: 100, height: 40 },
{ id: "b", position: { x: 300, y: 160 }, data: { label: "End" }, width: 100, height: 40 },
]}
defaultEdges={[{ id: "a-b", source: "a", target: "b", type: "smoothstep" }]}
>
<Background />
<Controls />
<MiniMap />
</ReactFlow>
)
}moon check --deny-warn
moon test --deny-warn
moon build --target js --deny-warnbash scripts/verify.shInstall
Download zipReact Flow compatible flow-diagram engine and React host implemented in MoonBit.