本页提供最短路径,帮助你在当前仓库里完成一次可运行的 MMEditor 初始化、布局和数据导出。
npm install mmeditor
如果你在当前仓库本地验证示例,先执行:
npm install
import MMEditor from "mmeditor";
async function bootstrap() {
const root = document.getElementById("root") as HTMLDivElement;
const editor = new MMEditor({
dom: root,
showBackGrid: true,
showMiniMap: true,
});
await editor.schema.setInitData({
nodes: [
{
uuid: "source",
type: "default",
name: "Source",
x: 0,
y: 0,
},
{
uuid: "target",
type: "default",
name: "Target",
x: 240,
y: 120,
},
],
lines: [
{
from: "source",
to: "target",
fromPoint: 1,
toPoint: 0,
},
],
});
editor.schema.format();
editor.controller.autoFit();
return editor;
}
bootstrap();
如果你希望不经过打包器,直接验证浏览器接入方式:
npm run build:browser
open public/basic.html
public/basic.html 中使用的是:
const { MMEditor } = window.MMEditor;
const editor = new MMEditor({ dom: document.getElementById("demo") });
这条路径适合验证 dist/MMEditor.browser.js 是否可被页面直接消费。
推荐顺序如下:
对应 API 一般是:
MMEditor 对外使用的基础数据结构是:
type MMEditorData = {
nodes: MMEditorNode[];
lines: MMEditorLine[];
};
节点最常用字段:
连线最常用字段: