feat: add register xml node to interface and stroy book

This commit is contained in:
多牧 2020-06-03 11:34:37 +08:00 committed by Moyee
parent 49139948fe
commit b090a03c95
2 changed files with 21 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import * as Algorithm from './algorithm';
const registerNode = Shape.registerNode;
const registerEdge = Shape.registerEdge;
const registerCombo = Shape.registerCombo;
const registerNodeByXML = Shape.registerNodeByXML;
const registerBehavior = Behaviors.registerBehavior;
const registerLayout = Layout.registerLayout;
const Minimap = Plugins.Minimap;
@ -57,6 +58,7 @@ export default {
registerCombo: Shape.registerCombo,
registerBehavior: Behaviors.registerBehavior,
registerLayout: Layout.registerLayout,
registerNodeByXML: Shape.registerNodeByXML,
Layout,
Global,
Minimap: Plugins.Minimap,

View File

@ -239,6 +239,25 @@ export default class Shape {
shapeFactory[shapeType] = shapeObj;
return shapeObj;
}
public static registerNodeByXML(
shapeType: string,
xml: (cfg: NodeConfig) => string | string,
extendDefinition: ShapeOptions = {}
) {
const shapeFactory = Shape.Node;
const autoNodeDefinition = createNodeFromXML(xml);
const nodeDefinition = {
...extendDefinition,
...autoNodeDefinition,
}
const shapeObj = Object.assign({}, ShapeFramework, nodeDefinition);
shapeObj.type = shapeType;
shapeObj.itemType = 'node';
shapeFactory[shapeType] = shapeObj;
return shapeObj;
}
}
// 注册 Node 的工厂方法