本地logicflow依赖包

This commit is contained in:
Jam committed 2022-11-28 14:31:03 +08:00
1 parent 8ff82208ad
commit 30f225df00
290 files changed
+18624 -16276

No files matched your search

@@ -0,0 +1,10 @@
import { h } from '@logicflow/core';
export default function Polygon({ fillOpacity, strokeWidth, strokeOpacity, fill, stroke, points, className, }: {
fillOpacity?: number;
strokeWidth?: number;
strokeOpacity?: number;
fill?: string;
stroke?: string;
points: any;
className?: string;
}): h.JSX.Element;
@@ -0,0 +1,26 @@
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { h } from '@logicflow/core';
export default function Polygon(_a) {
var _b = _a.fillOpacity, fillOpacity = _b === void 0 ? 1 : _b, _c = _a.strokeWidth, strokeWidth = _c === void 0 ? 1 : _c, _d = _a.strokeOpacity, strokeOpacity = _d === void 0 ? 1 : _d, _e = _a.fill, fill = _e === void 0 ? 'transparent' : _e, _f = _a.stroke, stroke = _f === void 0 ? '#000' : _f, points = _a.points, _g = _a.className, className = _g === void 0 ? 'lf-basic-shape' : _g;
var attrs = {
fill: fill,
fillOpacity: fillOpacity,
strokeWidth: strokeWidth,
stroke: stroke,
strokeOpacity: strokeOpacity,
points: '',
className: className,
};
attrs.points = points.map(function (point) { return point.join(','); }).join(' ');
return (h("polygon", __assign({}, attrs)));
}
@@ -0,0 +1,17 @@
import { h, Point, Size } from '@logicflow/core';
declare type IProps = {
className?: string;
radius?: number;
stroke?: string;
strokeDasharray?: string;
} & Point & Size;
declare function Rect(props: IProps): h.JSX.Element;
declare namespace Rect {
var defaultProps: {
radius: number;
stroke: string;
strokeDasharray: string;
className: string;
};
}
export default Rect;
@@ -0,0 +1,28 @@
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { h } from '@logicflow/core';
// TODO: 默认样式引入
export default function Rect(props) {
var x = props.x, y = props.y, width = props.width, height = props.height, radius = props.radius, className = props.className;
var leftTopX = x - width / 2;
var leftTopY = y - height / 2;
var attrs = __assign(__assign({
// default
width: 10, height: 10, cx: 0, cy: 0, rx: radius || 0, ry: radius || 0, fill: 'transparent', fillOpacity: 1, strokeWidth: '1px', stroke: '#000', strokeOpacity: 1, className: "lf-basic-shape " + className }, props), { x: leftTopX, y: leftTopY });
return (h("rect", __assign({}, attrs)));
}
Rect.defaultProps = {
radius: 0,
stroke: '',
strokeDasharray: '',
className: '',
};
@@ -0,0 +1,58 @@
import { h, Component } from 'preact';
import { BaseNodeModel, GraphModel, LogicFlowUtil } from '@logicflow/core';
interface IProps {
index: number;
x: number;
y: number;
model: BaseNodeModel;
graphModel: GraphModel;
style?: CSSStyleDeclaration;
}
declare class Control extends Component<IProps> {
index: number;
nodeModel: BaseNodeModel;
graphModel: GraphModel;
dragHandler: LogicFlowUtil.StepDrag;
constructor(props: any);
getNodeEdges(nodeId: any): {
sourceEdges: any[];
targetEdges: any[];
};
updatePosition: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
getResize: ({ index, deltaX, deltaY, width, height, pct }: {
index: any;
deltaX: any;
deltaY: any;
width: any;
height: any;
pct?: number;
}) => {
width: any;
height: any;
};
updateRect: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
updateEllipse: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
updateDiamond: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
eventEmit: ({ beforeNode, afterNode }: {
beforeNode: any;
afterNode: any;
}) => void;
onDraging: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
render(): h.JSX.Element;
}
export default Control;
@@ -0,0 +1,330 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { h, Component } from 'preact';
import { LogicFlowUtil } from '@logicflow/core';
import Rect from '../BasicShape/Rect';
import { getDiamondReizeEdgePoint, getEllipseReizeEdgePoint, getRectReizeEdgePoint, ModelType } from './Util';
var StepDrag = LogicFlowUtil.StepDrag;
var Control = /** @class */ (function (_super) {
__extends(Control, _super);
function Control(props) {
var _this = _super.call(this) || this;
// 更新中心点位置,更新文案位置
_this.updatePosition = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var _b = _this.nodeModel, x = _b.x, y = _b.y;
_this.nodeModel.x = x + deltaX / 2;
_this.nodeModel.y = y + deltaY / 2;
_this.nodeModel.moveText(deltaX / 2, deltaY / 2);
};
// 计算control拖动后,节点的宽高
_this.getResize = function (_a) {
var index = _a.index, deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height, _b = _a.pct, pct = _b === void 0 ? 1 : _b;
var resize = { width: width, height: height };
switch (index) {
case 0:
resize.width = width - deltaX * pct;
resize.height = height - deltaY * pct;
break;
case 1:
resize.width = width + deltaX * pct;
resize.height = height - deltaY * pct;
break;
case 2:
resize.width = width + deltaX;
resize.height = height + deltaY * pct;
break;
case 3:
resize.width = width - deltaX * pct;
resize.height = height + deltaY * pct;
break;
default:
break;
}
return resize;
};
// 矩形更新
_this.updateRect = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var _b = _this.nodeModel, id = _b.id, x = _b.x, y = _b.y, width = _b.width, height = _b.height, radius = _b.radius;
// 更新中心点位置,更新文案位置
var index = _this.index;
var size = _this.getResize({
index: index,
deltaX: deltaX,
deltaY: deltaY,
width: width,
height: height,
pct: 1,
});
// 限制放大缩小的最大最小范围
var _c = _this.nodeModel, minWidth = _c.minWidth, minHeight = _c.minHeight, maxWidth = _c.maxWidth, maxHeight = _c.maxHeight;
if (size.width < minWidth
|| size.width > maxWidth
|| size.height < minHeight
|| size.height > maxHeight) {
// 为了避免放到和缩小位置和鼠标不一致的问题
_this.dragHandler.cancelDrag();
return;
}
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
// 更新宽高
_this.nodeModel.width = size.width;
_this.nodeModel.height = size.height;
_this.nodeModel.setProperties({
nodeSize: {
width: size.width,
height: size.height,
},
});
var edges = _this.getNodeEdges(id);
var beforeNode = {
x: x,
y: y,
width: width,
height: height,
radius: radius,
};
var afterNode = {
x: _this.nodeModel.x,
y: _this.nodeModel.y,
width: _this.nodeModel.width,
height: _this.nodeModel.height,
radius: radius,
};
var params = {
point: '',
beforeNode: beforeNode,
afterNode: afterNode,
};
// 更新边
var afterPoint;
edges.sourceEdges.forEach(function (item) {
params.point = item.startPoint;
afterPoint = getRectReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = getRectReizeEdgePoint(params);
item.updateEndPoint(afterPoint);
});
_this.eventEmit({ beforeNode: beforeNode, afterNode: afterNode });
};
// 椭圆更新
_this.updateEllipse = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y;
var index = _this.index;
var width = rx;
var height = ry;
var size = _this.getResize({
index: index,
deltaX: deltaX,
deltaY: deltaY,
width: width,
height: height,
pct: 1 / 2,
});
// 限制放大缩小的最大最小范围
var _c = _this.nodeModel, minWidth = _c.minWidth, minHeight = _c.minHeight, maxWidth = _c.maxWidth, maxHeight = _c.maxHeight;
if (size.width < (minWidth / 2)
|| size.width > (maxWidth / 2)
|| size.height < (minHeight / 2)
|| size.height > (maxHeight / 2)) {
_this.dragHandler.cancelDrag();
return;
}
// 更新中心点位置,更新文案位置
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
// 更新rx ry,宽高为计算属性自动更新
// @ts-ignore
_this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
// @ts-ignore
_this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
_this.nodeModel.setProperties({
nodeSize: {
rx: size.width,
ry: size.height,
},
});
var edges = _this.getNodeEdges(id);
var beforeNode = { x: x, y: y };
var afterNode = {
rx: size.width,
ry: size.height,
x: _this.nodeModel.x,
y: _this.nodeModel.y,
};
var params = {
point: {},
beforeNode: beforeNode,
afterNode: afterNode,
};
// 更新边
var afterPoint;
edges.sourceEdges.forEach(function (item) {
params.point = item.startPoint;
afterPoint = getEllipseReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = getEllipseReizeEdgePoint(params);
item.updateEndPoint(afterPoint);
});
_this.eventEmit({ beforeNode: __assign(__assign({}, beforeNode), { rx: rx, ry: ry }), afterNode: afterNode });
};
// 菱形更新
_this.updateDiamond = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y;
var index = _this.index;
var width = rx;
var height = ry;
var size = _this.getResize({
index: index,
deltaX: deltaX,
deltaY: deltaY,
width: width,
height: height,
pct: 1 / 2,
});
// 限制放大缩小的最大最小范围
var _c = _this.nodeModel, minWidth = _c.minWidth, minHeight = _c.minHeight, maxWidth = _c.maxWidth, maxHeight = _c.maxHeight;
if (size.width < (minWidth / 2)
|| size.width > (maxWidth / 2)
|| size.height < (minHeight / 2)
|| size.height > (maxHeight / 2)) {
_this.dragHandler.cancelDrag();
return;
}
// 更新中心点位置,更新文案位置
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
// 更新rx ry,宽高为计算属性自动更新
// @ts-ignore
_this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
// @ts-ignore
_this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
_this.nodeModel.setProperties({
nodeSize: {
rx: size.width,
ry: size.height,
},
});
var beforeNode = { x: x, y: y, rx: rx, ry: ry };
var afterNode = {
rx: size.width,
ry: size.height,
x: _this.nodeModel.x,
y: _this.nodeModel.y,
};
var params = {
point: {},
beforeNode: beforeNode,
afterNode: afterNode,
};
// 更新边
var afterPoint;
var edges = _this.getNodeEdges(id);
edges.sourceEdges.forEach(function (item) {
params.point = item.startPoint;
afterPoint = getDiamondReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = getDiamondReizeEdgePoint(params);
item.updateEndPoint(afterPoint);
});
_this.eventEmit({ beforeNode: beforeNode, afterNode: afterNode });
};
_this.eventEmit = function (_a) {
var beforeNode = _a.beforeNode, afterNode = _a.afterNode;
var _b = _this.nodeModel, id = _b.id, modelType = _b.modelType, type = _b.type;
var oldNodeSize = __assign({ id: id, modelType: modelType, type: type }, beforeNode);
var newNodeSize = __assign({ id: id, modelType: modelType, type: type }, afterNode);
_this.graphModel.eventCenter.emit('node:resize', { oldNodeSize: oldNodeSize, newNodeSize: newNodeSize });
};
_this.onDraging = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var modelType = _this.nodeModel.modelType;
// html和矩形的计算方式是一样的,共用一个方法
if (modelType === ModelType.RECT_NODE || modelType === ModelType.HTML_NODE) {
_this.updateRect({ deltaX: deltaX, deltaY: deltaY });
// this.nodeModel.resize(deltaX, deltaY);
}
else if (modelType === ModelType.ELLIPSE_NODE) {
_this.updateEllipse({ deltaX: deltaX, deltaY: deltaY });
}
else if (modelType === ModelType.DIAMOND_NODE) {
_this.updateDiamond({ deltaX: deltaX, deltaY: deltaY });
}
};
_this.index = props.index;
_this.nodeModel = props.model;
_this.graphModel = props.graphModel;
var gridSize = _this.graphModel.gridSize;
// 为保证对齐线功能正常使用,step默认是网格grid的两倍,
// 没有网格设置,默认为2,保证坐标是整数
var step = 2;
if (gridSize > 1) {
step = 2 * gridSize;
}
if (_this.nodeModel.gridSize) {
step = 2 * _this.nodeModel.gridSize;
}
_this.state = {};
_this.dragHandler = new StepDrag({
onDraging: _this.onDraging,
step: step,
});
return _this;
}
Control.prototype.getNodeEdges = function (nodeId) {
var graphModel = this.graphModel;
var edges = graphModel.edges;
var sourceEdges = [];
var targetEdges = [];
for (var i = 0; i < edges.length; i++) {
var edgeModel = edges[i];
if (edgeModel.sourceNodeId === nodeId) {
sourceEdges.push(edgeModel);
}
else if (edges[i].targetNodeId === nodeId) {
targetEdges.push(edgeModel);
}
}
return { sourceEdges: sourceEdges, targetEdges: targetEdges };
};
Control.prototype.render = function () {
var _a = this.props, x = _a.x, y = _a.y, index = _a.index, model = _a.model;
var style = model.getControlPointStyle();
return (h("g", { className: "lf-resize-control-" + index },
h(Rect, __assign({ className: "lf-node-control" }, { x: x, y: y }, style, { onMouseDown: this.dragHandler.handleMouseDown }))));
};
return Control;
}(Component));
export default Control;
@@ -0,0 +1,13 @@
import { h, Component } from 'preact';
import { BaseNodeModel, GraphModel } from '@logicflow/core';
interface IProps {
model: BaseNodeModel;
graphModel: GraphModel;
}
declare class ControlGroup extends Component<IProps> {
constructor();
getResizeControl(): h.JSX.Element[];
getGroupSolid(): h.JSX.Element;
render(): h.JSX.Element;
}
export default ControlGroup;
@@ -0,0 +1,83 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { h, Component } from 'preact';
import Control from './Control';
import Rect from '../BasicShape/Rect';
var ControlGroup = /** @class */ (function (_super) {
__extends(ControlGroup, _super);
function ControlGroup() {
var _this = _super.call(this) || this;
_this.state = {};
return _this;
}
ControlGroup.prototype.getResizeControl = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
var x = model.x, y = model.y, width = model.width, height = model.height;
var box = {
minX: x - width / 2,
minY: y - height / 2,
maxX: x + width / 2,
maxY: y + height / 2,
};
var minX = box.minX, minY = box.minY, maxX = box.maxX, maxY = box.maxY;
var controlList = [
// 左上角
{
x: minX,
y: minY,
},
// 右上角
{
x: maxX,
y: minY,
},
// 右下角
{
x: maxX,
y: maxY,
},
// 左下角
{
x: minX,
y: maxY,
},
];
return controlList.map(function (control, index) { return (h(Control, __assign({ index: index }, control, { model: model, graphModel: graphModel }))); });
};
// 一般节点被选中了会有outline, 先不用这个
ControlGroup.prototype.getGroupSolid = function () {
var model = this.props.model;
var x = model.x, y = model.y, width = model.width, height = model.height;
var style = model.getResizeOutlineStyle();
return (h(Rect, __assign({ fill: "none" }, style, { x: x, y: y, width: width, height: height })));
};
ControlGroup.prototype.render = function () {
return (h("g", { className: "lf-resize-control" },
this.getGroupSolid(),
this.getResizeControl()));
};
return ControlGroup;
}(Component));
export default ControlGroup;
@@ -0,0 +1,33 @@
export declare enum ModelType {
NODE = "node",
CIRCLE_NODE = "circle-node",
POLYGON_NODE = "polygon-node",
RECT_NODE = "rect-node",
HTML_NODE = "html-node",
TEXT_NODE = "text-node",
ELLIPSE_NODE = "ellipse-node",
DIAMOND_NODE = "diamond-node",
EDGE = "edge",
LINE_EDGE = "line-edge",
POLYLINE_EDGE = "polyline-edge",
BEZIER_EDGE = "bezier-edge",
GRAPH = "graph"
}
export declare function getRectReizeEdgePoint({ point, beforeNode, afterNode }: {
point: any;
beforeNode: any;
afterNode: any;
}): {
x: any;
y: any;
};
export declare function getEllipseReizeEdgePoint({ point, beforeNode, afterNode }: {
point: any;
beforeNode: any;
afterNode: any;
}): any;
export declare function getDiamondReizeEdgePoint({ point, beforeNode, afterNode }: {
point: any;
beforeNode: any;
afterNode: any;
}): any;
@@ -0,0 +1,210 @@
export var ModelType;
(function (ModelType) {
ModelType["NODE"] = "node";
ModelType["CIRCLE_NODE"] = "circle-node";
ModelType["POLYGON_NODE"] = "polygon-node";
ModelType["RECT_NODE"] = "rect-node";
ModelType["HTML_NODE"] = "html-node";
ModelType["TEXT_NODE"] = "text-node";
ModelType["ELLIPSE_NODE"] = "ellipse-node";
ModelType["DIAMOND_NODE"] = "diamond-node";
ModelType["EDGE"] = "edge";
ModelType["LINE_EDGE"] = "line-edge";
ModelType["POLYLINE_EDGE"] = "polyline-edge";
ModelType["BEZIER_EDGE"] = "bezier-edge";
ModelType["GRAPH"] = "graph";
})(ModelType || (ModelType = {}));
// 计算节点的box四角数据
function getNodeBox(node) {
var x = node.x, y = node.y, width = node.width, height = node.height;
return {
minX: x - width / 2,
minY: y - height / 2,
maxX: x + width / 2,
maxY: y + height / 2,
};
}
// 计算矩形radius设置后,四个圆角的圆心
function getRidusCenter(node) {
var nodeBox = getNodeBox(node);
var radius = node.radius;
var minX = nodeBox.minX, minY = nodeBox.minY, maxX = nodeBox.maxX, maxY = nodeBox.maxY;
return [
{
x: minX + radius,
y: minY + radius,
},
{
x: maxX - radius,
y: minY + radius,
},
{
x: maxX - radius,
y: maxY - radius,
},
{
x: minX + radius,
y: maxY - radius,
},
];
}
// 获取矩形resize之后,与矩形连接边的新端点
export function getRectReizeEdgePoint(_a) {
var point = _a.point, beforeNode = _a.beforeNode, afterNode = _a.afterNode;
var x = point.x, y = point.y;
var afterPoint = {
x: x, y: y,
};
var radius = beforeNode.radius;
var beforeNodeBox = getNodeBox(beforeNode);
var afterNodeBox = getNodeBox(afterNode);
if (x === beforeNodeBox.minX) {
// 左边
afterPoint.x = afterNodeBox.minX;
var pct = (y - beforeNode.y) / (beforeNode.height / 2 - radius);
if (pct) {
afterPoint.y = afterNode.y + (afterNode.height / 2 - radius) * pct;
}
else {
afterPoint.y = afterNode.y;
}
}
else if (x === beforeNodeBox.maxX) {
// 右边
afterPoint.x = afterNodeBox.maxX;
var pct = (y - beforeNode.y) / (beforeNode.height / 2 - radius);
if (pct) {
afterPoint.y = afterNode.y + (afterNode.height / 2 - radius) * pct;
}
else {
afterPoint.y = afterNode.y;
}
}
else if (y === beforeNodeBox.minY) {
// 上边
afterPoint.y = afterNodeBox.minY;
var pct = (x - beforeNode.x) / (beforeNode.width / 2 - radius);
if (pct) {
afterPoint.x = afterNode.x + (afterNode.width / 2 - radius) * pct;
}
else {
afterPoint.x = afterNode.x;
}
}
else if (y === beforeNodeBox.maxY) {
// 下边
afterPoint.y = afterNodeBox.maxY;
var pct = (x - beforeNode.x) / (beforeNode.width / 2 - radius);
if (pct) {
afterPoint.x = afterNode.x + (afterNode.width / 2 - radius) * pct;
}
else {
afterPoint.x = afterNode.x;
}
}
else {
// 在圆角部分
var beeforCoc = getRidusCenter(beforeNode);
var afterCoc = getRidusCenter(afterNode);
var nodeBox = getNodeBox(beforeNode);
var minX = nodeBox.minX, minY = nodeBox.minY, maxX = nodeBox.maxX, maxY = nodeBox.maxY;
var index = -1;
if (x - minX < radius && y - minY < radius) {
// 左上角
index = 0;
}
else if (maxX - x < radius && y - minY < radius) {
// 右上角
index = 1;
}
else if (maxX - x < radius && maxY - y < radius) {
// 右下角
index = 2;
}
else if (x - minX < radius && minY - y < radius) {
// 左下角
index = 3;
}
if (index > -1) {
// 根据夹角角度计算位置
var angle = Math.atan2((y - beeforCoc[index].y), (x - beeforCoc[index].x));
afterPoint.x = afterCoc[index].x + radius * Math.cos(angle);
afterPoint.y = afterCoc[index].y + radius * Math.sin(angle);
}
}
return afterPoint;
}
// 获取椭圆resize之后,与椭圆连接边的新端点
export function getEllipseReizeEdgePoint(_a) {
var point = _a.point, beforeNode = _a.beforeNode, afterNode = _a.afterNode;
var rx = afterNode.rx, ry = afterNode.ry;
var afterPoint = point;
// 将椭圆中心当做中心点(0,0),放大缩小前点与X周夹角
var tan = (point.y - beforeNode.y) / (point.x - beforeNode.x);
// 方便与公式对照,将rx命名为a,ry命名为b
var a = rx;
var b = ry;
var x;
var y;
// 将椭圆中心当做中心点(0,0),计算放大缩小后,同一夹角下,点相对位置
if (tan >= Infinity) {
// θ = PI / 2
x = 0;
y = b;
}
else if (tan <= -Infinity) {
// θ = 3 * PI / 2
x = 0;
y = -b;
}
else if (point.x - beforeNode.x > 0) {
// 0 < θ = PI / 2 或者 3 * PI / 2 < θ = 2 * PI
// 一四象限
x = (a * b) / (Math.sqrt((b * b) + a * a * tan * tan));
y = (a * b * tan) / (Math.sqrt((b * b) + a * a * tan * tan));
}
else {
// PI / 2 < θ 3 * PI / 2
// 二三象限
x = -(a * b) / (Math.sqrt((b * b) + a * a * tan * tan));
y = -(a * b * tan) / (Math.sqrt((b * b) + a * a * tan * tan));
}
afterPoint = { x: x + afterNode.x, y: y + afterNode.y };
return afterPoint;
}
// 获取菱形resize之后,与菱形连接边的新端点
export function getDiamondReizeEdgePoint(_a) {
var point = _a.point, beforeNode = _a.beforeNode, afterNode = _a.afterNode;
var afterPoint = point;
var x;
var y;
var px = point.x - beforeNode.x;
var py = point.y - beforeNode.y;
var rxBefore = beforeNode.rx;
var ryBefore = beforeNode.ry;
// eslint-disable-next-line max-len
var pct = Math.sqrt((rxBefore - Math.abs(px)) * (rxBefore - Math.abs(px)) + py * py) / Math.sqrt(rxBefore * rxBefore + ryBefore * ryBefore);
var rxAfter = afterNode.rx;
var ryAfter = afterNode.ry;
// eslint-disable-next-line max-len
var a = Math.sqrt((rxAfter * rxAfter + ryAfter * ryAfter) * pct * pct * ((rxAfter * rxAfter) / (rxAfter * rxAfter + ryAfter * ryAfter)));
var b = a * (ryAfter / rxAfter);
if (px >= 0) {
// eslint-disable-next-line max-len
x = rxAfter - a;
}
else {
x = a - rxAfter;
}
if (py > 0) {
y = b;
}
else {
y = -b;
}
afterPoint = {
x: x + afterNode.x,
y: y + afterNode.y,
};
return afterPoint;
}
@@ -0,0 +1,28 @@
import { h, DiamondNode, DiamondNodeModel } from '@logicflow/core';
declare class DiamondResizeModel extends DiamondNodeModel {
constructor(data: any, graphModel: any);
initNodeData(data: any): void;
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
getResizeOutlineStyle(): {
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
getControlPointStyle(): {
width: number;
height: number;
fill: string;
stroke: string;
};
}
declare class DiamondResizeView extends DiamondNode {
getControlGroup(): h.JSX.Element;
getResizeShape(): h.JSX.Element;
getShape(): h.JSX.Element;
}
declare const EllipseResize: {
type: string;
view: typeof DiamondResizeView;
model: typeof DiamondResizeModel;
};
export default EllipseResize;
@@ -0,0 +1,102 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { h, DiamondNode, DiamondNodeModel } from '@logicflow/core';
import ControlGroup from '../Control/ControlGroup';
import Polygon from '../BasicShape/Polygon';
var DiamondResizeModel = /** @class */ (function (_super) {
__extends(DiamondResizeModel, _super);
function DiamondResizeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var nodeSize = _this.properties.nodeSize;
if (nodeSize) {
_this.rx = nodeSize.rx;
_this.ry = nodeSize.ry;
}
return _this;
}
DiamondResizeModel.prototype.initNodeData = function (data) {
_super.prototype.initNodeData.call(this, data);
this.minWidth = 30;
this.minHeight = 30;
this.maxWidth = 2000;
this.maxHeight = 2000;
this.gridSize = 1;
};
DiamondResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
}
return style;
};
DiamondResizeModel.prototype.getResizeOutlineStyle = function () {
return {
stroke: '#000000',
strokeWidth: 1,
strokeDasharray: '3,3',
};
};
DiamondResizeModel.prototype.getControlPointStyle = function () {
return {
width: 7,
height: 7,
fill: '#FFFFFF',
stroke: '#000000',
};
};
return DiamondResizeModel;
}(DiamondNodeModel));
var DiamondResizeView = /** @class */ (function (_super) {
__extends(DiamondResizeView, _super);
function DiamondResizeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
DiamondResizeView.prototype.getControlGroup = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
return (h(ControlGroup, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础菱形的getShape功能,可以通过复写此方法,进行节点自定义
DiamondResizeView.prototype.getResizeShape = function () {
var model = this.props.model;
var points = model.points;
var style = model.getNodeStyle();
return (h("g", null,
h(Polygon, __assign({}, style, { points: points }))));
};
DiamondResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
return (h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return DiamondResizeView;
}(DiamondNode));
var EllipseResize = {
type: 'diamond',
view: DiamondResizeView,
model: DiamondResizeModel,
};
export default EllipseResize;
@@ -0,0 +1,28 @@
import { h, EllipseNode, EllipseNodeModel } from '@logicflow/core';
declare class EllipseResizeModel extends EllipseNodeModel {
constructor(data: any, graphModel: any);
initNodeData(data: any): void;
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
getResizeOutlineStyle(): {
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
getControlPointStyle(): {
width: number;
height: number;
fill: string;
stroke: string;
};
}
declare class EllipseResizeView extends EllipseNode {
getControlGroup(): h.JSX.Element;
getResizeShape(): h.JSX.Element;
getShape(): h.JSX.Element;
}
declare const EllipseResize: {
type: string;
view: typeof EllipseResizeView;
model: typeof EllipseResizeModel;
};
export default EllipseResize;
@@ -0,0 +1,85 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { h, EllipseNode, EllipseNodeModel } from '@logicflow/core';
import ControlGroup from '../Control/ControlGroup';
var EllipseResizeModel = /** @class */ (function (_super) {
__extends(EllipseResizeModel, _super);
function EllipseResizeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var nodeSize = _this.properties.nodeSize;
if (nodeSize) {
_this.rx = nodeSize.rx;
_this.ry = nodeSize.ry;
}
return _this;
}
EllipseResizeModel.prototype.initNodeData = function (data) {
_super.prototype.initNodeData.call(this, data);
this.minWidth = 30;
this.minHeight = 30;
this.maxWidth = 2000;
this.maxHeight = 2000;
};
EllipseResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
}
return style;
};
EllipseResizeModel.prototype.getResizeOutlineStyle = function () {
return {
stroke: '#000000',
strokeWidth: 1,
strokeDasharray: '3,3',
};
};
EllipseResizeModel.prototype.getControlPointStyle = function () {
return {
width: 7,
height: 7,
fill: '#FFFFFF',
stroke: '#000000',
};
};
return EllipseResizeModel;
}(EllipseNodeModel));
var EllipseResizeView = /** @class */ (function (_super) {
__extends(EllipseResizeView, _super);
function EllipseResizeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
EllipseResizeView.prototype.getControlGroup = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
return (h(ControlGroup, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础椭圆的getShape功能,可以通过复写此方法,进行节点自定义
EllipseResizeView.prototype.getResizeShape = function () {
return _super.prototype.getShape.call(this);
};
EllipseResizeView.prototype.getShape = function () {
var model = this.props.model;
return (h("g", null,
this.getResizeShape(),
model.isSelected ? this.getControlGroup() : ''));
};
return EllipseResizeView;
}(EllipseNode));
var EllipseResize = {
type: 'ellipse',
view: EllipseResizeView,
model: EllipseResizeModel,
};
export default EllipseResize;
@@ -0,0 +1,28 @@
import { h, HtmlNode, HtmlNodeModel } from '@logicflow/core';
declare class HtmlResizeModel extends HtmlNodeModel {
constructor(data: any, graphModel: any);
initNodeData(data: any): void;
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
getResizeOutlineStyle(): {
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
getControlPointStyle(): {
width: number;
height: number;
fill: string;
stroke: string;
};
}
declare class HtmlResizeView extends HtmlNode {
getControlGroup(): h.JSX.Element;
getResizeShape(): h.JSX.Element;
getShape(): h.JSX.Element;
}
declare const HtmlResize: {
type: string;
view: typeof HtmlResizeView;
model: typeof HtmlResizeModel;
};
export default HtmlResize;
@@ -0,0 +1,85 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { h, HtmlNode, HtmlNodeModel } from '@logicflow/core';
import ControlGroup from '../Control/ControlGroup';
var HtmlResizeModel = /** @class */ (function (_super) {
__extends(HtmlResizeModel, _super);
function HtmlResizeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var nodeSize = _this.properties.nodeSize;
if (nodeSize) {
_this.width = nodeSize.width;
_this.height = nodeSize.height;
}
return _this;
}
HtmlResizeModel.prototype.initNodeData = function (data) {
_super.prototype.initNodeData.call(this, data);
this.minWidth = 30;
this.minHeight = 30;
this.maxWidth = 2000;
this.maxHeight = 2000;
};
HtmlResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
}
return style;
};
HtmlResizeModel.prototype.getResizeOutlineStyle = function () {
return {
stroke: '#000000',
strokeWidth: 1,
strokeDasharray: '3,3',
};
};
HtmlResizeModel.prototype.getControlPointStyle = function () {
return {
width: 7,
height: 7,
fill: '#FFFFFF',
stroke: '#000000',
};
};
return HtmlResizeModel;
}(HtmlNodeModel));
var HtmlResizeView = /** @class */ (function (_super) {
__extends(HtmlResizeView, _super);
function HtmlResizeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
HtmlResizeView.prototype.getControlGroup = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
return (h(ControlGroup, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
HtmlResizeView.prototype.getResizeShape = function () {
return _super.prototype.getShape.call(this);
};
HtmlResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
return (h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return HtmlResizeView;
}(HtmlNode));
var HtmlResize = {
type: 'html',
view: HtmlResizeView,
model: HtmlResizeModel,
};
export default HtmlResize;
@@ -0,0 +1,30 @@
import { h, RectNode, RectNodeModel } from '@logicflow/core';
declare class RectResizeModel extends RectNodeModel {
constructor(data: any, graphModel: any);
initNodeData(data: any): void;
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
getResizeOutlineStyle(): {
fill: string;
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
getControlPointStyle(): {
width: number;
height: number;
fill: string;
stroke: string;
};
resize(deltaX: any, deltaY: any): void;
}
declare class RectResizeView extends RectNode {
getControlGroup(): h.JSX.Element;
getResizeShape(): h.JSX.Element;
getShape(): h.JSX.Element;
}
declare const RectResize: {
type: string;
view: typeof RectResizeView;
model: typeof RectResizeModel;
};
export default RectResize;
@@ -0,0 +1,89 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { h, RectNode, RectNodeModel } from '@logicflow/core';
import ControlGroup from '../Control/ControlGroup';
var RectResizeModel = /** @class */ (function (_super) {
__extends(RectResizeModel, _super);
function RectResizeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var nodeSize = _this.properties.nodeSize;
if (nodeSize) {
_this.width = nodeSize.width;
_this.height = nodeSize.height;
}
return _this;
}
RectResizeModel.prototype.initNodeData = function (data) {
_super.prototype.initNodeData.call(this, data);
this.minWidth = 30;
this.minHeight = 30;
this.maxWidth = 2000;
this.maxHeight = 2000;
};
RectResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
}
return style;
};
RectResizeModel.prototype.getResizeOutlineStyle = function () {
return {
fill: 'none',
stroke: 'transparent',
strokeWidth: 1,
strokeDasharray: '3,3',
};
};
RectResizeModel.prototype.getControlPointStyle = function () {
return {
width: 7,
height: 7,
fill: '#FFFFFF',
stroke: '#000000',
};
};
RectResizeModel.prototype.resize = function (deltaX, deltaY) {
console.log(deltaX, deltaY);
};
return RectResizeModel;
}(RectNodeModel));
var RectResizeView = /** @class */ (function (_super) {
__extends(RectResizeView, _super);
function RectResizeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
RectResizeView.prototype.getControlGroup = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
return (h(ControlGroup, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
RectResizeView.prototype.getResizeShape = function () {
return _super.prototype.getShape.call(this);
};
RectResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
return (h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return RectResizeView;
}(RectNode));
var RectResize = {
type: 'rect',
view: RectResizeView,
model: RectResizeModel,
};
export default RectResize;
+11
View File
@@ -0,0 +1,11 @@
import RectResize from './Node/RectResize';
import EllipseResize from './Node/EllipseResize';
import DiamondResize from './Node/DiamondResize';
import HtmlResize from './Node/HtmlResize';
declare const NodeResize: {
pluginName: string;
step: number;
install(lf: any): void;
};
export default NodeResize;
export { NodeResize, RectResize, EllipseResize, DiamondResize, HtmlResize, };
@@ -0,0 +1,33 @@
import RectResize from './Node/RectResize';
import EllipseResize from './Node/EllipseResize';
import DiamondResize from './Node/DiamondResize';
import HtmlResize from './Node/HtmlResize';
var NodeResize = {
pluginName: 'nodeResize',
// 拖动step
step: 0,
install: function (lf) {
lf.register({
type: RectResize.type,
view: RectResize.view,
model: RectResize.model,
});
lf.register({
type: EllipseResize.type,
view: EllipseResize.view,
model: EllipseResize.model,
});
lf.register({
type: DiamondResize.type,
view: DiamondResize.view,
model: DiamondResize.model,
});
lf.register({
type: HtmlResize.type,
view: HtmlResize.view,
model: HtmlResize.model,
});
},
};
export default NodeResize;
export { NodeResize, RectResize, EllipseResize, DiamondResize, HtmlResize, };
@@ -0,0 +1 @@
export declare function getBpmnId(): string;
@@ -0,0 +1,5 @@
import Ids from 'ids';
var ids = new Ids([32, 32, 1]);
export function getBpmnId() {
return ids.next();
}
@@ -0,0 +1,45 @@
declare const BpmnAdapter: {
pluginName: string;
install(lf: any): void;
shapeConfigMap: Map<any, any>;
setCustomShape(key: any, val: any): void;
adapterOut(data: any): {
'bpmn:definitions': {
'-id': string;
'-xmlns:xsi': string;
'-xmlns:bpmn': string;
'-xmlns:bpmndi': string;
'-xmlns:dc': string;
'-xmlns:di': string;
'-targetNamespace': string;
'-exporter': string;
'-exporterVersion': string;
'bpmn:process': {
'-id': string;
'-isExecutable': string;
};
'bpmndi:BPMNDiagram': {
'-id': string;
'bpmndi:BPMNPlane': {
'-id': string;
'-bpmnElement': string;
};
};
};
};
adapterIn(bpmnData: any): {
nodes: any[];
edges: any[];
};
};
declare const BpmnXmlAdapter: {
pluginName: string;
install(lf: any): void;
adapterXmlIn(bpmnData: any): {
nodes: any[];
edges: any[];
};
adapterXmlOut(data: any): string;
};
export { BpmnAdapter, BpmnXmlAdapter, };
export default BpmnAdapter;
@@ -0,0 +1,485 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { getBpmnId } from './bpmnIds';
import { lfJson2Xml } from './json2xml';
import { lfXml2Json } from './xml2json';
import { ExclusiveGatewayConfig, StartEventConfig, EndEventConfig, ServiceTaskConfig, UserTaskConfig, } from '../bpmn/constant';
var BpmnElements;
(function (BpmnElements) {
BpmnElements["START"] = "bpmn:startEvent";
BpmnElements["END"] = "bpmn:endEvent";
BpmnElements["GATEWAY"] = "bpmn:exclusiveGateway";
BpmnElements["USER"] = "bpmn:userTask";
BpmnElements["SYSTEM"] = "bpmn:serviceTask";
BpmnElements["FLOW"] = "bpmn:sequenceFlow";
})(BpmnElements || (BpmnElements = {}));
var defaultAttrs = ['-name', '-id', 'bpmn:incoming', 'bpmn:outgoing', '-sourceRef', '-targetRef'];
/**
* 将普通json转换为xmljson
* xmljson中properity会以“-”开头
* 如果没有“-”表示为子节点
*/
function toXmlJson(json) {
var xmlJson = {};
Object.entries(json).forEach(function (_a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
if (typeof value !== 'object') {
if (key.indexOf('-') === 0) { // 如果本来就是“-”开头的了,那就不处理了。
xmlJson[key] = value;
}
else {
xmlJson["-" + key] = value;
}
}
else {
xmlJson[key] = toXmlJson(value);
}
});
return xmlJson;
}
/**
* 将xmlJson转换为普通的json,在内部使用。
*/
function toNormalJson(xmlJson) {
var json = {};
Object.entries(xmlJson).forEach(function (_a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
if (typeof value === 'string') {
if (key.indexOf('-') === 0) { // 如果本来就是“-”开头的了,那就不处理了。
json[key.substr(1)] = value;
}
else {
json[key] = value;
}
}
else if (typeof value === 'object') {
json[key] = toNormalJson(value);
}
else {
json[key] = value;
}
});
return json;
}
/**
* 设置bpmn process信息
* 目标格式请参考examples/bpmn.json
* bpmn因为是默认基于xml格式的,其特点与json存在差异。
* 1) 如果是xml的属性,json中属性用'-'开头
* 2)如果只有一个子元素,json中表示为正常属性
* 3)如果是多个子元素,json中使用数组存储
*/
function convertLf2ProcessData(bpmnProcessData, data) {
var nodeMap = new Map();
data.nodes.forEach(function (node) {
var _a;
var processNode = {
'-id': node.id,
};
if ((_a = node.text) === null || _a === void 0 ? void 0 : _a.value) {
processNode['-name'] = node.text.value;
}
if (node.properties) {
var properties = toXmlJson(node.properties);
Object.assign(processNode, properties);
}
nodeMap.set(node.id, processNode);
if (!bpmnProcessData[node.type]) {
bpmnProcessData[node.type] = processNode; // 如果只有一个子元素,json中表示为正常属性
}
else if (Array.isArray(bpmnProcessData[node.type])) { // 如果是多个子元素,json中使用数组存储
bpmnProcessData[node.type].push(processNode);
}
else { // 如果是多个子元素,json中使用数组存储
bpmnProcessData[node.type] = [
bpmnProcessData[node.type],
processNode,
];
}
});
var sequenceFlow = data.edges.map(function (edge) {
var _a, _b;
var targetNode = nodeMap.get(edge.targetNodeId);
// @see https://github.com/didi/LogicFlow/issues/325
// 需要保证incomming在outgoing之前
if (!targetNode['bpmn:incoming']) {
targetNode['bpmn:incoming'] = edge.id;
}
else if (Array.isArray(targetNode['bpmn:incoming'])) {
targetNode['bpmn:incoming'].push(edge.id);
}
else {
targetNode['bpmn:incoming'] = [
targetNode['bpmn:incoming'],
edge.id,
];
}
var sourceNode = nodeMap.get(edge.sourceNodeId);
if (!sourceNode['bpmn:outgoing']) {
sourceNode['bpmn:outgoing'] = edge.id;
}
else if (Array.isArray(sourceNode['bpmn:outgoing'])) {
sourceNode['bpmn:outgoing'].push(edge.id);
}
else { // 字符串转数组
sourceNode['bpmn:outgoing'] = [
sourceNode['bpmn:outgoing'],
edge.id,
];
}
var edgeConfig = {
'-id': edge.id,
'-sourceRef': edge.sourceNodeId,
'-targetRef': edge.targetNodeId,
};
if ((_a = edge.text) === null || _a === void 0 ? void 0 : _a.value) {
edgeConfig['-name'] = (_b = edge.text) === null || _b === void 0 ? void 0 : _b.value;
}
if (edge.properties) {
var properties = toXmlJson(edge.properties);
Object.assign(edgeConfig, properties);
}
return edgeConfig;
});
bpmnProcessData[BpmnElements.FLOW] = sequenceFlow;
}
/**
* adapterOut 设置bpmn diagram信息
*/
function convertLf2DiagramData(bpmnDiagramData, data) {
bpmnDiagramData['bpmndi:BPMNEdge'] = data.edges.map(function (edge) {
var _a;
var edgeId = edge.id;
var pointsList = edge.pointsList.map(function (_a) {
var x = _a.x, y = _a.y;
return ({ '-x': x, '-y': y });
});
var diagramData = {
'-id': edgeId + "_di",
'-bpmnElement': edgeId,
'di:waypoint': pointsList,
};
if ((_a = edge.text) === null || _a === void 0 ? void 0 : _a.value) {
diagramData['bpmndi:BPMNLabel'] = {
'dc:Bounds': {
'-x': edge.text.x - (edge.text.value.length * 10) / 2,
'-y': edge.text.y - 7,
'-width': edge.text.value.length * 10,
'-height': 14,
},
};
}
return diagramData;
});
bpmnDiagramData['bpmndi:BPMNShape'] = data.nodes.map(function (node) {
var _a;
var nodeId = node.id;
var width = 100;
var height = 80;
var x = node.x, y = node.y;
// bpmn坐标是基于左上角,LogicFlow基于中心点,此处处理一下。
var shapeConfig = BpmnAdapter.shapeConfigMap.get(node.type);
if (shapeConfig) {
width = shapeConfig.width;
height = shapeConfig.height;
}
x -= width / 2;
y -= height / 2;
var diagramData = {
'-id': nodeId + "_di",
'-bpmnElement': nodeId,
'dc:Bounds': {
'-x': x,
'-y': y,
'-width': width,
'-height': height,
},
};
if ((_a = node.text) === null || _a === void 0 ? void 0 : _a.value) {
diagramData['bpmndi:BPMNLabel'] = {
'dc:Bounds': {
'-x': node.text.x - (node.text.value.length * 10) / 2,
'-y': node.text.y - 7,
'-width': node.text.value.length * 10,
'-height': 14,
},
};
}
return diagramData;
});
}
/**
* 将bpmn数据转换为LogicFlow内部能识别数据
*/
function convertBpmn2LfData(bpmnData) {
var nodes = [];
var edges = [];
var definitions = bpmnData['bpmn:definitions'];
if (definitions) {
var process_1 = definitions['bpmn:process'];
Object.keys(process_1).forEach(function (key) {
if (key.indexOf('bpmn:') === 0) {
var value = process_1[key];
if (key === BpmnElements.FLOW) {
var bpmnEdges = definitions['bpmndi:BPMNDiagram']['bpmndi:BPMNPlane']['bpmndi:BPMNEdge'];
edges = getLfEdges(value, bpmnEdges);
}
else {
var shapes = definitions['bpmndi:BPMNDiagram']['bpmndi:BPMNPlane']['bpmndi:BPMNShape'];
nodes = nodes.concat(getLfNodes(value, shapes, key));
}
}
});
}
return {
nodes: nodes,
edges: edges,
};
}
function getLfNodes(value, shapes, key) {
var nodes = [];
if (Array.isArray(value)) { // 数组
value.forEach(function (val) {
var shapeValue;
if (Array.isArray(shapes)) {
shapeValue = shapes.find(function (shape) { return shape['-bpmnElement'] === val['-id']; });
}
else {
shapeValue = shapes;
}
var node = getNodeConfig(shapeValue, key, val);
nodes.push(node);
});
}
else {
var shapeValue = void 0;
if (Array.isArray(shapes)) {
shapeValue = shapes.find(function (shape) { return shape['-bpmnElement'] === value['-id']; });
}
else {
shapeValue = shapes;
}
var node = getNodeConfig(shapeValue, key, value);
nodes.push(node);
}
return nodes;
}
function getNodeConfig(shapeValue, type, processValue) {
var x = Number(shapeValue['dc:Bounds']['-x']);
var y = Number(shapeValue['dc:Bounds']['-y']);
var name = processValue['-name'];
var shapeConfig = BpmnAdapter.shapeConfigMap.get(type);
if (shapeConfig) {
x += shapeConfig.width / 2;
y += shapeConfig.height / 2;
}
var properties;
// 判断是否存在额外的属性,将额外的属性放到properties中
Object.entries(processValue).forEach(function (_a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
if (defaultAttrs.indexOf(key) === -1) {
if (!properties)
properties = {};
properties[key] = value;
}
});
if (properties) {
properties = toNormalJson(properties);
}
var text;
if (name) {
text = {
x: x,
y: y,
value: name,
};
// 自定义文本位置
if (shapeValue['bpmndi:BPMNLabel'] && shapeValue['bpmndi:BPMNLabel']['dc:Bounds']) {
var textBounds = shapeValue['bpmndi:BPMNLabel']['dc:Bounds'];
text.x = Number(textBounds['-x']) + Number(textBounds['-width']) / 2;
text.y = Number(textBounds['-y']) + Number(textBounds['-height']) / 2;
}
}
var nodeConfig = {
id: shapeValue['-bpmnElement'],
type: type,
x: x,
y: y,
properties: properties,
};
if (text) {
nodeConfig.text = text;
}
return nodeConfig;
}
function getLfEdges(value, bpmnEdges) {
var edges = [];
if (Array.isArray(value)) {
value.forEach(function (val) {
var edgeValue;
if (Array.isArray(bpmnEdges)) {
edgeValue = bpmnEdges.find(function (edge) { return edge['-bpmnElement'] === val['-id']; });
}
else {
edgeValue = bpmnEdges;
}
edges.push(getEdgeConfig(edgeValue, val));
});
}
else {
var edgeValue = void 0;
if (Array.isArray(bpmnEdges)) {
edgeValue = bpmnEdges.find(function (edge) { return edge['-bpmnElement'] === value['-id']; });
}
else {
edgeValue = bpmnEdges;
}
edges.push(getEdgeConfig(edgeValue, value));
}
return edges;
}
function getEdgeConfig(edgeValue, processValue) {
var text;
var textVal = processValue['-name'];
if (textVal) {
var textBounds = edgeValue['bpmndi:BPMNLabel']['dc:Bounds'];
// 如果边文本换行,则其偏移量应该是最长一行的位置
var textLength_1 = 0;
textVal.split('\n').forEach(function (textSpan) {
if (textLength_1 < textSpan.length) {
textLength_1 = textSpan.length;
}
});
text = {
value: textVal,
x: Number(textBounds['-x']) + (textLength_1 * 10) / 2,
y: Number(textBounds['-y']) + 7,
};
}
var properties;
// 判断是否存在额外的属性,将额外的属性放到properties中
Object.entries(processValue).forEach(function (_a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
if (defaultAttrs.indexOf(key) === -1) {
if (!properties)
properties = {};
properties[key] = value;
}
});
if (properties) {
properties = toNormalJson(properties);
}
var edge = {
id: processValue['-id'],
type: BpmnElements.FLOW,
pointsList: edgeValue['di:waypoint'].map(function (point) { return ({
x: Number(point['-x']),
y: Number(point['-y']),
}); }),
sourceNodeId: processValue['-sourceRef'],
targetNodeId: processValue['-targetRef'],
properties: properties,
};
if (text) {
edge.text = text;
}
return edge;
}
var BpmnAdapter = {
pluginName: 'bpmn-adapter',
install: function (lf) {
lf.adapterIn = this.adapterIn;
lf.adapterOut = this.adapterOut;
},
shapeConfigMap: new Map(),
setCustomShape: function (key, val) {
this.shapeConfigMap.set(key, val);
},
adapterOut: function (data) {
var bpmnProcessData = {
'-id': "Process_" + getBpmnId(),
'-isExecutable': 'false',
};
convertLf2ProcessData(bpmnProcessData, data);
var bpmnDiagramData = {
'-id': 'BPMNPlane_1',
'-bpmnElement': bpmnProcessData['-id'],
};
convertLf2DiagramData(bpmnDiagramData, data);
var bpmnData = {
'bpmn:definitions': {
'-id': "Definitions_" + getBpmnId(),
'-xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'-xmlns:bpmn': 'http://www.omg.org/spec/BPMN/20100524/MODEL',
'-xmlns:bpmndi': 'http://www.omg.org/spec/BPMN/20100524/DI',
'-xmlns:dc': 'http://www.omg.org/spec/DD/20100524/DC',
'-xmlns:di': 'http://www.omg.org/spec/DD/20100524/DI',
'-targetNamespace': 'http://bpmn.io/schema/bpmn',
'-exporter': 'bpmn-js (https://demo.bpmn.io)',
'-exporterVersion': '7.3.0',
'bpmn:process': bpmnProcessData,
'bpmndi:BPMNDiagram': {
'-id': 'BPMNDiagram_1',
'bpmndi:BPMNPlane': bpmnDiagramData,
},
},
};
return bpmnData;
},
adapterIn: function (bpmnData) {
if (bpmnData) {
return convertBpmn2LfData(bpmnData);
}
},
};
BpmnAdapter.shapeConfigMap.set(BpmnElements.START, {
width: StartEventConfig.width,
height: StartEventConfig.height,
});
BpmnAdapter.shapeConfigMap.set(BpmnElements.END, {
width: EndEventConfig.width,
height: EndEventConfig.height,
});
BpmnAdapter.shapeConfigMap.set(BpmnElements.GATEWAY, {
width: ExclusiveGatewayConfig.width,
height: ExclusiveGatewayConfig.height,
});
BpmnAdapter.shapeConfigMap.set(BpmnElements.SYSTEM, {
width: ServiceTaskConfig.width,
height: ServiceTaskConfig.height,
});
BpmnAdapter.shapeConfigMap.set(BpmnElements.USER, {
width: UserTaskConfig.width,
height: UserTaskConfig.height,
});
var BpmnXmlAdapter = {
pluginName: 'bpmnXmlAdapter',
install: function (lf) {
lf.adapterIn = this.adapterXmlIn;
lf.adapterOut = this.adapterXmlOut;
},
adapterXmlIn: function (bpmnData) {
var json = lfXml2Json(bpmnData);
return BpmnAdapter.adapterIn(json);
},
adapterXmlOut: function (data) {
var outData = BpmnAdapter.adapterOut(data);
return lfJson2Xml(outData);
},
};
export { BpmnAdapter, BpmnXmlAdapter, };
export default BpmnAdapter;
@@ -0,0 +1,2 @@
declare function lfJson2Xml(o: any): string;
export { lfJson2Xml };
@@ -0,0 +1,59 @@
/**
* This work is licensed under Creative Commons GNU LGPL License.
* License:
* Version: 0.9
* Author: Stefan Goessner/2006
* Web: http://goessner.net/
*/
function addIndSpace(ind, deep) {
for (var i = 0; i < deep; i++) {
ind += ' ';
}
return ind;
}
function toXml(v, name, ind, deep) {
var xml = "";
if (v instanceof Array) {
for (var i = 0, n = v.length; i < n; i++) {
xml += addIndSpace(ind, deep) + toXml(v[i], name, ind, deep + 1);
}
}
else if (typeof (v) == "object") {
var hasChild = false;
xml += addIndSpace(ind, deep) + "<" + name;
for (var m in v) {
if (m.charAt(0) == "-")
xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
else
hasChild = true;
}
xml += hasChild ? ">" : " />";
if (hasChild) {
for (var m in v) {
if (m == "#text")
xml += v[m];
else if (m == "#cdata")
xml += "<![CDATA[" + v[m] + "]]>";
else if (m.charAt(0) != "-")
xml += toXml(v[m], m, ind, deep + 1);
}
xml += addIndSpace(ind, deep) + "</" + name + ">";
}
else {
// xml += addIndSpace(ind, deep);
}
}
else {
xml += addIndSpace(ind, deep) + "<" + name + ">" + v.toString() + "</" + name + ">";
}
return xml;
}
;
function lfJson2Xml(o) {
var xmlStr = "";
for (var m in o) {
xmlStr += toXml(o[m], m, "\t\n", 0);
}
return xmlStr;
}
export { lfJson2Xml };
@@ -0,0 +1,2 @@
declare const lfXml2Json: (xmlData: any) => any;
export { lfXml2Json, };
@@ -0,0 +1,526 @@
// @ts-nocheck
// ========================================================================
// XML.ObjTree -- XML source code from/to JavaScript object like E4X
// ========================================================================
var XML = function () { };
// constructor
XML.ObjTree = function () {
return this;
};
// class variables
XML.ObjTree.VERSION = "0.23";
// object prototype
XML.ObjTree.prototype.xmlDecl = '<?xml version="1.0" encoding="UTF-8" ?>\n';
XML.ObjTree.prototype.attr_prefix = '-';
// method: parseXML( xmlsource )
XML.ObjTree.prototype.parseXML = function (xml) {
var root;
if (window.DOMParser) {
var xmldom = new DOMParser();
// xmldom.async = false; // DOMParser is always sync-mode
var dom = xmldom.parseFromString(xml, "application/xml");
if (!dom)
return;
root = dom.documentElement;
}
else if (window.ActiveXObject) {
xmldom = new ActiveXObject('Microsoft.XMLDOM');
xmldom.async = false;
xmldom.loadXML(xml);
root = xmldom.documentElement;
}
if (!root)
return;
return this.parseDOM(root);
};
// method: parseHTTP( url, options, callback )
XML.ObjTree.prototype.parseHTTP = function (url, options, callback) {
var myopt = {};
for (var key in options) {
myopt[key] = options[key]; // copy object
}
if (!myopt.method) {
if (typeof (myopt.postBody) == "undefined" &&
typeof (myopt.postbody) == "undefined" &&
typeof (myopt.parameters) == "undefined") {
myopt.method = "get";
}
else {
myopt.method = "post";
}
}
if (callback) {
myopt.asynchronous = true; // async-mode
var __this = this;
var __func = callback;
var __save = myopt.onComplete;
myopt.onComplete = function (trans) {
var tree;
if (trans && trans.responseXML && trans.responseXML.documentElement) {
tree = __this.parseDOM(trans.responseXML.documentElement);
}
__func(tree, trans);
if (__save)
__save(trans);
};
}
else {
myopt.asynchronous = false; // sync-mode
}
var trans;
if (typeof (HTTP) != "undefined" && HTTP.Request) {
myopt.uri = url;
var req = new HTTP.Request(myopt); // JSAN
if (req)
trans = req.transport;
}
else if (typeof (Ajax) != "undefined" && Ajax.Request) {
var req = new Ajax.Request(url, myopt); // ptorotype.js
if (req)
trans = req.transport;
}
if (callback)
return trans;
if (trans && trans.responseXML && trans.responseXML.documentElement) {
return this.parseDOM(trans.responseXML.documentElement);
}
};
// method: parseDOM( documentroot )
XML.ObjTree.prototype.parseDOM = function (root) {
if (!root)
return;
this.__force_array = {};
if (this.force_array) {
for (var i = 0; i < this.force_array.length; i++) {
this.__force_array[this.force_array[i]] = 1;
}
}
var json = this.parseElement(root); // parse root node
if (this.__force_array[root.nodeName]) {
json = [json];
}
if (root.nodeType != 11) { // DOCUMENT_FRAGMENT_NODE
var tmp = {};
tmp[root.nodeName] = json; // root nodeName
json = tmp;
}
return json;
};
// method: parseElement( element )
XML.ObjTree.prototype.parseElement = function (elem) {
// COMMENT_NODE
if (elem.nodeType == 7) {
return;
}
// TEXT_NODE CDATA_SECTION_NODE
if (elem.nodeType == 3 || elem.nodeType == 4) {
var bool = elem.nodeValue.match(/[^\x00-\x20]/);
if (bool == null)
return; // ignore white spaces
return elem.nodeValue;
}
var retval;
var cnt = {};
// parse attributes
if (elem.attributes && elem.attributes.length) {
retval = {};
for (var i = 0; i < elem.attributes.length; i++) {
var key = elem.attributes[i].nodeName;
if (typeof (key) != "string")
continue;
var val = elem.attributes[i].nodeValue;
if (!val)
continue;
key = this.attr_prefix + key;
if (typeof (cnt[key]) == "undefined")
cnt[key] = 0;
cnt[key]++;
this.addNode(retval, key, cnt[key], val);
}
}
// parse child nodes (recursive)
if (elem.childNodes && elem.childNodes.length) {
var textonly = true;
if (retval)
textonly = false; // some attributes exists
for (var i = 0; i < elem.childNodes.length && textonly; i++) {
var ntype = elem.childNodes[i].nodeType;
if (ntype == 3 || ntype == 4)
continue;
textonly = false;
}
if (textonly) {
if (!retval)
retval = "";
for (var i = 0; i < elem.childNodes.length; i++) {
retval += elem.childNodes[i].nodeValue;
}
}
else {
if (!retval)
retval = {};
for (var i = 0; i < elem.childNodes.length; i++) {
var key = elem.childNodes[i].nodeName;
if (typeof (key) != "string")
continue;
var val = this.parseElement(elem.childNodes[i]);
if (!val)
continue;
if (typeof (cnt[key]) == "undefined")
cnt[key] = 0;
cnt[key]++;
this.addNode(retval, key, cnt[key], val);
}
}
}
return retval;
};
// method: addNode( hash, key, count, value )
XML.ObjTree.prototype.addNode = function (hash, key, cnts, val) {
if (this.__force_array[key]) {
if (cnts == 1)
hash[key] = [];
hash[key][hash[key].length] = val; // push
}
else if (cnts == 1) { // 1st sibling
hash[key] = val;
}
else if (cnts == 2) { // 2nd sibling
hash[key] = [hash[key], val];
}
else { // 3rd sibling and more
hash[key][hash[key].length] = val;
}
};
// method: writeXML( tree )
XML.ObjTree.prototype.writeXML = function (tree) {
var xml = this.hash_to_xml(null, tree);
return this.xmlDecl + xml;
};
// method: hash_to_xml( tagName, tree )
XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
var elem = [];
var attr = [];
for (var key in tree) {
if (!tree.hasOwnProperty(key))
continue;
var val = tree[key];
if (key.charAt(0) != this.attr_prefix) {
if (typeof (val) == "undefined" || val == null) {
elem[elem.length] = "<" + key + " />";
}
else if (typeof (val) == "object" && val.constructor == Array) {
elem[elem.length] = this.array_to_xml(key, val);
}
else if (typeof (val) == "object") {
elem[elem.length] = this.hash_to_xml(key, val);
}
else {
elem[elem.length] = this.scalar_to_xml(key, val);
}
}
else {
attr[attr.length] = " " + (key.substring(1)) + '="' + (this.xml_escape(val)) + '"';
}
}
var jattr = attr.join("");
var jelem = elem.join("");
if (typeof (name) == "undefined" || name == null) {
// no tag
}
else if (elem.length > 0) {
if (jelem.match(/\n/)) {
jelem = "<" + name + jattr + ">\n" + jelem + "</" + name + ">\n";
}
else {
jelem = "<" + name + jattr + ">" + jelem + "</" + name + ">\n";
}
}
else {
jelem = "<" + name + jattr + " />\n";
}
return jelem;
};
// method: array_to_xml( tagName, array )
XML.ObjTree.prototype.array_to_xml = function (name, array) {
var out = [];
for (var i = 0; i < array.length; i++) {
var val = array[i];
if (typeof (val) == "undefined" || val == null) {
out[out.length] = "<" + name + " />";
}
else if (typeof (val) == "object" && val.constructor == Array) {
out[out.length] = this.array_to_xml(name, val);
}
else if (typeof (val) == "object") {
out[out.length] = this.hash_to_xml(name, val);
}
else {
out[out.length] = this.scalar_to_xml(name, val);
}
}
return out.join("");
};
// method: scalar_to_xml( tagName, text )
XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
if (name == "#text") {
return this.xml_escape(text);
}
else {
return "<" + name + ">" + this.xml_escape(text) + "</" + name + ">\n";
}
};
// method: xml_escape( text )
XML.ObjTree.prototype.xml_escape = function (text) {
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
};
/*
// ========================================================================
=head1 NAME
XML.ObjTree -- XML source code from/to JavaScript object like E4X
=head1 SYNOPSIS
var xotree = new XML.ObjTree();
var tree1 = {
root: {
node: "Hello, World!"
}
};
var xml1 = xotree.writeXML( tree1 ); // object tree to XML source
alert( "xml1: "+xml1 );
var xml2 = '<?xml version="1.0"?><response><error>0</error></response>';
var tree2 = xotree.parseXML( xml2 ); // XML source to object tree
alert( "error: "+tree2.response.error );
=head1 DESCRIPTION
XML.ObjTree class is a parser/generater between XML source code
and JavaScript object like E4X, ECMAScript for XML.
This is a JavaScript version of the XML::TreePP module for Perl.
This also works as a wrapper for XMLHTTPRequest and successor to JKL.ParseXML class
when this is used with prototype.js or JSAN's HTTP.Request class.
=head2 JavaScript object tree format
A sample XML source:
<?xml version="1.0" encoding="UTF-8"?>
<family name="Kawasaki">
<father>Yasuhisa</father>
<mother>Chizuko</mother>
<children>
<girl>Shiori</girl>
<boy>Yusuke</boy>
<boy>Kairi</boy>
</children>
</family>
Its JavaScript object tree like JSON/E4X:
{
'family': {
'-name': 'Kawasaki',
'father': 'Yasuhisa',
'mother': 'Chizuko',
'children': {
'girl': 'Shiori'
'boy': [
'Yusuke',
'Kairi'
]
}
}
};
Each elements are parsed into objects:
tree.family.father; # the father's given name.
Prefix '-' is inserted before every attributes' name.
tree.family["-name"]; # this family's family name
A array is used because this family has two boys.
tree.family.children.boy[0]; # first boy's name
tree.family.children.boy[1]; # second boy's name
tree.family.children.girl; # (girl has no other sisiters)
=head1 METHODS
=head2 xotree = new XML.ObjTree()
This constructor method returns a new XML.ObjTree object.
=head2 xotree.force_array = [ "rdf:li", "item", "-xmlns" ];
This property allows you to specify a list of element names
which should always be forced into an array representation.
The default value is null, it means that context of the elements
will determine to make array or to keep it scalar.
=head2 xotree.attr_prefix = '@';
This property allows you to specify a prefix character which is
inserted before each attribute names.
Instead of default prefix '-', E4X-style prefix '@' is also available.
The default character is '-'.
Or set '@' to access attribute values like E4X, ECMAScript for XML.
The length of attr_prefix must be just one character and not be empty.
=head2 tree = xotree.parseXML( xmlsrc );
This method loads an XML document using the supplied string
and returns its JavaScript object converted.
=head2 tree = xotree.parseDOM( domnode );
This method parses a DOM tree (ex. responseXML.documentElement)
and returns its JavaScript object converted.
=head2 tree = xotree.parseHTTP( url, options );
This method loads a XML file from remote web server
and returns its JavaScript object converted.
XMLHTTPRequest's synchronous mode is always used.
This mode blocks the process until the response is completed.
First argument is a XML file's URL
which must exist in the same domain as parent HTML file's.
Cross-domain loading is not available for security reasons.
Second argument is options' object which can contains some parameters:
method, postBody, parameters, onLoading, etc.
This method requires JSAN's L<HTTP.Request> class or prototype.js's Ajax.Request class.
=head2 xotree.parseHTTP( url, options, callback );
If a callback function is set as third argument,
XMLHTTPRequest's asynchronous mode is used.
This mode calls a callback function with XML file's JavaScript object converted
after the response is completed.
=head2 xmlsrc = xotree.writeXML( tree );
This method parses a JavaScript object tree
and returns its XML source generated.
=head1 EXAMPLES
=head2 Text node and attributes
If a element has both of a text node and attributes
or both of a text node and other child nodes,
text node's value is moved to a special node named "#text".
var xotree = new XML.ObjTree();
var xmlsrc = '<span class="author">Kawasaki Yusuke</span>';
var tree = xotree.parseXML( xmlsrc );
var class = tree.span["-class"]; # attribute
var name = tree.span["#text"]; # text node
=head2 parseHTTP() method with HTTP-GET and sync-mode
HTTP/Request.js or prototype.js must be loaded before calling this method.
var xotree = new XML.ObjTree();
var url = "http://example.com/index.html";
var tree = xotree.parseHTTP( url );
xotree.attr_prefix = '@'; // E4X-style
alert( tree.html["@lang"] );
This code shows C<lang=""> attribute from a X-HTML source code.
=head2 parseHTTP() method with HTTP-POST and async-mode
Third argument is a callback function which is called on onComplete.
var xotree = new XML.ObjTree();
var url = "http://example.com/mt-tb.cgi";
var opts = {
postBody: "title=...&excerpt=...&url=...&blog_name=..."
};
var func = function ( tree ) {
alert( tree.response.error );
};
xotree.parseHTTP( url, opts, func );
This code send a trackback ping and shows its response code.
=head2 Simple RSS reader
This is a RSS reader which loads RDF file and displays all items.
var xotree = new XML.ObjTree();
xotree.force_array = [ "rdf:li", "item" ];
var url = "http://example.com/news-rdf.xml";
var func = function( tree ) {
var elem = document.getElementById("rss_here");
for( var i=0; i<tree["rdf:RDF"].item.length; i++ ) {
var divtag = document.createElement( "div" );
var atag = document.createElement( "a" );
atag.href = tree["rdf:RDF"].item[i].link;
var title = tree["rdf:RDF"].item[i].title;
var tnode = document.createTextNode( title );
atag.appendChild( tnode );
divtag.appendChild( atag );
elem.appendChild( divtag );
}
};
xotree.parseHTTP( url, {}, func );
=head2 XML-RPC using writeXML, prototype.js and parseDOM
If you wish to use prototype.js's Ajax.Request class by yourself:
var xotree = new XML.ObjTree();
var reqtree = {
methodCall: {
methodName: "weblogUpdates.ping",
params: {
param: [
{ value: "Kawa.net xp top page" }, // 1st param
{ value: "http://www.kawa.net/" } // 2nd param
]
}
}
};
var reqxml = xotree.writeXML( reqtree ); // JS-Object to XML code
var url = "http://example.com/xmlrpc";
var func = function( req ) {
var resdom = req.responseXML.documentElement;
xotree.force_array = [ "member" ];
var restree = xotree.parseDOM( resdom ); // XML-DOM to JS-Object
alert( restree.methodResponse.params.param.value.struct.member[0].value.string );
};
var opt = {
method: "post",
postBody: reqxml,
asynchronous: true,
onComplete: func
};
new Ajax.Request( url, opt );
=head1 AUTHOR
Yusuke Kawasaki http://www.kawa.net/
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2005-2006 Yusuke Kawasaki. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the Artistic license. Or whatever license I choose,
which I will do instead of keeping this documentation like it is.
=cut
// ========================================================================
*/
var lfXml2Json = function (xmlData) {
return new XML.ObjTree().parseXML(xmlData);
};
export { lfXml2Json, };
+46
View File
@@ -0,0 +1,46 @@
export declare const StartEventConfig: {
width: number;
height: number;
};
export declare const EndEventConfig: {
width: number;
height: number;
};
export declare const ExclusiveGatewayConfig: {
width: number;
height: number;
};
export declare const ServiceTaskConfig: {
width: number;
height: number;
};
export declare const UserTaskConfig: {
width: number;
height: number;
};
export declare const theme: {
rect: {
radius: number;
stroke: string;
};
circle: {
r: number;
stroke: string;
};
polygon: {
stroke: string;
};
polyline: {
stroke: string;
hoverStroke: string;
selectedStroke: string;
};
edgeText: {
background: {
fill: string;
height: number;
stroke: string;
radius: number;
};
};
};
@@ -0,0 +1,46 @@
export var StartEventConfig = {
width: 40,
height: 40,
};
export var EndEventConfig = {
width: 40,
height: 40,
};
export var ExclusiveGatewayConfig = {
width: 40,
height: 40,
};
export var ServiceTaskConfig = {
width: 100,
height: 80,
};
export var UserTaskConfig = {
width: 100,
height: 80,
};
export var theme = {
rect: {
radius: 5,
stroke: 'rgb(24, 125, 255)',
},
circle: {
r: 18,
stroke: 'rgb(24, 125, 255)',
},
polygon: {
stroke: 'rgb(24, 125, 255)',
},
polyline: {
stroke: 'rgb(24, 125, 255)',
hoverStroke: 'rgb(24, 125, 255)',
selectedStroke: 'rgb(24, 125, 255)',
},
edgeText: {
background: {
fill: 'white',
height: 14,
stroke: 'transparent',
radius: 3,
},
},
};
@@ -0,0 +1,21 @@
import { CircleNode, CircleNodeModel } from '@logicflow/core';
declare class EndEventModel extends CircleNodeModel {
static extendKey: string;
constructor(data: any, graphModel: any);
setAttributes(): void;
getConnectedSourceRules(): import("@logicflow/core").ConnectRule[];
}
declare class EndEventView extends CircleNode {
static extendKey: string;
getAnchorStyle(): {
visibility: string;
};
getShape(): import("preact").VNode<any>;
}
declare const EndEvent: {
type: string;
view: typeof EndEventView;
model: typeof EndEventModel;
};
export { EndEventView, EndEventModel };
export default EndEvent;
@@ -0,0 +1,88 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { CircleNode, CircleNodeModel, h } from '@logicflow/core';
import { getBpmnId } from '../getBpmnId';
var EndEventModel = /** @class */ (function (_super) {
__extends(EndEventModel, _super);
function EndEventModel(data, graphModel) {
var _this = this;
if (!data.id) {
data.id = "Event_" + getBpmnId();
}
if (!data.text) {
data.text = '';
}
if (data.text && typeof data.text === 'string') {
data.text = {
value: data.text,
x: data.x,
y: data.y + 40,
};
}
_this = _super.call(this, data, graphModel) || this;
return _this;
}
EndEventModel.prototype.setAttributes = function () {
this.r = 18;
};
EndEventModel.prototype.getConnectedSourceRules = function () {
var rules = _super.prototype.getConnectedSourceRules.call(this);
var notAsSource = {
message: '结束节点不能作为边的起点',
validate: function () { return false; },
};
rules.push(notAsSource);
return rules;
};
EndEventModel.extendKey = 'EndEventModel';
return EndEventModel;
}(CircleNodeModel));
var EndEventView = /** @class */ (function (_super) {
__extends(EndEventView, _super);
function EndEventView() {
return _super !== null && _super.apply(this, arguments) || this;
}
EndEventView.prototype.getAnchorStyle = function () {
return {
visibility: 'hidden',
};
};
EndEventView.prototype.getShape = function () {
var model = this.props.model;
var style = model.getNodeStyle();
var x = model.x, y = model.y, r = model.r;
var outCircle = _super.prototype.getShape.call(this);
return h('g', {}, outCircle, h('circle', __assign(__assign({}, style), { cx: x, cy: y, r: r - 5 })));
};
EndEventView.extendKey = 'EndEventView';
return EndEventView;
}(CircleNode));
var EndEvent = {
type: 'bpmn:endEvent',
view: EndEventView,
model: EndEventModel,
};
export { EndEventView, EndEventModel };
export default EndEvent;
@@ -0,0 +1,17 @@
import { CircleNode, CircleNodeModel } from '@logicflow/core';
declare class StartEventModel extends CircleNodeModel {
static extendKey: string;
constructor(data: any, graphModel: any);
setAttributes(): void;
getConnectedTargetRules(): import("@logicflow/core").ConnectRule[];
}
declare class StartEventView extends CircleNode {
static extendKey: string;
}
declare const StartEvent: {
type: string;
view: typeof StartEventView;
model: typeof StartEventModel;
};
export { StartEventModel, StartEventView };
export default StartEvent;
@@ -0,0 +1,67 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { CircleNode, CircleNodeModel } from '@logicflow/core';
import { getBpmnId } from '../getBpmnId';
var StartEventModel = /** @class */ (function (_super) {
__extends(StartEventModel, _super);
function StartEventModel(data, graphModel) {
var _this = this;
if (!data.id) {
data.id = "Event_" + getBpmnId();
}
if (!data.text) {
data.text = '';
}
if (data.text && typeof data.text === 'string') {
data.text = {
value: data.text,
x: data.x,
y: data.y + 40,
};
}
// fix: 不能直接全部加,会导致下载后再次上传,位置错误。
// data.text.y += 40;
_this = _super.call(this, data, graphModel) || this;
return _this;
}
StartEventModel.prototype.setAttributes = function () {
this.r = 18;
};
StartEventModel.prototype.getConnectedTargetRules = function () {
var rules = _super.prototype.getConnectedTargetRules.call(this);
var notAsTarget = {
message: '起始节点不能作为边的终点',
validate: function () { return false; },
};
rules.push(notAsTarget);
return rules;
};
StartEventModel.extendKey = 'StartEventModel';
return StartEventModel;
}(CircleNodeModel));
var StartEventView = /** @class */ (function (_super) {
__extends(StartEventView, _super);
function StartEventView() {
return _super !== null && _super.apply(this, arguments) || this;
}
StartEventView.extendKey = 'StartEventNode';
return StartEventView;
}(CircleNode));
var StartEvent = {
type: 'bpmn:startEvent',
view: StartEventView,
model: StartEventModel,
};
export { StartEventModel, StartEventView };
export default StartEvent;
@@ -0,0 +1,15 @@
import { PolylineEdge, PolylineEdgeModel } from '@logicflow/core';
declare class SequenceFlowModel extends PolylineEdgeModel {
static extendKey: string;
constructor(data: any, graphModel: any);
}
declare class SequenceFlowView extends PolylineEdge {
static extendKey: string;
}
declare const SequenceFlow: {
type: string;
view: typeof SequenceFlowView;
model: typeof SequenceFlowModel;
};
export { SequenceFlowView, SequenceFlowModel };
export default SequenceFlow;
@@ -0,0 +1,43 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { PolylineEdge, PolylineEdgeModel } from '@logicflow/core';
import { getBpmnId } from '../getBpmnId';
var SequenceFlowModel = /** @class */ (function (_super) {
__extends(SequenceFlowModel, _super);
function SequenceFlowModel(data, graphModel) {
var _this = this;
if (!data.id) {
data.id = "Flow_" + getBpmnId();
}
_this = _super.call(this, data, graphModel) || this;
return _this;
}
SequenceFlowModel.extendKey = 'SequenceFlowModel';
return SequenceFlowModel;
}(PolylineEdgeModel));
var SequenceFlowView = /** @class */ (function (_super) {
__extends(SequenceFlowView, _super);
function SequenceFlowView() {
return _super !== null && _super.apply(this, arguments) || this;
}
SequenceFlowView.extendKey = 'SequenceFlowEdge';
return SequenceFlowView;
}(PolylineEdge));
var SequenceFlow = {
type: 'bpmn:sequenceFlow',
view: SequenceFlowView,
model: SequenceFlowModel,
};
export { SequenceFlowView, SequenceFlowModel };
export default SequenceFlow;
@@ -0,0 +1,16 @@
import { PolygonNode, PolygonNodeModel } from '@logicflow/core';
declare class ExclusiveGatewayModel extends PolygonNodeModel {
static extendKey: string;
constructor(data: any, graphModel: any);
}
declare class ExclusiveGatewayView extends PolygonNode {
static extendKey: string;
getShape(): import("preact").VNode<any>;
}
declare const ExclusiveGateway: {
type: string;
view: typeof ExclusiveGatewayView;
model: typeof ExclusiveGatewayModel;
};
export { ExclusiveGatewayView, ExclusiveGatewayModel };
export default ExclusiveGateway;
@@ -0,0 +1,80 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { h, PolygonNode, PolygonNodeModel } from '@logicflow/core';
import { getBpmnId } from '../getBpmnId';
var ExclusiveGatewayModel = /** @class */ (function (_super) {
__extends(ExclusiveGatewayModel, _super);
function ExclusiveGatewayModel(data, graphModel) {
var _this = this;
if (!data.id) {
data.id = "Gateway_" + getBpmnId();
}
if (!data.text) {
data.text = '';
}
if (data.text && typeof data.text === 'string') {
data.text = {
value: data.text,
x: data.x,
y: data.y + 40,
};
}
_this = _super.call(this, data, graphModel) || this;
_this.points = [
[25, 0],
[50, 25],
[25, 50],
[0, 25],
];
return _this;
}
ExclusiveGatewayModel.extendKey = 'ExclusiveGatewayModel';
return ExclusiveGatewayModel;
}(PolygonNodeModel));
var ExclusiveGatewayView = /** @class */ (function (_super) {
__extends(ExclusiveGatewayView, _super);
function ExclusiveGatewayView() {
return _super !== null && _super.apply(this, arguments) || this;
}
ExclusiveGatewayView.prototype.getShape = function () {
var model = this.props.model;
var x = model.x, y = model.y, width = model.width, height = model.height, points = model.points;
var style = model.getNodeStyle();
return h('g', {
transform: "matrix(1 0 0 1 " + (x - width / 2) + " " + (y - height / 2) + ")",
}, h('polygon', __assign(__assign({}, style), { x: x,
y: y,
points: points })), h('path', __assign({ d: 'm 16,15 7.42857142857143,9.714285714285715 -7.42857142857143,9.714285714285715 3.428571428571429,0 5.714285714285715,-7.464228571428572 5.714285714285715,7.464228571428572 3.428571428571429,0 -7.42857142857143,-9.714285714285715 7.42857142857143,-9.714285714285715 -3.428571428571429,0 -5.714285714285715,7.464228571428572 -5.714285714285715,-7.464228571428572 -3.428571428571429,0 z' }, style)));
};
ExclusiveGatewayView.extendKey = 'ExclusiveGatewayNode';
return ExclusiveGatewayView;
}(PolygonNode));
var ExclusiveGateway = {
type: 'bpmn:exclusiveGateway',
view: ExclusiveGatewayView,
model: ExclusiveGatewayModel,
};
export { ExclusiveGatewayView, ExclusiveGatewayModel };
export default ExclusiveGateway;
+1
View File
@@ -0,0 +1 @@
export declare function getBpmnId(): string;
@@ -0,0 +1,5 @@
import Ids from 'ids';
var ids = new Ids([32, 32, 1]);
export function getBpmnId() {
return ids.next();
}
+13
View File
@@ -0,0 +1,13 @@
import { StartEventModel, StartEventView } from './events/StartEvent';
import { EndEventView, EndEventModel } from './events/EndEvent';
import { ExclusiveGatewayView, ExclusiveGatewayModel } from './gateways/ExclusiveGateway';
import { UserTaskView, UserTaskModel } from './tasks/UserTask';
import { ServiceTaskView, ServiceTaskModel } from './tasks/ServiceTask';
import { SequenceFlowView, SequenceFlowModel } from './flow/SequenceFlow';
declare class BpmnElement {
static pluginName: string;
constructor({ lf }: {
lf: any;
});
}
export { BpmnElement, StartEventModel, StartEventView, EndEventView, EndEventModel, ExclusiveGatewayView, ExclusiveGatewayModel, UserTaskView, UserTaskModel, ServiceTaskView, ServiceTaskModel, SequenceFlowView, SequenceFlowModel, };
@@ -0,0 +1,28 @@
// import LogicFlow from '@logicflow/core';
import StartEvent, { StartEventModel, StartEventView } from './events/StartEvent';
import EndEvent, { EndEventView, EndEventModel } from './events/EndEvent';
import ExclusiveGateway, { ExclusiveGatewayView, ExclusiveGatewayModel } from './gateways/ExclusiveGateway';
import UserTask, { UserTaskView, UserTaskModel } from './tasks/UserTask';
import ServiceTask, { ServiceTaskView, ServiceTaskModel } from './tasks/ServiceTask';
import SequenceFlow, { SequenceFlowView, SequenceFlowModel } from './flow/SequenceFlow';
import { theme } from './constant';
// todo: name
var BpmnElement = /** @class */ (function () {
function BpmnElement(_a) {
var lf = _a.lf;
lf.setTheme(theme);
lf.register(StartEvent);
lf.register(EndEvent);
lf.register(ExclusiveGateway);
lf.register(UserTask);
lf.register(ServiceTask);
// 支持自定义bpmn元素的边
if (!lf.options.customBpmnEdge) {
lf.register(SequenceFlow);
lf.setDefaultEdgeType('bpmn:sequenceFlow');
}
}
BpmnElement.pluginName = 'bpmnElement';
return BpmnElement;
}());
export { BpmnElement, StartEventModel, StartEventView, EndEventView, EndEventModel, ExclusiveGatewayView, ExclusiveGatewayModel, UserTaskView, UserTaskModel, ServiceTaskView, ServiceTaskModel, SequenceFlowView, SequenceFlowModel, };
@@ -0,0 +1,17 @@
import { RectNodeModel, RectNode } from '@logicflow/core';
declare class ServiceTaskModel extends RectNodeModel {
static extendKey: string;
constructor(data: any, graphModel: any);
}
declare class ServiceTaskView extends RectNode {
static extendKey: string;
getLabelShape(): import("preact").VNode<any>;
getShape(): import("preact").VNode<any>;
}
declare const ServiceTask: {
type: string;
view: typeof ServiceTaskView;
model: typeof ServiceTaskModel;
};
export { ServiceTaskView, ServiceTaskModel };
export default ServiceTask;
@@ -0,0 +1,79 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { h, RectNodeModel, RectNode } from '@logicflow/core';
import { getBpmnId } from '../getBpmnId';
var ServiceTaskModel = /** @class */ (function (_super) {
__extends(ServiceTaskModel, _super);
function ServiceTaskModel(data, graphModel) {
var _this = this;
if (!data.id) {
data.id = "Activity_" + getBpmnId();
}
_this = _super.call(this, data, graphModel) || this;
return _this;
}
ServiceTaskModel.extendKey = 'ServiceTaskModel';
return ServiceTaskModel;
}(RectNodeModel));
var ServiceTaskView = /** @class */ (function (_super) {
__extends(ServiceTaskView, _super);
function ServiceTaskView() {
return _super !== null && _super.apply(this, arguments) || this;
}
ServiceTaskView.prototype.getLabelShape = function () {
var model = this.props.model;
var x = model.x, y = model.y, width = model.width, height = model.height;
var style = model.getNodeStyle();
return h('svg', {
x: x - width / 2 + 5,
y: y - height / 2 + 5,
width: 30,
height: 30,
viewBox: '0 0 1274 1024',
}, h('path', {
fill: style.stroke,
d: 'M882.527918 434.149934c-2.234901-5.303796-7.311523-8.853645-13.059434-9.138124l-61.390185-3.009544c-6.635117-20.973684-15.521508-41.175795-26.513864-60.282968l42.051745-47.743374c4.308119-4.889357 4.955872-12.004405 1.602498-17.59268-46.384423-77.30362-103.969956-101.422947-106.400309-102.410438-5.332449-2.170432-11.432377-1.090844-15.693424 2.77009L654.674467 240.664222c-17.004279-8.654101-35.092239-15.756869-53.995775-21.210068l-3.26537-66.490344c-0.280386-5.747911-3.833305-10.824533-9.134031-13.059434-1.683339-0.709151-30.193673-12.391215-76.866668-12.051477-46.672996-0.339738-75.18333 11.342326-76.866668 12.051477-5.300726 2.234901-8.853645 7.311523-9.134031 13.059434l-3.26537 66.490344c-18.903535 5.453199-36.991496 12.555967-53.995775 21.210068l-48.450479-43.922349c-4.261047-3.860934-10.360975-4.940522-15.693424-2.77009-2.430352 0.98749-60.015885 25.106818-106.400309 102.410438-3.353374 5.588275-2.705622 12.703323 1.602498 17.59268l42.051745 47.743374c-10.992355 19.107173-19.878746 39.309284-26.513864 60.282968l-61.390185 3.009544c-5.747911 0.284479-10.824533 3.834328-13.059434 9.138124-1.01512 2.415003-24.687262 60.190871-2.822278 147.651828 1.583055 6.324032 7.072069 10.893094 13.57518 11.308557 5.892197 0.37146 11.751648 0.523933 17.419741 0.667196 14.498202 0.372483 28.193109 0.723477 40.908712 4.63353 4.212952 1.294482 6.435573 8.270361 9.349949 18.763342 1.287319 4.640694 2.617617 9.43693 4.484128 14.010085 1.794879 4.393054 3.75758 8.570189 5.66093 12.607132 1.302669 2.765997 2.529613 5.380544 3.689019 8.018627 2.986007 6.803963 2.682086 9.773598 2.578732 10.349719-3.061732 3.672646-6.391571 7.238868-9.91379 11.015891-1.810229 1.943258-3.680832 3.949962-5.523807 5.980201l-22.560832 24.8909c-3.865028 4.261047-4.940522 10.365068-2.774183 15.693424 0.991584 2.426259 25.102724 60.011792 102.414531 106.400309 5.588275 3.353374 12.703323 2.701528 17.591657-1.603521l23.476691-20.682042c2.346441-2.061962 4.64888-4.336772 6.875594-6.534833 9.05319-8.93858 14.018272-12.95608 17.73185-11.576663 3.305279 1.222851 6.907317 3.166109 10.720156 5.228071 3.325745 1.794879 6.764054 3.650133 10.465352 5.288446 6.016017 2.662643 12.120039 4.688789 18.019399 6.65149 6.827499 2.266623 13.279445 4.409426 18.819624 7.275707 1.518586 0.782829 1.926886 0.994654 2.358721 7.830339 0.726547 11.496845 1.25048 23.276123 1.753947 34.672684 0.264013 5.900384 0.528026 11.803837 0.815575 17.700127 0.284479 5.743818 3.833305 10.82044 9.138124 13.05534 1.654686 0.698918 29.371958 12.063757 74.869175 12.063757 0.328481 0 3.65832 0 3.986801 0 45.497217 0 73.214489-11.364839 74.869175-12.063757 5.304819-2.234901 8.853645-7.311523 9.138124-13.05534 0.287549-5.89629 0.551562-11.799744 0.815575-17.700127 0.503467-11.396561 1.027399-23.175839 1.753947-34.672684 0.431835-6.835685 0.840134-7.04751 2.358721-7.830339 5.54018-2.866281 11.992125-5.009084 18.819624-7.275707 5.89936-1.962701 12.003382-3.988848 18.019399-6.65149 3.701299-1.638313 7.139607-3.493567 10.465352-5.288446 3.812839-2.061962 7.414877-4.00522 10.720156-5.228071 3.713578-1.379417 8.67866 2.638083 17.73185 11.576663 2.226714 2.198062 4.529153 4.472871 6.875594 6.534833l23.476691 20.682042c4.888334 4.305049 12.003382 4.956895 17.591657 1.603521 77.311807-46.388517 101.422947-103.97405 102.414531-106.400309 2.166339-5.328355 1.090844-11.432377-2.774183-15.693424l-22.560832-24.8909c-1.842974-2.030239-3.713578-4.036943-5.523807-5.980201-3.52222-3.777023-6.852058-7.343245-9.91379-11.015891-0.103354-0.576121-0.407276-3.545756 2.578732-10.349719 1.159406-2.638083 2.38635-5.252631 3.689019-8.018627 1.90335-4.036943 3.866051-8.214079 5.66093-12.607132 1.866511-4.573155 3.196809-9.369392 4.484128-14.010085 2.914376-10.492982 5.136997-17.46886 9.349949-18.763342 12.715603-3.910053 26.41051-4.261047 40.908712-4.63353 5.668093-0.143263 11.527544-0.295735 17.419741-0.667196 6.503111-0.415462 11.992125-4.984524 13.57518-11.308557C907.21518 494.340805 883.543038 436.564937 882.527918 434.149934zM643.49894 643.761929c-35.280528 35.280528-82.191954 54.711066-132.086317 54.711066s-96.806813-19.430538-132.086317-54.711066c-35.280528-35.279504-54.711066-82.191954-54.711066-132.086317 0-49.894364 19.430538-96.80272 54.711066-132.082224 35.283598-35.284621 82.191954-54.711066 132.086317-54.711066s96.80579 19.426445 132.086317 54.711066c35.279504 35.279504 54.711066 82.187861 54.711066 132.082224C698.210006 561.569976 678.782537 608.482425 643.49894 643.761929z',
}));
};
ServiceTaskView.prototype.getShape = function () {
var model = this.props.model;
var x = model.x, y = model.y, width = model.width, height = model.height, radius = model.radius;
var style = model.getNodeStyle();
return h('g', {}, [
h('rect', __assign({ x: x - width / 2, y: y - height / 2, rx: radius, ry: radius, width: width,
height: height }, style)),
this.getLabelShape(),
]);
};
ServiceTaskView.extendKey = 'ServiceTaskNode';
return ServiceTaskView;
}(RectNode));
var ServiceTask = {
type: 'bpmn:serviceTask',
view: ServiceTaskView,
model: ServiceTaskModel,
};
export { ServiceTaskView, ServiceTaskModel };
export default ServiceTask;
@@ -0,0 +1,17 @@
import { RectNode, RectNodeModel } from '@logicflow/core';
declare class UserTaskModel extends RectNodeModel {
static extendKey: string;
constructor(data: any, graphModel: any);
}
declare class UserTaskView extends RectNode {
static extendKey: string;
getLabelShape(): import("preact").VNode<any>;
getShape(): import("preact").VNode<any>;
}
declare const UserTask: {
type: string;
view: typeof UserTaskView;
model: typeof UserTaskModel;
};
export { UserTaskView, UserTaskModel };
export default UserTask;
@@ -0,0 +1,80 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { h, RectNode, RectNodeModel } from '@logicflow/core';
import { getBpmnId } from '../getBpmnId';
var UserTaskModel = /** @class */ (function (_super) {
__extends(UserTaskModel, _super);
function UserTaskModel(data, graphModel) {
var _this = this;
if (!data.id) {
data.id = "Activity_" + getBpmnId();
}
_this = _super.call(this, data, graphModel) || this;
return _this;
}
UserTaskModel.extendKey = 'UserTaskModel';
return UserTaskModel;
}(RectNodeModel));
var UserTaskView = /** @class */ (function (_super) {
__extends(UserTaskView, _super);
function UserTaskView() {
return _super !== null && _super.apply(this, arguments) || this;
}
UserTaskView.prototype.getLabelShape = function () {
var model = this.props.model;
var x = model.x, y = model.y, width = model.width, height = model.height;
var style = model.getNodeStyle();
return h('svg', {
x: x - width / 2 + 5,
y: y - height / 2 + 5,
width: 25,
height: 25,
viewBox: '0 0 1274 1024',
}, h('path', {
fill: style.stroke,
d: 'M655.807326 287.35973m-223.989415 0a218.879 218.879 0 1 0 447.978829 0 218.879 218.879 0 1 0-447.978829 0ZM1039.955839 895.482975c-0.490184-212.177424-172.287821-384.030443-384.148513-384.030443-211.862739 0-383.660376 171.85302-384.15056 384.030443L1039.955839 895.482975z',
}));
};
UserTaskView.prototype.getShape = function () {
var model = this.props.model;
var x = model.x, y = model.y, width = model.width, height = model.height, radius = model.radius;
var style = model.getNodeStyle();
// todo: 将basic-shape对外暴露,在这里可以直接用。现在纯手写有点麻烦。
return h('g', {}, [
h('rect', __assign(__assign({}, style), { x: x - width / 2, y: y - height / 2, rx: radius, ry: radius, width: width,
height: height })),
this.getLabelShape(),
]);
};
UserTaskView.extendKey = 'UserTaskNode';
return UserTaskView;
}(RectNode));
var UserTask = {
type: 'bpmn:userTask',
view: UserTaskView,
model: UserTaskModel,
};
export { UserTaskView, UserTaskModel };
export default UserTask;
@@ -0,0 +1,34 @@
declare class ContextMenu {
static pluginName: string;
private __menuDOM;
private lf;
private _activeData;
private menuTypeMap;
container: any;
isShow: boolean;
constructor({ lf }: {
lf: any;
});
render(lf: any, container: any): void;
setContextMenuByType(type: any, menus: any): void;
/**
* 隐藏菜单
*/
hideContextMenu(): void;
/**
* 显示指定元素菜单
* @param data 节点id、节点类型、菜单位置
*/
showContextMenu(data: any): void;
setContextMenuItems(menus: any): void;
/**
* 获取新菜单位置
*/
private getContextMenuPosition;
private createContextMenu;
private addNode;
private showMenu;
listenDelete: () => void;
}
export default ContextMenu;
export { ContextMenu, };
@@ -0,0 +1,222 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var COMMON_TYPE_KEY = 'menu-common';
var NEXT_X_DISTANCE = 200;
var NEXT_Y_DISTANCE = 100;
var ContextMenu = /** @class */ (function () {
function ContextMenu(_a) {
var _this = this;
var lf = _a.lf;
this.menuTypeMap = new Map();
this.listenDelete = function () {
_this.hideContextMenu();
};
this.lf = lf;
this.__menuDOM = document.createElement('div');
this.__menuDOM.className = 'lf-inner-context';
this.menuTypeMap.set(COMMON_TYPE_KEY, []);
this.lf.setContextMenuByType = function (type, menus) {
_this.setContextMenuByType(type, menus);
};
this.lf.setContextMenuItems = function (menus) {
_this.setContextMenuItems(menus);
};
this.lf.showContextMenu = function (data) {
_this.showContextMenu(data);
};
this.lf.hideContextMenu = function () {
_this.hideContextMenu();
};
}
ContextMenu.prototype.render = function (lf, container) {
var _this = this;
this.container = container;
lf.on('node:click', function (_a) {
var data = _a.data;
_this._activeData = data;
_this.createContextMenu();
});
lf.on('edge:click', function (_a) {
var data = _a.data;
// 获取右上角坐标
_this._activeData = data;
_this.createContextMenu();
});
lf.on('blank:click', function () {
_this.hideContextMenu();
});
};
ContextMenu.prototype.setContextMenuByType = function (type, menus) {
this.menuTypeMap.set(type, menus);
};
/**
* 隐藏菜单
*/
ContextMenu.prototype.hideContextMenu = function () {
this.__menuDOM.innerHTML = '';
this.__menuDOM.style.display = 'none';
if (this.isShow) {
this.container.removeChild(this.__menuDOM);
}
this.lf.off('node:delete,edge:delete,node:drag,graph:transform', this.listenDelete);
this.isShow = false;
};
/**
* 显示指定元素菜单
* @param data 节点id、节点类型、菜单位置
*/
ContextMenu.prototype.showContextMenu = function (data) {
if (!data || !data.id) {
console.warn('请检查传入的参数');
return;
}
this._activeData = data;
this.createContextMenu();
};
ContextMenu.prototype.setContextMenuItems = function (menus) {
this.menuTypeMap.set(COMMON_TYPE_KEY, menus);
};
/**
* 获取新菜单位置
*/
ContextMenu.prototype.getContextMenuPosition = function () {
var data = this._activeData;
var Model = this.lf.graphModel.getElement(data.id);
if (!Model) {
console.warn("\u627E\u4E0D\u5230\u5143\u7D20" + data.id);
return;
}
var x;
var y;
if (Model.BaseType === 'edge') {
x = Number.MIN_SAFE_INTEGER;
y = Number.MAX_SAFE_INTEGER;
var edgeData = Model.getData();
x = Math.max(edgeData.startPoint.x, x);
y = Math.min(edgeData.startPoint.y, y);
x = Math.max(edgeData.endPoint.x, x);
y = Math.min(edgeData.endPoint.y, y);
if (edgeData.pointsList) {
edgeData.pointsList.forEach(function (point) {
x = Math.max(point.x, x);
y = Math.min(point.y, y);
});
}
}
if (Model.BaseType === 'node') {
x = data.x + Model.width / 2;
y = data.y - Model.height / 2;
}
return this.lf.graphModel.transformModel.CanvasPointToHtmlPoint([x, y]);
};
ContextMenu.prototype.createContextMenu = function () {
var _this = this;
var isSilentMode = this.lf.options.isSilentMode;
// 静默模式不显示菜单
if (isSilentMode) {
return;
}
var items = this.menuTypeMap.get(this._activeData.type) || [];
items = items.concat(this.menuTypeMap.get(COMMON_TYPE_KEY));
var menus = document.createDocumentFragment();
items.forEach(function (item) {
var menuItem = document.createElement('div');
menuItem.className = 'lf-context-item';
var img = document.createElement('img');
img.src = item.icon;
img.className = 'lf-context-img';
if (item.className) {
menuItem.className = menuItem.className + " " + item.className;
}
img.addEventListener('click', function () {
_this.hideContextMenu();
if (item.callback) {
item.callback(_this._activeData);
}
else {
_this.addNode({
sourceId: _this._activeData.id,
x: _this._activeData.x,
y: _this._activeData.y,
properties: item.properties,
type: item.type,
});
}
});
menuItem.appendChild(img);
menus.appendChild(menuItem);
});
this.__menuDOM.innerHTML = '';
this.__menuDOM.appendChild(menus);
this.showMenu();
};
ContextMenu.prototype.addNode = function (node, y) {
var isDeep = y !== undefined;
if (y === undefined) {
y = node.y;
}
var nodeModel = this.lf.getNodeModelById(node.sourceId);
var leftTopX = node.x - nodeModel.width + NEXT_X_DISTANCE;
var leftTopY = y - node.y / 2 - 20;
var rightBottomX = node.x + nodeModel.width + NEXT_X_DISTANCE;
var rightBottomY = y + node.y / 2 + 20;
var exsitElements = this.lf.getAreaElement([leftTopX, leftTopY], [rightBottomX, rightBottomY]);
if (exsitElements.length) {
y = y + NEXT_Y_DISTANCE;
this.addNode(node, y);
return;
}
var newNode = this.lf.addNode({
type: node.type,
x: node.x + 200,
y: y,
properties: node.properties,
});
var startPoint;
var endPoint;
if (isDeep) {
startPoint = {
x: node.x,
y: node.y + nodeModel.height / 2,
};
endPoint = {
x: newNode.x - newNode.width / 2,
y: newNode.y,
};
}
this.lf.addEdge({
sourceNodeId: node.sourceId,
targetNodeId: newNode.id,
startPoint: startPoint,
endPoint: endPoint,
});
};
ContextMenu.prototype.showMenu = function () {
var _a = __read(this.getContextMenuPosition(), 2), x = _a[0], y = _a[1];
this.__menuDOM.style.display = 'flex';
this.__menuDOM.style.top = y + "px";
this.__menuDOM.style.left = x + 10 + "px";
this.container.appendChild(this.__menuDOM);
// 菜单显示的时候,监听删除,同时隐藏
!this.isShow && this.lf.on('node:delete,edge:delete,node:drag,graph:transform', this.listenDelete);
this.isShow = true;
};
ContextMenu.pluginName = 'contextMenu';
return ContextMenu;
}());
export default ContextMenu;
export { ContextMenu, };
@@ -0,0 +1,26 @@
declare type ControlItem = {
key: string;
iconClass: string;
title: string;
text: string;
onClick?: Function;
onMouseEnter?: Function;
onMouseLeave?: Function;
};
declare class Control {
private lf;
static pluginName: string;
private controlItems;
private domContainer;
private toolEl;
constructor({ lf }: {
lf: any;
});
render(lf: any, domContainer: any): void;
destroy(): void;
addItem(item: any): void;
removeItem(key: any): ControlItem;
private getControlTool;
}
export default Control;
export { Control };
@@ -0,0 +1,139 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var Control = /** @class */ (function () {
function Control(_a) {
var _this = this;
var lf = _a.lf;
this.controlItems = [
{
key: 'zoom-out',
iconClass: 'lf-control-zoomOut',
title: '缩小流程图',
text: '缩小',
onClick: function () {
_this.lf.zoom(false);
},
},
{
key: 'zoom-in',
iconClass: 'lf-control-zoomIn',
title: '放大流程图',
text: '放大',
onClick: function () {
_this.lf.zoom(true);
},
},
{
key: 'reset',
iconClass: 'lf-control-fit',
title: '恢复流程原有尺寸',
text: '适应',
onClick: function () {
_this.lf.resetZoom();
},
},
{
key: 'undo',
iconClass: 'lf-control-undo',
title: '回到上一步',
text: '上一步',
onClick: function () {
_this.lf.undo();
},
},
{
key: 'redo',
iconClass: 'lf-control-redo',
title: '移到下一步',
text: '下一步',
onClick: function () {
_this.lf.redo();
},
},
];
this.lf = lf;
}
Control.prototype.render = function (lf, domContainer) {
this.destroy();
var toolEl = this.getControlTool();
this.toolEl = toolEl;
domContainer.appendChild(toolEl);
this.domContainer = domContainer;
};
Control.prototype.destroy = function () {
if (this.domContainer && this.toolEl && this.domContainer.contains(this.toolEl)) {
this.domContainer.removeChild(this.toolEl);
}
};
Control.prototype.addItem = function (item) {
this.controlItems.push(item);
};
Control.prototype.removeItem = function (key) {
var index = this.controlItems.findIndex(function (item) { return item.key === key; });
return this.controlItems.splice(index, 1)[0];
};
Control.prototype.getControlTool = function () {
var _this = this;
var NORMAL = 'lf-control-item';
var DISABLED = 'lf-control-item disabled';
var controlTool = document.createElement('div');
var controlElements = [];
controlTool.className = 'lf-control';
this.controlItems.forEach(function (item) {
var itemContainer = document.createElement('div');
var icon = document.createElement('i');
var text = document.createElement('span');
itemContainer.className = DISABLED;
item.onClick && (itemContainer.onclick = item.onClick.bind(null, _this.lf));
item.onMouseEnter && (itemContainer.onmouseenter = item.onMouseEnter.bind(null, _this.lf));
item.onMouseLeave && (itemContainer.onmouseleave = item.onMouseLeave.bind(null, _this.lf));
icon.className = item.iconClass;
text.className = 'lf-control-text';
text.title = item.title;
text.innerText = item.text;
itemContainer.append(icon, text);
switch (item.text) {
case '上一步':
_this.lf.on('history:change', function (_a) {
var undoAble = _a.data.undoAble;
itemContainer.className = undoAble ? NORMAL : DISABLED;
});
break;
case '下一步':
_this.lf.on('history:change', function (_a) {
var redoAble = _a.data.redoAble;
itemContainer.className = redoAble ? NORMAL : DISABLED;
});
break;
default:
itemContainer.className = NORMAL;
break;
}
controlElements.push(itemContainer);
});
controlTool.append.apply(controlTool, __spread(controlElements));
return controlTool;
};
Control.pluginName = 'control';
return Control;
}());
export default Control;
export { Control };
@@ -0,0 +1,25 @@
import LogicFlow from '@logicflow/core';
declare type ShapeItem = {
type?: string;
text?: string;
icon?: string;
label?: string;
className?: string;
properties?: Record<string, any>;
callback?: (lf: LogicFlow, container: HTMLElement) => void;
};
declare class DndPanel {
lf: LogicFlow;
shapeList: ShapeItem[];
panelEl: HTMLDivElement;
static pluginName: string;
domContainer: HTMLElement;
constructor({ lf }: {
lf: any;
});
render(lf: any, domContainer: any): void;
destroy(): void;
setPatternItems(shapeList: any): void;
private createDndItem;
}
export { DndPanel, };
@@ -0,0 +1,71 @@
var DndPanel = /** @class */ (function () {
function DndPanel(_a) {
var _this = this;
var lf = _a.lf;
this.lf = lf;
this.lf.setPatternItems = function (shapeList) {
_this.setPatternItems(shapeList);
};
}
DndPanel.prototype.render = function (lf, domContainer) {
var _this = this;
this.destroy();
if (!this.shapeList || this.shapeList.length === 0) {
// 首次render后失败后,后续调用setPatternItems支持渲染
this.domContainer = domContainer;
return;
}
this.panelEl = document.createElement('div');
this.panelEl.className = 'lf-dndpanel';
this.shapeList.forEach(function (shapeItem) {
_this.panelEl.appendChild(_this.createDndItem(shapeItem));
});
domContainer.appendChild(this.panelEl);
this.domContainer = domContainer;
};
DndPanel.prototype.destroy = function () {
if (this.domContainer && this.panelEl && this.domContainer.contains(this.panelEl)) {
this.domContainer.removeChild(this.panelEl);
}
};
DndPanel.prototype.setPatternItems = function (shapeList) {
this.shapeList = shapeList;
// 支持渲染后重新设置拖拽面板
if (this.domContainer) {
this.render(this.lf, this.domContainer);
}
};
DndPanel.prototype.createDndItem = function (shapeItem) {
var _this = this;
var el = document.createElement('div');
el.className = shapeItem.className ? "lf-dnd-item " + shapeItem.className : 'lf-dnd-item';
var shape = document.createElement('div');
shape.className = 'lf-dnd-shape';
if (shapeItem.icon) {
shape.style.backgroundImage = "url(" + shapeItem.icon + ")";
}
el.appendChild(shape);
if (shapeItem.label) {
var text = document.createElement('div');
text.innerText = shapeItem.label;
text.className = 'lf-dnd-text';
el.appendChild(text);
}
el.onmousedown = function () {
if (shapeItem.type) {
_this.lf.dnd.startDrag({
type: shapeItem.type,
properties: shapeItem.properties,
text: shapeItem.text,
});
}
if (shapeItem.callback) {
shapeItem.callback(_this.lf, _this.domContainer);
}
};
return el;
};
DndPanel.pluginName = 'dndPanel';
return DndPanel;
}());
export { DndPanel, };
@@ -0,0 +1,50 @@
import LogicFlow from '@logicflow/core';
declare type SetType = 'add' | 'reset';
export declare type MenuItem = {
text?: string;
className?: string;
icon?: boolean;
callback: (element: any) => void;
};
export declare type MenuConfig = {
nodeMenu?: MenuItem[] | false;
edgeMenu?: MenuItem[] | false;
graphMenu?: MenuItem[] | false;
};
declare class Menu {
lf: LogicFlow;
private __container;
private __menuDOM;
private menuTypeMap;
private __currentData;
static pluginName: string;
constructor({ lf }: {
lf: any;
});
/**
* 初始化设置默认内置菜单栏
*/
private init;
render(lf: any, container: any): void;
destroy(): void;
private showMenu;
/**
* 设置指定类型元素的菜单
*/
private setMenuByType;
/**
* 获取 Menu DOM
* @param list 菜单项
* @return 菜单项 DOM
*/
private __getMenuDom;
setMenuConfig(config: MenuConfig): void;
addMenuConfig(config: MenuConfig): void;
/**
* @deprecated
* 复写添加
*/
changeMenuItem(type: SetType, config: MenuConfig): void;
}
export default Menu;
export { Menu, };
@@ -0,0 +1,300 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var DefalutNodeMenuKey = 'lf:defaultNodeMenu';
var DefalutEdgeMenuKey = 'lf:defaultEdgeMenu';
var DefalutGraphMenuKey = 'lf:defaultGraphMenu';
var DefalutSelectionMenuKey = 'lf:defaultSelectionMenu';
var Menu = /** @class */ (function () {
function Menu(_a) {
var _this = this;
var lf = _a.lf;
this.__menuDOM = document.createElement('ul');
this.lf = lf;
this.menuTypeMap = new Map();
this.init();
this.lf.setMenuConfig = function (config) {
_this.setMenuConfig(config);
};
this.lf.addMenuConfig = function (config) {
_this.addMenuConfig(config);
};
this.lf.setMenuByType = function (config) {
_this.setMenuByType(config);
};
}
/**
* 初始化设置默认内置菜单栏
*/
Menu.prototype.init = function () {
var _this = this;
var defalutNodeMenu = [
{
text: '删除',
callback: function (node) {
_this.lf.deleteNode(node.id);
},
},
{
text: '编辑文本',
callback: function (node) {
_this.lf.graphModel.editText(node.id);
},
},
{
text: '复制',
callback: function (node) {
_this.lf.cloneNode(node.id);
},
},
];
this.menuTypeMap.set(DefalutNodeMenuKey, defalutNodeMenu);
var defaultEdgeMenu = [
{
text: '删除',
callback: function (edge) {
_this.lf.deleteEdge(edge.id);
},
},
{
text: '编辑文本',
callback: function (edge) {
_this.lf.graphModel.editText(edge.id);
},
},
];
this.menuTypeMap.set(DefalutEdgeMenuKey, defaultEdgeMenu);
this.menuTypeMap.set(DefalutGraphMenuKey, []);
var DefalutSelectionMenu = [
{
text: '删除',
callback: function (elements) {
_this.lf.clearSelectElements();
elements.edges.forEach(function (edge) { return _this.lf.deleteEdge(edge.id); });
elements.nodes.forEach(function (node) { return _this.lf.deleteNode(node.id); });
},
},
];
this.menuTypeMap.set(DefalutSelectionMenuKey, DefalutSelectionMenu);
};
Menu.prototype.render = function (lf, container) {
var _this = this;
this.__container = container;
this.__currentData = null; // 当前展示的菜单所属元素的model数据
this.__menuDOM.className = 'lf-menu';
container.appendChild(this.__menuDOM);
// 将选项的click事件委托至menu容器
// 在捕获阶段拦截并执行
this.__menuDOM.addEventListener('click', function (event) {
event.stopPropagation();
var target = event.target;
// 菜单有多层dom,需要精确获取菜单项所对应的dom
// 除菜单项dom外,应考虑两种情况
// 1. 菜单项的子元素 2. 菜单外层容器
while (Array.from(target.classList).indexOf('lf-menu-item') === -1 && Array.from(target.classList).indexOf('lf-menu') === -1) {
target = target.parentElement;
}
if (Array.from(target.classList).indexOf('lf-menu-item') > -1) {
// 如果点击区域在菜单项内
target.onclickCallback(_this.__currentData);
// 点击后隐藏menu
_this.__menuDOM.style.display = 'none';
_this.__currentData = null;
}
else {
// 如果点击区域不在菜单项内
console.warn('点击区域不在菜单项内,请检查代码!');
}
}, true);
// 通过事件控制菜单的显示和隐藏
this.lf.on('node:contextmenu', function (_a) {
var data = _a.data, position = _a.position;
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
var id = data.id;
var model = _this.lf.graphModel.getNodeModelById(id);
var menuList = [];
var typeMenus = _this.menuTypeMap.get(model.type);
// 如果单个节点自定义了节点,以单个节点自定义为准
if (model && model.menu && Array.isArray(model.menu)) {
menuList = model.menu;
}
else if (typeMenus) { // 如果定义当前节点类型的元素
menuList = typeMenus;
}
else { // 最后取全局默认
menuList = _this.menuTypeMap.get(DefalutNodeMenuKey);
}
_this.__currentData = data;
_this.showMenu(x, y, menuList);
});
this.lf.on('edge:contextmenu', function (_a) {
var data = _a.data, position = _a.position;
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
var id = data.id;
var model = _this.lf.graphModel.getEdgeModelById(id);
var menuList = [];
var typeMenus = _this.menuTypeMap.get(model.type);
// 如果单个节点自定义了边
if (model && model.menu && Array.isArray(model.menu)) {
menuList = model.menu;
}
else if (typeMenus) { // 如果定义当前边类型的元素
menuList = typeMenus;
}
else { // 最后取全局默认
menuList = _this.menuTypeMap.get(DefalutEdgeMenuKey);
}
_this.__currentData = data;
_this.showMenu(x, y, menuList);
});
this.lf.on('blank:contextmenu', function (_a) {
var position = _a.position;
var menuList = _this.menuTypeMap.get(DefalutGraphMenuKey);
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
_this.showMenu(x, y, menuList);
});
this.lf.on('selection:contextmenu', function (_a) {
var data = _a.data, position = _a.position;
var menuList = _this.menuTypeMap.get(DefalutSelectionMenuKey);
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
_this.__currentData = data;
_this.showMenu(x, y, menuList);
});
this.lf.on('node:mousedown', function () {
_this.__menuDOM.style.display = 'none';
});
this.lf.on('edge:click', function () {
_this.__menuDOM.style.display = 'none';
});
this.lf.on('blank:click', function () {
_this.__menuDOM.style.display = 'none';
});
};
Menu.prototype.destroy = function () {
var _a;
(_a = this === null || this === void 0 ? void 0 : this.__container) === null || _a === void 0 ? void 0 : _a.removeChild(this.__menuDOM);
this.__menuDOM = null;
};
Menu.prototype.showMenu = function (x, y, menuList) {
if (!menuList || !menuList.length)
return;
var menu = this.__menuDOM;
// 菜单容器不变,需要先清空内部的菜单项
menu.innerHTML = '';
menu.append.apply(menu, __spread(this.__getMenuDom(menuList)));
// 菜单中没有项,不显示
if (!menu.children.length)
return;
menu.style.display = 'block';
menu.style.top = y + "px";
menu.style.left = x + "px";
};
/**
* 设置指定类型元素的菜单
*/
Menu.prototype.setMenuByType = function (config) {
if (!config.type || !config.menu) {
return;
}
this.menuTypeMap.set(config.type, config.menu);
};
/**
* 获取 Menu DOM
* @param list 菜单项
* @return 菜单项 DOM
*/
Menu.prototype.__getMenuDom = function (list) {
var menuList = [];
list && list.length > 0 && list.forEach(function (item) {
var element = document.createElement('li');
if (item.className) {
element.className = "lf-menu-item " + item.className;
}
else {
element.className = 'lf-menu-item';
}
if (item.icon === true) {
var icon = document.createElement('span');
icon.className = 'lf-menu-item-icon';
element.appendChild(icon);
}
var text = document.createElement('span');
text.className = 'lf-menu-item-text';
if (item.text) {
text.innerText = item.text;
}
element.appendChild(text);
element.onclickCallback = item.callback;
menuList.push(element);
});
return menuList;
};
// 复写菜单
Menu.prototype.setMenuConfig = function (config) {
if (!config) {
return;
}
// node
config.nodeMenu !== undefined
&& this.menuTypeMap.set(DefalutNodeMenuKey, config.nodeMenu ? config.nodeMenu : []);
// edge
config.edgeMenu !== undefined
&& this.menuTypeMap.set(DefalutEdgeMenuKey, config.edgeMenu ? config.edgeMenu : []);
// graph
config.graphMenu !== undefined
&& this.menuTypeMap.set(DefalutGraphMenuKey, config.graphMenu ? config.graphMenu : []);
};
// 在默认菜单后面追加菜单项
Menu.prototype.addMenuConfig = function (config) {
if (!config) {
return;
}
// 追加项时,只支持数组类型,对false不做操作
if (Array.isArray(config.nodeMenu)) {
var menuList = this.menuTypeMap.get(DefalutNodeMenuKey);
this.menuTypeMap.set(DefalutNodeMenuKey, menuList.concat(config.nodeMenu));
}
if (Array.isArray(config.edgeMenu)) {
var menuList = this.menuTypeMap.get(DefalutEdgeMenuKey);
this.menuTypeMap.set(DefalutEdgeMenuKey, menuList.concat(config.edgeMenu));
}
if (Array.isArray(config.graphMenu)) {
var menuList = this.menuTypeMap.get(DefalutGraphMenuKey);
this.menuTypeMap.set(DefalutGraphMenuKey, menuList.concat(config.graphMenu));
}
};
/**
* @deprecated
* 复写添加
*/
Menu.prototype.changeMenuItem = function (type, config) {
if (type === 'add')
this.addMenuConfig(config);
else if (type === 'reset')
this.setMenuConfig(config);
else {
throw new Error('The first parameter of changeMenuConfig should be \'add\' or \'reset\'');
}
};
Menu.pluginName = 'menu';
return Menu;
}());
export default Menu;
export { Menu, };
@@ -0,0 +1,75 @@
declare class MiniMap {
static pluginName: string;
__lf: any;
__container: any;
__miniMapWrap: any;
__miniMapContainer: any;
__lfMap: any;
__viewport: any;
__width: number;
__height: number;
__miniMapWidth: number;
__miniMapHeight: number;
__viewPortTop: number;
__viewPortLeft: number;
__startPosition: any;
__viewPortScale: number;
__viewPortWidth: number;
__viewPortHeight: number;
__resetDataX: number;
__resetDataY: number;
__LogicFlow: any;
__isShow: boolean;
__disabledPlugins: string[];
constructor({ lf, LogicFlow }: {
lf: any;
LogicFlow: any;
});
render(lf: any, container: any): void;
init(option: any): void;
/**
* 显示mini map
*/
show: (leftPosition?: number, topPosition?: number) => void;
/**
* 隐藏mini map
*/
hide: () => void;
__init(): void;
__createMiniMap(left: any, top: any): void;
__removeMiniMap(): void;
/**
* 计算所有图形一起,占领的区域范围。
* @param data
*/
__getBounds(data: any): {
left: number;
top: number;
bottom: number;
right: number;
};
/**
* 将负值的平移转换为正值。
* 保证渲染的时候,minimap能完全展示。
* 获取将画布所有元素平移到0,0开始时,所有节点数据
*/
__resetData(data: any): any;
/**
* 显示导航
* 显示视口范围
* 1. 基于画布的范围比例,设置视口范围比例。宽度默认为导航宽度。
*/
__setView(): void;
__setViewPort(scale: any, { left, right, top, bottom }: {
left: any;
right: any;
top: any;
bottom: any;
}): void;
__createViewPort(): void;
__startDrag: (e: any) => void;
__drag: (e: any) => void;
__drop: () => void;
}
export default MiniMap;
export { MiniMap };
@@ -0,0 +1,325 @@
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var MiniMap = /** @class */ (function () {
function MiniMap(_a) {
var _this = this;
var lf = _a.lf, LogicFlow = _a.LogicFlow;
this.__lf = null;
this.__container = null;
this.__miniMapWrap = null;
this.__miniMapContainer = null;
this.__lfMap = null;
this.__viewport = null;
this.__width = 150;
this.__height = 220;
this.__miniMapWidth = 450;
this.__miniMapHeight = 660;
this.__viewPortTop = 0;
this.__viewPortLeft = 0;
this.__startPosition = null;
this.__viewPortScale = 1;
this.__viewPortWidth = 150;
this.__viewPortHeight = 75;
this.__resetDataX = 0;
this.__resetDataY = 0;
this.__LogicFlow = null;
this.__isShow = false;
this.__disabledPlugins = ['miniMap', 'control', 'selectionSelect'];
/**
* 显示mini map
*/
this.show = function (leftPosition, topPosition) {
_this.__setView();
if (!_this.__isShow) {
_this.__createMiniMap(leftPosition, topPosition);
}
_this.__isShow = true;
};
/**
* 隐藏mini map
*/
this.hide = function () {
if (_this.__isShow) {
_this.__removeMiniMap();
}
_this.__isShow = false;
};
this.__startDrag = function (e) {
document.addEventListener('mousemove', _this.__drag);
document.addEventListener('mouseup', _this.__drop);
_this.__startPosition = {
x: e.x,
y: e.y,
};
};
this.__drag = function (e) {
var viewStyle = _this.__viewport.style;
_this.__viewPortTop += e.y - _this.__startPosition.y;
_this.__viewPortLeft += e.x - _this.__startPosition.x;
viewStyle.top = _this.__viewPortTop + "px";
viewStyle.left = _this.__viewPortLeft + "px";
_this.__startPosition = {
x: e.x,
y: e.y,
};
var centerX = (_this.__viewPortLeft + _this.__viewPortWidth / 2)
/ _this.__viewPortScale;
var centerY = (_this.__viewPortTop + _this.__viewPortHeight / 2)
/ _this.__viewPortScale;
_this.__lf.focusOn({
coordinate: {
x: centerX + _this.__resetDataX,
y: centerY + _this.__resetDataY,
},
});
};
this.__drop = function () {
document.removeEventListener('mousemove', _this.__drag);
document.removeEventListener('mouseup', _this.__drop);
};
this.__lf = lf;
this.__miniMapWidth = lf.graphModel.width;
this.__miniMapHeight = (lf.graphModel.width * 220) / 150;
this.__LogicFlow = LogicFlow;
this.__init();
}
MiniMap.prototype.render = function (lf, container) {
var _this = this;
this.__container = container;
this.__lf.on('history:change', function () {
if (_this.__isShow) {
_this.__setView();
}
});
};
MiniMap.prototype.init = function (option) {
this.__disabledPlugins = this.__disabledPlugins.concat(option.disabledPlugins || []);
};
MiniMap.prototype.__init = function () {
var miniMapWrap = document.createElement('div');
miniMapWrap.className = 'lf-mini-map-graph';
miniMapWrap.style.width = this.__width + "px";
miniMapWrap.style.height = this.__height + "px";
this.__lfMap = new this.__LogicFlow({
width: this.__lf.graphModel.width,
height: (this.__lf.graphModel.width * 220) / 150,
container: miniMapWrap,
isSilentMode: true,
stopZoomGraph: true,
stopScrollGraph: true,
stopMoveGraph: true,
hideAnchors: true,
hoverOutline: false,
disabledPlugins: this.__disabledPlugins,
});
// minimap中禁用adapter。
this.__lfMap.adapterIn = function (a) { return a; };
this.__lfMap.adapterOut = function (a) { return a; };
this.__miniMapWrap = miniMapWrap;
this.__createViewPort();
};
MiniMap.prototype.__createMiniMap = function (left, top) {
var miniMapContainer = document.createElement('div');
var miniMapWrap = this.__miniMapWrap;
miniMapContainer.appendChild(miniMapWrap);
if (typeof left !== 'undefined' && typeof top !== 'undefined') {
miniMapContainer.style.left = left + "px";
miniMapContainer.style.top = top + "px";
}
miniMapContainer.style.position = 'absolute';
miniMapContainer.className = 'lf-mini-map';
this.__container.appendChild(miniMapContainer);
this.__miniMapWrap.appendChild(this.__viewport);
var header = document.createElement('div');
header.className = 'lf-mini-map-header';
header.innerText = '导航';
miniMapContainer.appendChild(header);
var close = document.createElement('span');
close.className = 'lf-mini-map-close';
close.addEventListener('click', this.hide);
miniMapContainer.appendChild(close);
this.__miniMapContainer = miniMapContainer;
};
MiniMap.prototype.__removeMiniMap = function () {
this.__container.removeChild(this.__miniMapContainer);
};
/**
* 计算所有图形一起,占领的区域范围。
* @param data
*/
MiniMap.prototype.__getBounds = function (data) {
var left = 0;
var right = this.__miniMapWidth;
var top = 0;
var bottom = this.__miniMapHeight;
var nodes = data.nodes;
if (nodes && nodes.length > 0) {
// 因为获取的节点不知道真实的宽高,这里需要补充一点数值
nodes.forEach(function (_a) {
var x = _a.x, y = _a.y, _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c;
var nodeLeft = x - width / 2;
var noderight = x + width / 2;
var nodeTop = y - height / 2;
var nodeBottom = y + height / 2;
left = nodeLeft < left ? nodeLeft : left;
right = noderight > right ? noderight : right;
top = nodeTop < top ? nodeTop : top;
bottom = nodeBottom > bottom ? nodeBottom : bottom;
});
}
return {
left: left,
top: top,
bottom: bottom,
right: right,
};
};
/**
* 将负值的平移转换为正值。
* 保证渲染的时候,minimap能完全展示。
* 获取将画布所有元素平移到0,0开始时,所有节点数据
*/
MiniMap.prototype.__resetData = function (data) {
var nodes = data.nodes, edges = data.edges;
var left = 0;
var top = 0;
if (nodes && nodes.length > 0) {
// 因为获取的节点不知道真实的宽高,这里需要补充一点数值
nodes.forEach(function (_a) {
var x = _a.x, y = _a.y, _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c;
var nodeLeft = x - width / 2;
var nodeTop = y - height / 2;
left = nodeLeft < left ? nodeLeft : left;
top = nodeTop < top ? nodeTop : top;
});
if (left < 0 || top < 0) {
this.__resetDataX = left;
this.__resetDataY = top;
nodes.forEach(function (node) {
node.x = node.x - left;
node.y = node.y - top;
if (node.text) {
node.text.x = node.text.x - left;
node.text.y = node.text.y - top;
}
});
edges.forEach(function (edge) {
if (edge.startPoint) {
edge.startPoint.x = edge.startPoint.x - left;
edge.startPoint.y = edge.startPoint.y - top;
}
if (edge.endPoint) {
edge.endPoint.x = edge.endPoint.x - left;
edge.endPoint.y = edge.endPoint.y - top;
}
if (edge.text) {
edge.text.x = edge.text.x - left;
edge.text.y = edge.text.y - top;
}
if (edge.pointsList) {
edge.pointsList.forEach(function (point) {
point.x = point.x - left;
point.y = point.y - top;
});
}
});
}
}
return data;
};
/**
* 显示导航
* 显示视口范围
* 1. 基于画布的范围比例,设置视口范围比例。宽度默认为导航宽度。
*/
MiniMap.prototype.__setView = function () {
var e_1, _a;
// 1. 获取到图中所有的节点中的位置,将其偏移到原点开始(避免节点位置为负的时候无法展示问题)。
var data = this.__resetData(this.__lf.getGraphRawData());
// 由于随时都会有新节点注册进来,需要同步将注册的
var viewMap = this.__lf.viewMap;
var modelMap = this.__lf.graphModel.modelMap;
var minimapViewMap = this.__lfMap.viewMap;
try {
// todo: no-restricted-syntax
for (var _b = __values(viewMap.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;
if (!minimapViewMap.has(key)) {
this.__lfMap.setView(key, viewMap.get(key));
this.__lfMap.graphModel.modelMap.set(key, modelMap.get(key));
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
this.__lfMap.render(data);
// 2. 将偏移后的数据渲染到minimap画布上
// 3. 计算出所有节点在一起的边界。
var _d = this.__getBounds(data), left = _d.left, top = _d.top, right = _d.right, bottom = _d.bottom;
// 4. 计算所有节点的边界与minimap看板的边界的比例.
var realWidthScale = this.__width / (right - left);
var realHeightScale = this.__height / (bottom - top);
// 5. 取比例最小的值,将渲染的画布缩小对应比例。
var innerStyle = this.__miniMapWrap.firstChild.style;
var scale = Math.min(realWidthScale, realHeightScale);
innerStyle.transform = "matrix(" + scale + ", 0, 0, " + scale + ", 0, 0)";
innerStyle.transformOrigin = 'left top';
innerStyle.height = bottom - Math.min(top, 0) + "px";
innerStyle.width = right - Math.min(left, 0) + "px";
this.__viewPortScale = scale;
this.__setViewPort(scale, {
left: left,
top: top,
right: right,
bottom: bottom,
});
};
// 设置视口
MiniMap.prototype.__setViewPort = function (scale, _a) {
var left = _a.left, right = _a.right, top = _a.top, bottom = _a.bottom;
var viewStyle = this.__viewport.style;
viewStyle.width = this.__width - 4 + "px";
viewStyle.height = (this.__width - 4) / (this.__lf.graphModel.width / this.__lf.graphModel.height) + "px";
// top
var _b = this.__lf.getTransform(), TRANSLATE_X = _b.TRANSLATE_X, TRANSLATE_Y = _b.TRANSLATE_Y;
var realWidth = right - left;
// 视口实际宽 = 视口默认宽 / (所有元素一起占据的真实宽 / 绘布宽)
var realViewPortWidth = (this.__width - 4) / (realWidth / this.__lf.graphModel.width);
// 视口实际高 = 视口实际宽 / (绘布宽 / 绘布高)
var graphRatio = (this.__lf.graphModel.width / this.__lf.graphModel.height);
var realViewPortHeight = realViewPortWidth / graphRatio;
this.__viewPortTop = TRANSLATE_Y > 0 ? 0 : -TRANSLATE_Y * scale;
this.__viewPortLeft = -TRANSLATE_X * scale;
this.__viewPortWidth = realViewPortWidth;
this.__viewPortHeight = realViewPortHeight;
viewStyle.top = this.__viewPortTop + "px";
viewStyle.left = this.__viewPortLeft + "px";
viewStyle.width = realViewPortWidth + "px";
viewStyle.height = realViewPortHeight + "px";
};
// 预览视窗
MiniMap.prototype.__createViewPort = function () {
var div = document.createElement('div');
div.className = 'lf-minimap-viewport';
div.addEventListener('mousedown', this.__startDrag);
this.__viewport = div;
};
MiniMap.pluginName = 'miniMap';
return MiniMap;
}());
export default MiniMap;
export { MiniMap };
@@ -0,0 +1,42 @@
import LogicFlow from '@logicflow/core';
declare class SelectionSelect {
__domContainer: HTMLElement;
wrapper: HTMLElement;
lf: LogicFlow;
startPoint: {
x: number;
y: number;
};
endPoint: {
x: number;
y: number;
};
__disabled: boolean;
isDefalutStopMoveGraph: boolean;
isWholeNode: boolean;
isWholeEdge: boolean;
static pluginName: string;
constructor({ lf }: {
lf: any;
});
render(lf: any, domContainer: any): void;
/**
* 设置选中的灵敏度
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
* @param isWholeNode 是否要节点的全部点都在选区范围才算选中。默认true
*/
setSelectionSense(isWholeEdge?: boolean, isWholeNode?: boolean): void;
/**
* 开启选区
*/
openSelectionSelect(): void;
/**
* 关闭选区
*/
closeSelectionSelect(): void;
__draw: (ev: any) => void;
__drawOff: () => void;
open(): void;
close(): void;
}
export { SelectionSelect };
@@ -0,0 +1,127 @@
var SelectionSelect = /** @class */ (function () {
function SelectionSelect(_a) {
var _this = this;
var lf = _a.lf;
this.__disabled = false;
this.isDefalutStopMoveGraph = false;
this.isWholeNode = true;
this.isWholeEdge = true;
this.__draw = function (ev) {
var _a = _this.lf.getPointByClient(ev.clientX, ev.clientY).domOverlayPosition, x1 = _a.x, y1 = _a.y;
_this.endPoint = { x: x1, y: y1 };
var _b = _this.startPoint, x = _b.x, y = _b.y;
var style = _this.wrapper.style;
var left = x;
var top = y;
var width = x1 - x;
var height = y1 - y;
if (x1 < x) {
left = x1;
width = x - x1;
}
if (y1 < y) {
top = y1;
height = y - y1;
}
style.left = left + "px";
style.top = top + "px";
style.width = width + "px";
style.height = height + "px";
};
this.__drawOff = function () {
document.removeEventListener('mousemove', _this.__draw);
document.removeEventListener('mouseup', _this.__drawOff);
_this.__domContainer.removeChild(_this.wrapper);
var _a = _this.startPoint, x = _a.x, y = _a.y;
var _b = _this.endPoint, x1 = _b.x, y1 = _b.y;
// 选区太小的情况就忽略
if (Math.abs(x1 - x) < 10 && Math.abs(y1 - y) < 10) {
return;
}
var lt = [Math.min(x, x1), Math.min(y, y1)];
var rt = [Math.max(x, x1), Math.max(y, y1)];
var elements = _this.lf.getAreaElement(lt, rt, _this.isWholeEdge, _this.isWholeNode);
elements.forEach(function (element) {
_this.lf.selectElementById(element.id, true);
});
_this.lf.emit('selection:selected', elements);
};
this.lf = lf;
// 初始化isDefalutStopMoveGraph取值
var stopMoveGraph = lf.getEditConfig().stopMoveGraph;
this.isDefalutStopMoveGraph = stopMoveGraph;
lf.openSelectionSelect = function () {
_this.openSelectionSelect();
};
lf.closeSelectionSelect = function () {
_this.closeSelectionSelect();
};
}
SelectionSelect.prototype.render = function (lf, domContainer) {
var _this = this;
this.__domContainer = domContainer;
lf.on('blank:mousedown', function (_a) {
var e = _a.e;
var config = lf.getEditConfig();
// 鼠标控制滚动移动画布的时候,不能选区。
if (!config.stopMoveGraph || _this.__disabled) {
return;
}
var _b = lf.getPointByClient(e.clientX, e.clientY).domOverlayPosition, x = _b.x, y = _b.y;
_this.startPoint = { x: x, y: y };
_this.endPoint = { x: x, y: y };
var wrapper = document.createElement('div');
wrapper.className = 'lf-selection-select';
wrapper.style.top = _this.startPoint.y + "px";
wrapper.style.left = _this.startPoint.x + "px";
domContainer.appendChild(wrapper);
_this.wrapper = wrapper;
document.addEventListener('mousemove', _this.__draw);
document.addEventListener('mouseup', _this.__drawOff);
});
};
/**
* 设置选中的灵敏度
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
* @param isWholeNode 是否要节点的全部点都在选区范围才算选中。默认true
*/
SelectionSelect.prototype.setSelectionSense = function (isWholeEdge, isWholeNode) {
if (isWholeEdge === void 0) { isWholeEdge = true; }
if (isWholeNode === void 0) { isWholeNode = true; }
this.isWholeEdge = isWholeEdge;
this.isWholeNode = isWholeNode;
};
/**
* 开启选区
*/
SelectionSelect.prototype.openSelectionSelect = function () {
var stopMoveGraph = this.lf.getEditConfig().stopMoveGraph;
if (!stopMoveGraph) {
this.isDefalutStopMoveGraph = false;
this.lf.updateEditConfig({
stopMoveGraph: true,
});
}
this.open();
};
/**
* 关闭选区
*/
SelectionSelect.prototype.closeSelectionSelect = function () {
if (!this.isDefalutStopMoveGraph) {
this.lf.updateEditConfig({
stopMoveGraph: false,
});
}
this.close();
};
SelectionSelect.prototype.open = function () {
this.__disabled = false;
};
SelectionSelect.prototype.close = function () {
this.__disabled = true;
};
SelectionSelect.pluginName = 'selectionSelect';
return SelectionSelect;
}());
export { SelectionSelect };
+18
View File
@@ -0,0 +1,18 @@
export * from './bpmn';
export * from './tools/snapshot';
export * from './bpmn-adapter';
export * from './turbo-adapter';
export * from './insert-node-in-polyline';
export * from './components/control';
export * from './components/menu';
export * from './components/context-menu';
export * from './components/dnd-panel';
export * from './components/selection-select';
export * from './components/mini-map';
export * from './materials/curved-edge';
export * from './materials/group';
export * from './NodeResize';
export * from './tools/flow-path';
export * from './tools/auto-layout';
export * from './bpmn-adapter/xml2json';
export * from './bpmn-adapter/json2xml';
@@ -0,0 +1,19 @@
export * from './bpmn';
// export * from './~mindmap';
export * from './tools/snapshot';
export * from './bpmn-adapter';
export * from './turbo-adapter';
export * from './insert-node-in-polyline';
export * from './components/control';
export * from './components/menu';
export * from './components/context-menu';
export * from './components/dnd-panel';
export * from './components/selection-select';
export * from './components/mini-map';
export * from './materials/curved-edge';
export * from './materials/group';
export * from './NodeResize';
export * from './tools/flow-path';
export * from './tools/auto-layout';
export * from './bpmn-adapter/xml2json';
export * from './bpmn-adapter/json2xml';
@@ -0,0 +1,21 @@
import { Point, PolylineEdgeModel, BaseNodeModel } from '@logicflow/core';
export declare const isInSegment: (point: any, start: any, end: any) => boolean;
export declare const corssPointInSegement: (node: BaseNodeModel, start: Point, end: Point) => {
startCrossPoint: {
x: number;
y: number;
};
endCrossPoint: {
x: number;
y: number;
};
};
interface SegementCross {
crossIndex: number;
crossPoints: {
startCrossPoint: Point;
endCrossPoint: Point;
};
}
export declare const isNodeInSegement: (node: BaseNodeModel, polyline: PolylineEdgeModel) => SegementCross;
export {};
@@ -0,0 +1,107 @@
// 这个里面的函数有些在core中已经存在,为了解耦关系,没有引用
var SegmentDirection;
(function (SegmentDirection) {
SegmentDirection["HORIZONTAL"] = "horizontal";
SegmentDirection["VERTICAL"] = "vertical";
})(SegmentDirection || (SegmentDirection = {}));
/* 判断一个点是否在线段中
入参点:point, 线段起终点,start,end,
返回值: 在线段中true,否则false
*/
export var isInSegment = function (point, start, end) {
var x = point.x, y = point.y;
return (x - start.x) * (x - end.x) <= 0
&& (y - start.y) * (y - end.y) <= 0;
};
/* 获取节点bbox */
var getNodeBBox = function (node) {
var x = node.x, y = node.y, width = node.width, height = node.height;
var bBox = {
minX: x - width / 2,
minY: y - height / 2,
maxX: x + width / 2,
maxY: y + height / 2,
x: x,
y: y,
width: width,
height: height,
centerX: x,
centerY: y,
};
return bBox;
};
/* 判断线段的方向 */
var segmentDirection = function (start, end) {
var direction;
if (start.x === end.x) {
direction = SegmentDirection.VERTICAL;
}
else if (start.y === end.y) {
direction = SegmentDirection.HORIZONTAL;
}
return direction;
};
// 节点是够在线段内,求出节点与线段的交点
export var corssPointInSegement = function (node, start, end) {
var bBox = getNodeBBox(node);
var direction = segmentDirection(start, end);
var maxX = Math.max(start.x, end.x);
var minX = Math.min(start.x, end.x);
var maxY = Math.max(start.y, end.y);
var minY = Math.min(start.y, end.y);
var x = node.x, y = node.y, width = node.width, height = node.height;
if (direction === SegmentDirection.HORIZONTAL) {
// 同一水平线
if (start.y === y && maxX >= bBox.maxX && minX <= bBox.minX) {
return {
startCrossPoint: {
x: start.x > end.x ? x + (width / 2) : x - (width / 2),
y: y,
},
endCrossPoint: {
x: start.x > end.x ? x - (width / 2) : x + (width / 2),
y: y,
},
};
}
}
else if (direction === SegmentDirection.VERTICAL) {
// 同一垂直线
if (start.x === node.x && maxY >= bBox.maxY && minY <= bBox.minY) {
return {
startCrossPoint: {
x: x,
y: start.y > end.y ? y + (height / 2) : y - (height / 2),
},
endCrossPoint: {
x: x,
y: start.y > end.y ? y - (height / 2) : y + (height / 2),
},
};
}
}
};
// 节点是否在线段内
// eslint-disable-next-line max-len
export var isNodeInSegement = function (node, polyline) {
var x = node.x, y = node.y;
var pointsList = polyline.pointsList;
for (var i = 0; i < pointsList.length - 1; i++) {
if (isInSegment({ x: x, y: y }, pointsList[i], pointsList[i + 1])) {
var bBoxCross = corssPointInSegement(node, pointsList[i], pointsList[i + 1]);
if (bBoxCross) {
return {
crossIndex: i + 1,
crossPoints: bBoxCross,
};
}
}
}
return {
crossIndex: -1,
crossPoints: {
startCrossPoint: { x: 0, y: 0 },
endCrossPoint: { x: 0, y: 0 },
},
};
};
@@ -0,0 +1,14 @@
import LogicFlow from '@logicflow/core';
declare class InsertNodeInPolyline {
static pluginName: string;
_lf: LogicFlow;
dndAdd: boolean;
dropAdd: boolean;
constructor({ lf }: {
lf: any;
});
eventHandler(): void;
insetNode(nodeData: any): void;
}
export { InsertNodeInPolyline };
export default InsertNodeInPolyline;
@@ -0,0 +1,86 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import { isNodeInSegement } from './edge';
var InsertNodeInPolyline = /** @class */ (function () {
function InsertNodeInPolyline(_a) {
var lf = _a.lf;
this._lf = lf;
this.dndAdd = true;
this.dropAdd = true;
this.eventHandler();
}
InsertNodeInPolyline.prototype.eventHandler = function () {
var _this = this;
// 监听事件
if (this.dndAdd) {
this._lf.on('node:dnd-add', function (_a) {
var data = _a.data;
_this.insetNode(data);
});
}
if (this.dropAdd) {
this._lf.on('node:drop', function (_a) {
var data = _a.data;
var edges = _this._lf.graphModel.edges;
var id = data.id;
var pureNode = true;
for (var i = 0; i < edges.length; i++) {
if (edges[i].sourceNodeId === id || edges[i].targetNodeId === id) {
pureNode = false;
break;
}
}
if (pureNode) {
_this.insetNode(data);
}
});
}
};
InsertNodeInPolyline.prototype.insetNode = function (nodeData) {
var edges = this._lf.graphModel.edges;
var nodeModel = this._lf.getNodeModelById(nodeData.id);
for (var i = 0; i < edges.length; i++) {
// eslint-disable-next-line max-len
var _a = isNodeInSegement(nodeModel, edges[i]), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
if (crossIndex >= 0) {
var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList;
this._lf.addEdge({
type: type,
sourceNodeId: sourceNodeId,
targetNodeId: nodeData.id,
pointsList: __spread(pointsList.slice(0, crossIndex), [crossPoints.startCrossPoint]),
});
this._lf.addEdge({
type: type,
sourceNodeId: nodeData.id,
targetNodeId: targetNodeId,
pointsList: __spread([crossPoints.endCrossPoint], pointsList.slice(crossIndex)),
});
this._lf.deleteEdge(id);
break;
}
}
};
InsertNodeInPolyline.pluginName = 'insertNodeInPolyline';
return InsertNodeInPolyline;
}());
export { InsertNodeInPolyline };
export default InsertNodeInPolyline;
@@ -0,0 +1,7 @@
import { Extension } from '@logicflow/core';
interface CurvedEdgePlugin extends Extension {
[x: string]: any;
}
declare const CurvedEdge: CurvedEdgePlugin;
export default CurvedEdge;
export { CurvedEdge, };
@@ -0,0 +1,107 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { PolylineEdge, PolylineEdgeModel, h } from '@logicflow/core';
var CurvedEdgeView = /** @class */ (function (_super) {
__extends(CurvedEdgeView, _super);
function CurvedEdgeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
CurvedEdgeView.prototype.getEdge = function () {
var _a = this.props.model.getEdgeStyle(), strokeWidth = _a.strokeWidth, stroke = _a.stroke, strokeDashArray = _a.strokeDashArray;
var points = this.props.model.points;
var points2 = points.split(' ').map(function (p) { return p.split(',').map(function (a) { return Number(a); }); });
var _b = __read(points2[0], 2), startX = _b[0], startY = _b[1];
var d = "M" + startX + " " + startY;
// 1) 如果一个点不为开始和结束,则在这个点的前后增加弧度开始和结束点。
// 2) 判断这个点与前一个点的坐标
// 如果x相同则前一个点的x也不变,
// y为(这个点的y 大于前一个点的y, 则 为 这个点的y - 5;小于前一个点的y, 则为这个点的y+5)
// 同理,判断这个点与后一个点的x,y是否相同,如果x相同,则y进行加减,如果y相同,则x进行加减
// todo: 好丑,看看怎么优化下
var space = 5;
for (var i = 1; i < points2.length - 1; i++) {
var _c = __read(points2[i - 1], 2), preX = _c[0], preY = _c[1];
var _d = __read(points2[i], 2), currentX = _d[0], currentY = _d[1];
var _e = __read(points2[i + 1], 2), nextX = _e[0], nextY = _e[1];
if (currentX === preX && currentY !== preY) {
var y = currentY > preY ? currentY - space : currentY + space;
d = d + " L " + currentX + " " + y;
}
if (currentY === preY && currentX !== preX) {
var x = currentX > preX ? currentX - space : currentX + space;
d = d + " L " + x + " " + currentY;
}
d = d + " Q " + currentX + " " + currentY;
if (currentX === nextX && currentY !== nextY) {
var y = currentY > nextY ? currentY - space : currentY + space;
d = d + " " + currentX + " " + y;
}
if (currentY === nextY && currentX !== nextX) {
var x = currentX > nextX ? currentX - space : currentX + space;
d = d + " " + x + " " + currentY;
}
}
var _f = __read(points2[points2.length - 1], 2), endX = _f[0], endY = _f[1];
d = d + " L " + endX + " " + endY;
return h('path', {
d: d,
strokeWidth: strokeWidth,
stroke: stroke,
fill: 'none',
strokeDashArray: strokeDashArray,
});
};
CurvedEdgeView.extendKey = 'curvedEdge';
return CurvedEdgeView;
}(PolylineEdge));
var CurvedEdgeModel = /** @class */ (function (_super) {
__extends(CurvedEdgeModel, _super);
function CurvedEdgeModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return CurvedEdgeModel;
}(PolylineEdgeModel));
var CurvedEdge = {
pluginName: 'curved-edge',
curvedSpace: 5,
init: function (_a) {
var curvedSpace = _a.curvedSpace;
CurvedEdge.curvedSpace = curvedSpace;
},
install: function (lf) {
lf.register({
type: 'curved-edge',
view: CurvedEdgeView,
model: CurvedEdgeModel,
});
},
};
export default CurvedEdge;
export { CurvedEdge, };
@@ -0,0 +1,113 @@
import { h } from '@logicflow/core';
import { RectResize } from '../../NodeResize';
declare class GroupNodeModel extends RectResize.model {
readonly isGroup = true;
/**
* 此分组的子节点Id
*/
children: Set<string>;
/**
* 其子节点是否被禁止通过拖拽移出分组。 默认false,允许拖拽移除分组。
*/
isRestrict: boolean;
/**
* 分组节点是否允许调整大小。
*/
resizable: boolean;
/**
* 分组节点是否允许折叠
*/
foldable: boolean;
/**
* 折叠后的宽度
*/
foldedWidth: number;
/**
* 折叠后的高度
*/
foldedHeight: number;
/**
* 分组折叠状态
*/
isFolded: boolean;
unfoldedWidth: number;
unfoldedHight: number;
initNodeData(data: any): void;
getResizeOutlineStyle(): {
fill: string;
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
/**
* 折叠分组
* 1. 折叠分组的宽高
* 2. 处理分组子节点
* 3. 处理连线
*/
foldGroup(isFolded: any): void;
getAnchorStyle(anchorInfo: any): Record<string, any>;
/**
* 折叠分组的时候,处理分组自身的连线和分组内部子节点上的连线
* 边的分类:
* - 虚拟边:分组被收起时,表示分组本身与外部节点关系的边。
* - 真实边:分组本身或者分组内部节点与外部节点节点(非收起分组)关系的边。
* 如果一个分组,本身与外部节点有M条连线,且内部N个子节点与外部节点有连线,那么这个分组收起时会生成M+N条连线。
* 折叠分组时:
* - 原有的虚拟边删除;
* - 创建一个虚拟边;
* - 真实边则隐藏;
* 展开分组是:
* - 原有的虚拟边删除;
* - 如果目外部点是收起的分组,则创建虚拟边;
* - 如果外部节点是普通节点,则显示真实边;
*/
private foldEdge;
createVirtualEdge(edgeData: any): void;
isInRange({ x1, y1, x2, y2 }: {
x1: any;
y1: any;
x2: any;
y2: any;
}): boolean;
isAllowMoveTo({ x1, y1, x2, y2 }: {
x1: any;
y1: any;
x2: any;
y2: any;
}): {
x: boolean;
y: boolean;
};
setAllowAppendChild(isAllow: any): void;
/**
* 添加分组子节点
* @param id 节点id
*/
addChild(id: any): void;
/**
* 删除分组子节点
* @param id 节点id
*/
removeChild(id: any): void;
getAddableOutlineStyle(): {
stroke: string;
strokeWidth: number;
strokeDasharray: string;
fill: string;
};
getData(): import("@logicflow/core").NodeData;
getHistoryData(): import("@logicflow/core").NodeData;
}
declare class GroupNode extends RectResize.view {
getControlGroup(): h.JSX.Element;
getAddedableShape(): import("preact").VNode<any>;
getFoldIcon(): import("preact").VNode<any>;
getResizeShape(): import("preact").VNode<any>;
}
declare const _default: {
type: string;
view: typeof GroupNode;
model: typeof GroupNodeModel;
};
export default _default;
@@ -0,0 +1,353 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import { h } from '@logicflow/core';
import { RectResize } from '../../NodeResize';
var defaultWidth = 500;
var defaultHeight = 300;
var GroupNodeModel = /** @class */ (function (_super) {
__extends(GroupNodeModel, _super);
function GroupNodeModel() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.isGroup = true;
_this.unfoldedWidth = defaultWidth;
_this.unfoldedHight = defaultHeight;
return _this;
}
GroupNodeModel.prototype.initNodeData = function (data) {
var _this = this;
_super.prototype.initNodeData.call(this, data);
var children = [];
if (Array.isArray(data.children)) {
children = data.children;
}
// 初始化组的子节点
this.children = new Set(children);
this.width = defaultWidth;
this.height = defaultHeight;
this.foldedWidth = 80;
this.foldedHeight = 60;
// todo: 参考bpmn.js, 分组和未加入分组的节点重合时,未加入分组的节点在分组之下。方便标识。
this.zIndex = -1;
this.radius = 0;
this.text.editable = false;
this.text.draggable = false;
this.isRestrict = false;
this.resizable = false;
this.autoToFront = false;
this.foldable = false;
if (this.properties.isFolded === undefined) {
this.properties.isFolded = false;
}
this.isFolded = this.properties.isFolded;
// fixme: 虽然默认保存的分组不会收起,但是如果重写保存数据分组了,
// 此处代码会导致多一个history记录
setTimeout(function () {
_this.isFolded && _this.foldGroup(_this.isFolded);
});
// this.foldGroup(this.isFolded);
};
GroupNodeModel.prototype.getResizeOutlineStyle = function () {
var style = _super.prototype.getResizeOutlineStyle.call(this);
style.stroke = 'none';
return style;
};
/**
* 折叠分组
* 1. 折叠分组的宽高
* 2. 处理分组子节点
* 3. 处理连线
*/
GroupNodeModel.prototype.foldGroup = function (isFolded) {
var _this = this;
this.setProperty('isFolded', isFolded);
this.isFolded = isFolded;
// step 1
if (isFolded) {
this.x = this.x - this.width / 2 + this.foldedWidth / 2;
this.y = this.y - this.height / 2 + this.foldedHeight / 2;
this.unfoldedWidth = this.width;
this.unfoldedHight = this.height;
this.width = this.foldedWidth;
this.height = this.foldedHeight;
}
else {
this.width = this.unfoldedWidth;
this.height = this.unfoldedHight;
this.x = this.x + this.width / 2 - this.foldedWidth / 2;
this.y = this.y + this.height / 2 - this.foldedHeight / 2;
}
// step 2
var allEdges = this.incoming.edges.concat(this.outgoing.edges);
this.children.forEach(function (elementId) {
var nodeModel = _this.graphModel.getElement(elementId);
nodeModel.visible = !isFolded;
allEdges = allEdges.concat(nodeModel.incoming.edges.concat(nodeModel.outgoing.edges));
});
// step 3
this.foldEdge(isFolded, allEdges);
};
GroupNodeModel.prototype.getAnchorStyle = function (anchorInfo) {
var style = _super.prototype.getAnchorStyle.call(this, anchorInfo);
style.stroke = 'transparent';
style.fill = 'transparent';
style.hover.fill = 'transparent';
style.hover.stroke = 'transparent';
return style;
};
/**
* 折叠分组的时候,处理分组自身的连线和分组内部子节点上的连线
* 边的分类:
* - 虚拟边:分组被收起时,表示分组本身与外部节点关系的边。
* - 真实边:分组本身或者分组内部节点与外部节点节点(非收起分组)关系的边。
* 如果一个分组,本身与外部节点有M条连线,且内部N个子节点与外部节点有连线,那么这个分组收起时会生成M+N条连线。
* 折叠分组时:
* - 原有的虚拟边删除;
* - 创建一个虚拟边;
* - 真实边则隐藏;
* 展开分组是:
* - 原有的虚拟边删除;
* - 如果目外部点是收起的分组,则创建虚拟边;
* - 如果外部节点是普通节点,则显示真实边;
*/
GroupNodeModel.prototype.foldEdge = function (isFolded, allEdges) {
var _this = this;
allEdges.forEach(function (edgeModel, index) {
var id = edgeModel.id, sourceNodeId = edgeModel.sourceNodeId, targetNodeId = edgeModel.targetNodeId, startPoint = edgeModel.startPoint, endPoint = edgeModel.endPoint, type = edgeModel.type, properties = edgeModel.properties, text = edgeModel.text;
var data = {
id: id + "__" + index,
sourceNodeId: sourceNodeId,
targetNodeId: targetNodeId,
startPoint: startPoint,
endPoint: endPoint,
type: type,
properties: properties,
text: text === null || text === void 0 ? void 0 : text.value,
};
if (edgeModel.virtual) {
_this.graphModel.deleteEdgeById(edgeModel.id);
}
var targetNodeIdGroup = _this.graphModel.group.getNodeGroup(targetNodeId);
// 考虑目标节点本来就是分组的情况
if (!targetNodeIdGroup) {
targetNodeIdGroup = _this.graphModel.getNodeModelById(targetNodeId);
}
var sourceNodeIdGroup = _this.graphModel.group.getNodeGroup(sourceNodeId);
if (!sourceNodeIdGroup) {
sourceNodeIdGroup = _this.graphModel.getNodeModelById(sourceNodeId);
}
// 折叠时,处理未被隐藏的边的逻辑
if (isFolded && edgeModel.visible !== false) {
// 需要确认此分组节点是新连线的起点还是终点
// 创建一个虚拟边,虚拟边相对真实边,起点或者终点从一起分组内部的节点成为了分组,
// 如果需要被隐藏的边的起点在需要折叠的分组中,那么设置虚拟边的开始节点为此分组
if (_this.children.has(sourceNodeId) || _this.id === sourceNodeId) {
data.startPoint = undefined;
data.sourceNodeId = _this.id;
}
else {
data.endPoint = undefined;
data.targetNodeId = _this.id;
}
// 如果边的起点和终点都在分组内部,则不创建新的虚拟边
if (targetNodeIdGroup.id !== _this.id || sourceNodeIdGroup.id !== _this.id) {
_this.createVirtualEdge(data);
}
edgeModel.visible = false;
}
// 展开时,处理被隐藏的边的逻辑
if (!isFolded && edgeModel.visible === false) {
// 展开分组时:判断真实边的起点和终点是否有任一节点在已折叠分组中,如果不是,则显示真实边。如果是,这修改这个边的对应目标节点id来创建虚拟边。
if (targetNodeIdGroup && targetNodeIdGroup.isGroup && targetNodeIdGroup.isFolded) {
data.targetNodeId = targetNodeIdGroup.id;
data.endPoint = undefined;
_this.createVirtualEdge(data);
}
else if (sourceNodeIdGroup && sourceNodeIdGroup.isGroup && sourceNodeIdGroup.isFolded) {
data.sourceNodeId = sourceNodeIdGroup.id;
data.startPoint = undefined;
_this.createVirtualEdge(data);
}
else {
edgeModel.visible = true;
}
}
});
};
GroupNodeModel.prototype.createVirtualEdge = function (edgeData) {
edgeData.pointsList = undefined;
var model = this.graphModel.addEdge(edgeData);
model.virtual = true;
// 强制不保存group连线数据
model.getData = function () { return null; };
model.text.editable = false;
model.isFoldedEdge = true;
};
GroupNodeModel.prototype.isInRange = function (_a) {
var x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
return x1 >= (this.x - this.width / 2)
&& x2 <= (this.x + this.width / 2)
&& y1 >= (this.y - this.height / 2)
&& y2 <= (this.y + this.height / 2);
};
GroupNodeModel.prototype.isAllowMoveTo = function (_a) {
var x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
return {
x: x1 >= (this.x - this.width / 2) && x2 <= (this.x + this.width / 2),
y: y1 >= (this.y - this.height / 2) && y2 <= (this.y + this.height / 2),
};
};
GroupNodeModel.prototype.setAllowAppendChild = function (isAllow) {
this.setProperty('groupAddable', isAllow);
};
/**
* 添加分组子节点
* @param id 节点id
*/
GroupNodeModel.prototype.addChild = function (id) {
this.children.add(id);
};
/**
* 删除分组子节点
* @param id 节点id
*/
GroupNodeModel.prototype.removeChild = function (id) {
this.children.delete(id);
};
GroupNodeModel.prototype.getAddableOutlineStyle = function () {
return {
stroke: '#FEB663',
strokeWidth: 2,
strokeDasharray: '4 4',
fill: 'transparent',
};
};
GroupNodeModel.prototype.getData = function () {
var data = _super.prototype.getData.call(this);
data.children = __spread(this.children);
var properties = data.properties;
delete properties.groupAddable;
delete properties.isFolded;
return data;
};
GroupNodeModel.prototype.getHistoryData = function () {
var data = _super.prototype.getData.call(this);
data.children = __spread(this.children);
var properties = data.properties;
delete properties.groupAddable;
if (properties.isFolded) { // 如果分组被折叠
data.x = data.x + this.unfoldedWidth / 2 - this.foldedWidth / 2;
data.y = data.y + this.unfoldedHight / 2 - this.foldedHeight / 2;
}
return data;
};
return GroupNodeModel;
}(RectResize.model));
var GroupNode = /** @class */ (function (_super) {
__extends(GroupNode, _super);
function GroupNode() {
return _super !== null && _super.apply(this, arguments) || this;
}
GroupNode.prototype.getControlGroup = function () {
var _a = this.props.model, resizable = _a.resizable, properties = _a.properties;
return resizable && !properties.isFolded ? _super.prototype.getControlGroup.call(this) : null;
};
GroupNode.prototype.getAddedableShape = function () {
var _a = this.props.model, width = _a.width, height = _a.height, x = _a.x, y = _a.y, radius = _a.radius, properties = _a.properties;
if (!properties.groupAddable)
return null;
var strokeWidth = this.props.model.getNodeStyle().strokeWidth;
var style = this.props.model.getAddableOutlineStyle();
var newWidth = width + strokeWidth + 8;
var newHeight = height + strokeWidth + 8;
return h('rect', __assign(__assign({}, style), { width: newWidth, height: newHeight, x: x - newWidth / 2, y: y - newHeight / 2, rx: radius, ry: radius }));
};
GroupNode.prototype.getFoldIcon = function () {
var model = this.props.model;
var foldX = model.x - model.width / 2 + 5;
var foldY = model.y - model.height / 2 + 5;
if (!model.foldable)
return null;
var iconIcon = h('path', {
fill: 'none',
stroke: '#818281',
strokeWidth: 2,
'pointer-events': 'none',
d: model.properties.isFolded
? "M " + (foldX + 3) + "," + (foldY + 6) + " " + (foldX + 11) + "," + (foldY + 6) + " M" + (foldX + 7) + "," + (foldY + 2) + " " + (foldX + 7) + "," + (foldY + 10)
: "M " + (foldX + 3) + "," + (foldY + 6) + " " + (foldX + 11) + "," + (foldY + 6) + " ",
});
return h('g', {}, [
h('rect', {
height: 12,
width: 14,
rx: 2,
ry: 2,
strokeWidth: 1,
fill: '#F4F5F6',
stroke: '#CECECE',
cursor: 'pointer',
x: model.x - model.width / 2 + 5,
y: model.y - model.height / 2 + 5,
onClick: function () {
model.foldGroup(!model.properties.isFolded);
},
}),
iconIcon,
]);
};
GroupNode.prototype.getResizeShape = function () {
return h('g', {}, [
this.getAddedableShape(),
_super.prototype.getResizeShape.call(this),
this.getFoldIcon(),
]);
};
return GroupNode;
}(RectResize.view));
export default {
type: 'group',
view: GroupNode,
model: GroupNodeModel,
};
@@ -0,0 +1,38 @@
import LogicFlow, { BaseNodeModel } from '@logicflow/core';
import GroupNode from './GroupNode';
declare type BaseNodeId = string;
declare type GroupId = string;
declare type Bounds = {
x1: number;
y1: number;
x2: number;
y2: number;
};
declare class Group {
static pluginName: string;
lf: LogicFlow;
activeGroup: any;
nodeGroupMap: Map<BaseNodeId, GroupId>;
constructor({ lf }: {
lf: any;
});
graphRendered: (data: any) => void;
appendNodeToGrop: ({ data }: {
data: any;
}) => void;
deleteGroupChild: ({ data }: {
data: any;
}) => void;
setActiveGroup: ({ data }: {
data: any;
}) => void;
/**
* 获取自定位置其所属分组
*/
getGroup(bounds: Bounds): BaseNodeModel | undefined;
/**
* 获取某个节点所属的groupModel
*/
getNodeGroup(nodeId: any): BaseNodeModel;
}
export { Group, GroupNode, };
@@ -0,0 +1,144 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import GroupNode from './GroupNode';
var Group = /** @class */ (function () {
function Group(_a) {
var _this = this;
var lf = _a.lf;
this.nodeGroupMap = new Map();
this.graphRendered = function (data) {
// 如果节点
if (data && data.nodes) {
data.nodes.forEach(function (node) {
if (node.children) {
node.children.forEach(function (nodeId) {
_this.nodeGroupMap.set(nodeId, node.id);
});
}
});
}
};
this.appendNodeToGrop = function (_a) {
var data = _a.data;
// 如果这个节点之前已经在group中了,则将其从之前的group中移除
var preGroupId = _this.nodeGroupMap.get(data.id);
if (preGroupId) {
var preGroup = _this.lf.getNodeModelById(preGroupId);
preGroup.removeChild(data.id);
_this.nodeGroupMap.delete(data.id);
preGroup.setAllowAppendChild(false);
}
// 然后再判断这个节点是否在某个group中,如果在,则将其添加到对应的group中
var bounds = _this.lf.getNodeModelById(data.id).getBounds();
var group = _this.getGroup(bounds);
if (!group)
return;
if (data.id !== group.id) {
group.addChild(data.id);
_this.nodeGroupMap.set(data.id, group.id);
group.setAllowAppendChild(false);
}
else if (data.children && data.children.length > 0) {
// 表示当前添加的节点是一个新增的group
data.children.forEach(function (nodeId) {
_this.nodeGroupMap.set(nodeId, data.id);
});
}
};
this.deleteGroupChild = function (_a) {
var data = _a.data;
var groupId = _this.nodeGroupMap.get(data.id);
if (groupId) {
var group = _this.lf.getNodeModelById(groupId);
group.removeChild(data.id);
_this.nodeGroupMap.delete(data.id);
}
};
this.setActiveGroup = function (_a) {
var data = _a.data;
var nodeModel = _this.lf.getNodeModelById(data.id);
if (nodeModel.isGroup)
return;
var bounds = nodeModel.getBounds();
var newGroup = _this.getGroup(bounds);
if (newGroup || newGroup !== _this.activeGroup) {
if (_this.activeGroup) {
_this.activeGroup.setAllowAppendChild(false);
}
if (newGroup) {
_this.activeGroup = newGroup;
_this.activeGroup.setAllowAppendChild(true);
}
}
};
lf.register(GroupNode);
this.lf = lf;
lf.graphModel.addNodeMoveRules(function (model, deltaX, deltaY) {
if (model.isGroup) { // 如果移动的是分组,那么分组的子节点也跟着移动。
lf.graphModel.moveNodes(__spread(model.children), deltaX, deltaY, true);
return true;
}
var groupModel = lf.getNodeModelById(_this.nodeGroupMap.get(model.id));
if (groupModel && groupModel.isRestrict) { // 如果移动的节点存在分组中,且这个分组禁止子节点移出去。
var _a = model.getBounds(), x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
var r = groupModel.isAllowMoveTo({
x1: x1 + deltaX,
y1: y1 + deltaY,
x2: x2 + deltaX,
y2: y2 + deltaY,
});
return r;
}
return true;
});
lf.graphModel.group = this;
lf.on('node:add', this.appendNodeToGrop);
lf.on('node:delete', this.deleteGroupChild);
lf.on('node:drop', this.appendNodeToGrop);
lf.on('node:dnd-drag', this.setActiveGroup);
lf.on('node:drag', this.setActiveGroup);
lf.on('graph:rendered', this.graphRendered);
}
/**
* 获取自定位置其所属分组
*/
Group.prototype.getGroup = function (bounds) {
var nodes = this.lf.graphModel.nodes;
for (var i = 0; i < nodes.length; i++) {
var model = nodes[i];
if (model.isGroup && model.isInRange(bounds)) {
return model;
}
}
};
/**
* 获取某个节点所属的groupModel
*/
Group.prototype.getNodeGroup = function (nodeId) {
var groupId = this.nodeGroupMap.get(nodeId);
if (groupId) {
return this.lf.getNodeModelById(groupId);
}
};
Group.pluginName = 'group';
return Group;
}());
export { Group, GroupNode, };
@@ -0,0 +1,208 @@
.lf-control {
display: flex;
padding: 0 15px;
background: rgba(255, 255, 255, 0.8);
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
border-radius: 5px;
margin: 5px;
position: absolute;
right: 10px;
top: 0;
}
.lf-control-item {
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
justify-content: center;
padding: 5px 10px;
}
.lf-control-item:hover {
background: #efefef;
}
.lf-control-item.disabled {
filter: opacity(0.5);
/* cursor: not-allowed; */
pointer-events: none;
}
.lf-control-item.disabled:hover {
background: #fff;
}
.lf-control-item.disabled i {
pointer-events: none;
}
.lf-control-item i {
display: inline-block;
width: 20px;
height: 20px;
vertical-align: middle;
background-size: cover;
}
.lf-control-text {
margin-top: 5px;
font-size: 12px;
}
.lf-control-zoomOut {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAFMElEQVR4Xu3dsQ3CQBBFQei/KEoDXQG2xAv9h3yDnb0nh7xffgQIXAq82RAgcC0gEK+DwI2AQDwPAgLxBgg0AV+Q5mZqREAgI4e2ZhMQSHMzNSIgkJFDW7MJCKS5mRoREMjIoa3ZBATS3EyNCAhk5NDWbAICaW6mRgQEMnJoazYBgTQ3UyMCAhk5tDWbgECam6kRAYGMHNqaTUAgzc3UiIBARg5tzSYgkOZmakRAICOHtmY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rfo9uiUbLGBEkLrVIO6XT3BSvUmiBpcZ5oU5DpC2NUL2n9jQkSg+7K2iYmSAzOZwD7xqhe0voDEyQOXV3KUpJtFYQxQWJw/hTwpBjVS1ovNkEC0S1UKzL4+A4LVcY/YXcjRB8UfskEace5N51V4qud4Qc7igreKBlHlJxtgkRBa73RCNwN+FHwIKebIMEIW30YAroBupT9MFCOMkEC0bXqUASUe1lZMyPlqSZIJLzWHYnA14EHRw4AbGuCBCNs9SEI6Cr0n4OTx/0b2NgECfGflQYjoDrqq4PHUJXde5sgwShbfQgCZwbnMZPRZwFO2hDiPiuNRECfV78Lvmor+1+huDrPIJGutO4IBA4uQngidC/Xqbs+l5og0TBbf2oELgZU7yVS/gJsoQFMkEiYrTs1Ag8Avpla6RR9qyZXeU2QFtD2EMkQUKI4JYyLlgOA93sGiYbZ+lMioNLe30ipcI4uFelRqiZ/YrUEuIdpjoDql6s6WLT8ANhuMog/saLhtv4UCDwT+EgKRSV0KBHEcSZICaTcJAsEdO7xkxZqgehh/wfcsaiku/TwnkGyeAdsxBwElGFfBTXbkC+srH1ogrQBu8eoi4Dum+veeVui/AFKBHG9mCBtQe9xqiKgbJU6FNR15TbkGuCWgDLGmyBtIO4xaiOwWUGObWprqN7xVOCgld08g1QH0j3iETgX2C1+mHVGEBnXu+NugrTsBQ83F4EbFGHmz2gZp9OB/aeNaYK07AkPNxMBvYvasYrMlDht8P8CWwFKML6emCB+Y3NBQGsAxUC1LLine truncated
}
.lf-control-redo {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAASJElEQVR4Xu2dCdB2YxnHf0hZvkTC2CpZxpKZZB0iDcZUQ5LJEkNkouxEWUJSyJatIssIqca0aLSQyiStTCotQzXaJs1EQiqq+X/ffXzv937v85ztXs+5rpl3vm/mPee6r/t/n9/7POec676uJTAzBUyBiQosYdqYAqbAZAUMELs6TIEpChggdnmYAgaIXQOmQDcF7BOkm2521kgUMEBGstA2zW4K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0E312YEX09eolYyl6HFhLcx9JgQoQ9QVRfd7QdiBwfehBzL8p4EuBCpAlAfUnDJn2rphVYkY1ssxMgSIUqABRsDHuQzTOJsADRahjQY5egZmAqLKeWhSENr2UfGvoQcy/KeBDgZmA6C+7amSFNm3s0ctJ+xQJrbT5763ATEDkLHQJoCrgzwN79o7eHJgCgRWYDcg5EfePW7fbwItr7vsrMBuQjQH1vY5hKi6g8Wz/dAy1bYxOCswGRE5Ut3WrTt7an3SR633X/kw7wxSIoMBcgMRoqDNzatsC90SYqw1hCrRWYC5AVgLUvHHp1t66nfAIsFmEPondorOzRq3AXIBIkJuBvSMqox4lsb7WRZyWDVW6ApMAURkgVSOJadcAhLine truncated
}
/*menu*/
.lf-menu {
position: absolute;
display: none;
background: #fff;
padding: 10px 0;
margin: 0 0 0 10px;
border-radius: 3px;
border: 1px solid #efefee;
width: 200px;
z-index: 999;
}
.lf-menu > li {
cursor: pointer;
list-style: none;
padding: 3px 12px;
font-size: 12px;
line-height: 18px;
cursor: pointer;
transition: all 120ms ease-in-out;
position: relative;
}
.lf-menu-item__disabled {
cursor: default;
pointer-events: none;
color: #aaa;
opacity: 0.88;
}
.lf-menu-item:hover {
background: #f3f3f3;
}
/* dndpanel */
.lf-dndpanel {
position: absolute;
margin: 5px;
padding: 15px 5px;
background: rgba(255, 255, 255, 0.8);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
border-radius: 5px;
}
.lf-dnd-item {
margin-top: 5px;
text-align: center;
font-size: 14px;
}
.lf-dnd-shape {
width: 36px;
height: 36px;
background-repeat: no-repeat;
background-position: center center;
cursor: grab;
margin: 0 auto;
opacity: 0.99;
}
/* 选区 */
.lf-selection-select {
border: 2px dashed darkorange;
position: absolute;
}
/* 缩略图 */
.lf-mini-map {
border: 1px solid #93a3b4;
background: rgba(255, 255, 255, 1);
position: absolute;
overflow: hidden;
padding-top: 20px;
}
.lf-mini-map-graph {
position: relative;
overflow: hidden;
}
.lf-minimap-viewport {
position: absolute;
top: 0;
left: 0;
border: 2px solid rgb(24, 125, 255);
cursor: grab;
}
.lf-mini-map-header {
height: 18px;
line-height: 18px;
border-top: #bfbfbf solid 1px;
border-bottom: #666666 solid 1px;
text-shadow: 0 1px 0 rgb(255 255 255 / 33%);
background-color: #a6a6a6;
background-image: linear-gradient(to bottom,#b2b2b2,#9b9b9b);
padding: 0px 10px;
position: absolute;
top: 0;
left: 0;
right: 0;
border: 1px solid #999;
}
.lf-mini-map-close {
position: absolute;
right: 2px;
top: 0px;
width: 18px;
height: 18px;
cursor: pointer;
background-size: contain;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAACL0lEQVRoQ+1YT2vUQBT/vS+Smc3u0ZtfwA+hUKEttIIVbMEWrGAL3UItqKCCCipooS3Ynu29ePfqLcnO5Nov0NsrWbc0myxtJpNmGZw9LZk37/3+vCTzQnD8R47jhycwbQe9A94BSwV8C1kKaL3dO2AtoWWC/8+BMJB9ItwHcM6MX0mqtm1EzOU7Y8bvJFV9k3zGDnSFPAVw76oIb8ZavzIpehnbE+Ilg/J7/8Za3THJVYfAHwB3x4owXsSpemNSuCs6zwEu7rl9AmEgt4hQspkIa5FS76uQCKV8RoxSLDP6pi1p7EAGsCvEBkA7ZbC0EuvBp+tI9IR4yqBSDIE3Iq13qwiQj6lFYEgikOsgvC4VJDyJlfo6CUg3kI9BmLBG67EevDUFn8XXJpBt7km5yox3xcIMfpRo/SN/PZRygRhj17J1JqwmSn2oA96awL926iwD/LEIgJjmo3RwMCQadGaZePh/3H5ejrT+XBd8IwSGJKRcAuPLhHZ6mIkMxlFpjbEUp+qbDfjGCGSJQiEWCfS9CiAmLCZK7VWJvSnG6h4oJu8FnTkm3r+uKDHNReng8CZgVdcbJTBqpxkwfk4EQJiJlTquCq5KnCeQV8npFnL6Jnb6Mer0i8zpo4TThzmnj9OjGXardDBrZqDZbmMmdnukdH6oL3xWOTG1vNh6oxn7AYB2PqtUOWC1GdP4Ya5N8I0ONG0Dv6znHZiW8t6BaSvvHfAONKSAf4w2JGTtNBey0xBAkjSEzwAAAABJRU5ErkJggg==');
}
/* 节点调整 */
.lf-resize-control-0{
cursor: nw-resize;
}
.lf-resize-control-1{
cursor: ne-resize;
}
.lf-resize-control-2{
cursor: se-resize;
}
.lf-resize-control-3{
cursor: sw-resize;
}
/* context-menu */
.lf-inner-context {
display: none;
position: absolute;
/* display: flex; */
flex-direction: column;
flex-wrap: wrap;
height: 90px;
}
.lf-context-item {
padding: 2px 3px;
width: 20px;
height: 20px;
margin: 0 2px 2px 0;
box-sizing: content-box;
}
.lf-context-item:hover {
background: rgba(201, 217, 216, 0.5);
}
.lf-context-img {
width: 20px;
height: 20px;
cursor: pointer;
}
/* mind map */
.lf-mindmap_addIcon {
margin-top: 10px;
}
@@ -0,0 +1,40 @@
/**
* 自动布局插件
* 依赖flowpath插件
* 未完善
*/
import LogicFlow from '@logicflow/core';
declare class AutoLayout {
lf: LogicFlow;
levelHeight: any[];
newNodeMap: Map<string, any>;
trunk: any[];
static pluginName: string;
constructor({ lf }: {
lf: any;
});
layout(data: any, path: any): void;
private setNodePosition;
/**
* 1. 处理边上的文本
* 2. 主干节点之间直接的边
* 3. 一个节点被多个连接作为目标节点,合理分配锚点位置。
*/
private getEdgeDataPoints;
/**
* 获取边的连接节点相对位置。
* source一定在target左边。
* 1. 如果source和target在同一x, y坐标内容。
* 2. 如果source在target左上方。
* 3. 如果souce在target左下方。
*/
private getRelativePosition;
/**
* 获取边节点图形的宽高。
*/
private getShape;
private formatData;
addLevelHeight(level: any, height?: number, isNegative?: boolean): void;
getLevelHeight(level: any, isNegative?: boolean): any;
}
export { AutoLayout };
@@ -0,0 +1,266 @@
/**
* 自动布局插件
* 依赖flowpath插件
* 未完善
*/
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var POSITION_TYPE = {
LEFT_TOP: -1,
LEFT: 0,
LEFT_BOTTOM: 1,
};
var AutoLayout = /** @class */ (function () {
function AutoLayout(_a) {
var _this = this;
var lf = _a.lf;
this.lf = lf;
/**
* 用于记录上一次调用layout时计算出的trunk
* 当旧trunk和新trunk长度一致时,用于选择旧trunk,
* a->b->c->d
* |->e
* e后面新增f节点时候,旧逻辑会返回新trunk[a,b,e,f]
* 界面布局变成
* a->b->e->f
* |->c->d
* 其实只想要这样 尽量少变化
* a->b->c->d
* |->e->f
* */
this.trunk = [];
// 给lf添加方法
lf.layout = function (startNodeType) {
var data = _this.lf.getGraphRawData();
_this.lf.setStartNodeType(startNodeType);
var path = _this.lf.getPathes();
_this.levelHeight = [];
_this.newNodeMap = new Map();
return _this.layout(data, path);
};
}
// 1) 将所有节点和边的坐标删除。节点上的文本改成偏移量。
// 2) 找到长度最长的路径,作为基准路径。
// 3) 依次计算
// 拿到最长的路径。
// nodes: [], edges: [],
AutoLayout.prototype.layout = function (data, path) {
var _this = this;
var trunk = [];
path.forEach(function (p) {
var elements = p.elements;
if (elements.length > trunk.length) {
trunk = elements;
}
else if (elements.length === trunk.length) {
// 考虑是否替换为旧的trunk
if (JSON.stringify(elements) === JSON.stringify(_this.trunk)) {
trunk = _this.trunk;
}
}
});
// 记录上一次trunk
this.trunk = trunk;
var nodeMap = this.formatData(data);
var newGraphData = {
nodes: [],
edges: [],
};
// 从后向前布局
for (var i = trunk.length - 1; i >= 0; i--) {
this.setNodePosition(trunk[i], nodeMap, newGraphData, i, 1);
}
this.lf.graphModel.graphDataToModel(newGraphData);
};
// 1) 需要知道下一层级已占高度。
// 2) 基于自己的高度,判断下一个层级的高度
AutoLayout.prototype.setNodePosition = function (nodeId, nodeMap, newGraphData, xLevel, yLevel) {
var _this = this;
var n = nodeMap[nodeId];
var text = n.text, type = n.type, next = n.next, properties = n.properties;
var x = xLevel * 160 + 40;
var y = yLevel * 120;
var nodeData = {
id: nodeId,
x: x,
text: text,
y: y,
type: type,
properties: properties,
};
if (text && typeof text === 'object') {
nodeData.text = __assign(__assign({}, text), { x: x + text.x, y: y + text.y });
}
this.newNodeMap.set(nodeData.id, {
x: nodeData.x,
y: nodeData.y,
type: type,
});
newGraphData.nodes.push(nodeData);
n.isFixed = true;
this.addLevelHeight(xLevel, 1);
if (next && next.length > 0) {
next.forEach(function (nextInfo) {
// 如果下一个节点还没有被定位,那么设置其定位
var n1 = nodeMap[nextInfo.nodeId];
if (!n1.isFixed) {
var nextYLevel = _this.getLevelHeight(xLevel + 1);
_this.addLevelHeight(xLevel, 1);
_this.setNodePosition(nextInfo.nodeId, nodeMap, newGraphData, xLevel + 1, nextYLevel + 1);
}
else {
// todo: 如果下一个节点是已经定位的,则需要考虑边的规避
}
// 设置连接到下一个节点的边
// 1) 起始位置为source节点的下方,结束位置为target节点左边。
// 2) 计算折线
newGraphData.edges.push(__assign({ id: nextInfo.edgeId, type: nextInfo.edgeType, sourceNodeId: nodeId, targetNodeId: nextInfo.nodeId, properties: nextInfo.properties, text: nextInfo.text }, _this.getEdgeDataPoints(nodeId, nextInfo.nodeId)));
});
}
return nodeData;
};
/**
* 1. 处理边上的文本
* 2. 主干节点之间直接的边
* 3. 一个节点被多个连接作为目标节点,合理分配锚点位置。
*/
AutoLayout.prototype.getEdgeDataPoints = function (sourceNodeId, targetNodeId) {
var source = this.newNodeMap.get(sourceNodeId);
var target = this.newNodeMap.get(targetNodeId);
var _a = this.getShape(sourceNodeId), width = _a.width, height = _a.height;
var _b = this.getShape(targetNodeId), targetWidth = _b.width, targetHeight = _b.height;
var postionType = this.getRelativePosition(source, target);
var startPoint = {
x: source.x,
y: source.y,
};
var endPoint = {
x: target.x,
y: target.y,
};
switch (postionType) {
case POSITION_TYPE.LEFT:
startPoint.x = source.x + width / 2;
endPoint.x = target.x - targetWidth / 2;
break;
case POSITION_TYPE.LEFT_TOP:
startPoint.y = source.y + height / 2;
endPoint.x = target.x - targetWidth / 2;
break;
case POSITION_TYPE.LEFT_BOTTOM:
startPoint.x = source.x + width / 2;
endPoint.y = target.y + targetHeight / 2;
break;
default:
break;
}
return {
startPoint: startPoint,
endPoint: endPoint,
};
};
/**
* 获取边的连接节点相对位置。
* source一定在target左边。
* 1. 如果source和target在同一x, y坐标内容。
* 2. 如果source在target左上方。
* 3. 如果souce在target左下方。
*/
AutoLayout.prototype.getRelativePosition = function (source, target) {
var y = source.y;
var y1 = target.y;
var postionType;
if (y < y1) {
postionType = -1;
}
else if (y === y1) {
postionType = 0;
}
else {
postionType = 1;
}
return postionType;
};
/**
* 获取边节点图形的宽高。
*/
AutoLayout.prototype.getShape = function (nodeId) {
var nodeModel = this.lf.getNodeModelById(nodeId);
return {
height: nodeModel.height,
width: nodeModel.width,
};
};
AutoLayout.prototype.formatData = function (data) {
var nodeMap = data.nodes.reduce(function (nMap, node) {
var type = node.type, properties = node.properties, text = node.text, x = node.x, y = node.y;
if (text && typeof text === 'object') {
// 坐标转换为偏移量
text.x = text.x - x;
text.y = text.y - y;
}
nMap[node.id] = {
type: type,
properties: properties,
text: text,
prev: [],
next: [],
};
return nMap;
}, {});
data.edges.forEach(function (edge) {
var sourceNodeId = edge.sourceNodeId, targetNodeId = edge.targetNodeId, id = edge.id, properties = edge.properties, text = edge.text;
var newText = text;
if (typeof text === 'object') {
newText = text.value;
}
nodeMap[sourceNodeId].next.push({
edgeId: id,
nodeId: targetNodeId,
edgeType: edge.type,
properties: properties,
text: newText,
});
nodeMap[targetNodeId].prev.push({
edgeId: id,
nodeId: sourceNodeId,
properties: properties,
text: newText,
});
});
return nodeMap;
};
AutoLayout.prototype.addLevelHeight = function (level, height, isNegative) {
if (height === void 0) { height = 1; }
if (isNegative === void 0) { isNegative = false; }
var l = this.levelHeight[level];
if (!l) {
l = {
positiveHeight: 0,
negativeHeight: 0,
};
this.levelHeight[level] = l;
}
isNegative ? (l.negativeHeight -= height) : (l.positiveHeight += height);
};
AutoLayout.prototype.getLevelHeight = function (level, isNegative) {
if (isNegative === void 0) { isNegative = false; }
var val = this.levelHeight[level];
if (!val) {
return 0;
}
return isNegative ? val.negativeHeight : val.positiveHeight;
};
AutoLayout.pluginName = 'AutoLayout';
return AutoLayout;
}());
export { AutoLayout };
@@ -0,0 +1,47 @@
/**
* 路径插件,此插件支持获取绘制的图中所有的路径。
* 需要指定开始节点类型。
*/
import LogicFlow from '@logicflow/core';
declare type Path = {
routeId: string;
name: string;
elements: string[];
type: number;
};
declare type RawPath = Path & {
similarElement: RawPath;
weight: number;
};
declare class FlowPath {
lf: LogicFlow;
pathes: RawPath[];
startNodeType: string;
static pluginName: string;
constructor({ lf }: {
lf: any;
});
setPathes(pathes: any): void;
getPathes(): any[];
private findPathElements;
/**
* 设置路径id
* 如果存在原始路径Id, 则需要比较新路径是否在原始路径中存在相似路径
* 如果有,则尽量使用原始路径。
* 相似路径
* 1. 如果所有的节点都相同,则必定为同一路径。(包括顺序不同)
* 2. 如果新路径比原来路径少了或者多了部分节点,则记录为相似路径。基于不同的差异,标记不同的权重。
* 3. 基于新路径在旧路径占用权限,设置新路径Id.
* 4. 如果某一条旧路径被多条新路径标记为相同的权重,则这两条新路径都使用新Id.
*/
private getNewPathes;
private similar2Path;
private getNewId;
/**
* 判断是否为循环路径
* 由于前面进行了特殊处理,将循环部分单独提出来作为路径
* 所有循环路径必定开始节点等于结束节点。
*/
private isLoopPath;
}
export { FlowPath, };
@@ -0,0 +1,212 @@
/**
* 路径插件,此插件支持获取绘制的图中所有的路径。
* 需要指定开始节点类型。
*/
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import { getBpmnId } from '../../bpmn/getBpmnId';
var FlowPath = /** @class */ (function () {
function FlowPath(_a) {
var _this = this;
var lf = _a.lf;
this.lf = lf;
this.pathes = [];
// 给lf添加方法
lf.getPathes = function () {
if (!_this.startNodeType) {
throw new Error('需要预先指定开始节点类型');
}
return _this.getPathes();
};
lf.setRawPathes = function (pathes) {
_this.setPathes(pathes);
};
lf.getRawPathes = function () { return _this.pathes; };
lf.setStartNodeType = function (type) {
_this.startNodeType = type;
};
}
FlowPath.prototype.setPathes = function (pathes) {
this.pathes = pathes.map(function (_a) {
var routeId = _a.routeId, name = _a.name, elements = _a.elements, type = _a.type;
return ({
routeId: routeId,
name: name,
elements: elements,
type: type,
similarElement: null,
weight: 0,
});
});
};
FlowPath.prototype.getPathes = function () {
var _this = this;
var graphData = this.lf.getGraphRawData();
var nodesMap = new Map();
var startNodeIds = [];
graphData.nodes.forEach(function (node) {
nodesMap.set(node.id, {
id: node.id,
data: node,
nextNodes: [],
});
if (node.type === _this.startNodeType) {
startNodeIds.push(node.id);
}
});
graphData.edges.forEach(function (edge) {
var node = nodesMap.get(edge.sourceNodeId);
node.nextNodes.push(edge.targetNodeId);
});
var pathElements = [];
startNodeIds.forEach(function (id) {
pathElements = pathElements.concat(_this.findPathElements(nodesMap.get(id), nodesMap, []));
});
return this.getNewPathes(pathElements);
};
FlowPath.prototype.findPathElements = function (node, nodesMap, elements) {
if (elements === void 0) { elements = []; }
var newPathes = __spread(elements);
newPathes.push(node.id);
if (node.nextNodes.length === 0) {
return [newPathes];
}
var subPath = [];
for (var i = 0; i < node.nextNodes.length; i++) {
var n = nodesMap.get(node.nextNodes[i]);
var p = void 0;
// 循环路径
var idx = newPathes.indexOf(n.id);
if (idx !== -1) {
p = [__spread(newPathes.slice(idx), [n.id])];
}
else {
p = this.findPathElements(n, nodesMap, __spread(newPathes));
}
subPath = subPath.concat(p);
}
return subPath;
};
/**
* 设置路径id
* 如果存在原始路径Id, 则需要比较新路径是否在原始路径中存在相似路径
* 如果有,则尽量使用原始路径。
* 相似路径
* 1. 如果所有的节点都相同,则必定为同一路径。(包括顺序不同)
* 2. 如果新路径比原来路径少了或者多了部分节点,则记录为相似路径。基于不同的差异,标记不同的权重。
* 3. 基于新路径在旧路径占用权限,设置新路径Id.
* 4. 如果某一条旧路径被多条新路径标记为相同的权重,则这两条新路径都使用新Id.
*/
FlowPath.prototype.getNewPathes = function (pathElements) {
var _this = this;
var pathes = [];
// 由于循环路径不包括开始,所以存在重复的情况,此处去重。
var LoopSet = new Set();
pathElements.forEach(function (elements) {
var routeId = _this.getNewId('path');
var name = _this.getNewId('路径');
var isLoop = _this.isLoopPath(elements);
var elementStr = elements.join(',');
if (!LoopSet.has(elementStr)) {
LoopSet.add(elementStr);
pathes.push({
routeId: routeId,
name: name,
elements: elements,
type: isLoop,
weight: 0,
similarElement: '',
});
}
});
var oldPathes = JSON.parse(JSON.stringify(this.pathes));
// 1) 找到所有路径最相似的路径, 给旧路径标记其最接近的路径
pathes.forEach(function (newPath) {
for (var i = 0; i < oldPathes.length; i++) {
var oldPath = oldPathes[i];
var weight = _this.similar2Path(__spread(newPath.elements), __spread(oldPath.elements));
if (weight > newPath.weight && oldPath.weight <= weight) {
newPath.weight = weight;
newPath.similarElement = oldPath;
if (weight === oldPath.weight && oldPath.similarElement) {
// 特殊处理,如果两个路径都与同一条旧路径有相似的权重,则这两个路径的相似路径都置空
oldPath.similarElement.similarElement = null;
oldPath.similarElement.weight = 0;
oldPath.similarElement = null;
oldPath.weight = 0;
}
else {
oldPath.similarElement = newPath;
oldPath.weight = weight;
}
}
}
});
// 2) 再次遍历所有路径,如果该路径的相似路径对应的相似路径是自己,那么就设置该路径id和name为其相似路径。
pathes.forEach(function (newPath) {
if (newPath.similarElement && newPath.similarElement.similarElement === newPath) {
newPath.routeId = newPath.similarElement.routeId;
newPath.name = newPath.similarElement.name;
}
delete newPath.similarElement;
delete newPath.weight;
});
this.setPathes(pathes);
return pathes;
};
FlowPath.prototype.similar2Path = function (x, y) {
var z = 0;
var s = x.length + y.length;
x.sort();
y.sort();
var a = x.shift();
var b = y.shift();
while (a !== undefined && b !== undefined) {
if (a === b) {
z++;
a = x.shift();
b = y.shift();
}
else if (a < b) {
a = x.shift();
}
else if (a > b) {
b = y.shift();
}
}
return (z / s) * 200;
};
FlowPath.prototype.getNewId = function (prefix) {
return prefix + "_" + getBpmnId();
};
/**
* 判断是否为循环路径
* 由于前面进行了特殊处理,将循环部分单独提出来作为路径
* 所有循环路径必定开始节点等于结束节点。
*/
FlowPath.prototype.isLoopPath = function (elements) {
var length = elements.length;
return elements.indexOf(elements[length - 1]) !== length - 1 ? 1 : 0;
};
FlowPath.pluginName = 'flowPath';
return FlowPath;
}());
export { FlowPath, };
@@ -0,0 +1,17 @@
/**
* 快照插件,生成视图
*/
declare const Snapshot: {
pluginName: string;
install(lf: any): void;
getSvgRootElement(lf: any): any;
triggerDownload(imgURI: string): void;
removeAnchor(element: any): void;
downloadSvg(svg: SVGGraphicsElement, fileName: string, backgroundColor: string): void;
getBase64(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
getBlob(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
getClassRules(): string;
getCanvasData(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
};
export default Snapshot;
export { Snapshot, };
@@ -0,0 +1,212 @@
/**
* 快照插件,生成视图
*/
var Snapshot = {
pluginName: 'snapshot',
install: function (lf) {
var _this = this;
this.lf = lf;
/* 下载快照 */
lf.getSnapshot = function (fileName, backgroundColor) {
_this.offsetX = Number.MAX_SAFE_INTEGER;
_this.offsetY = Number.MAX_SAFE_INTEGER;
_this.fileName = fileName || "logic-flow." + Date.now() + ".png";
var svgRootElement = _this.getSvgRootElement(lf);
_this.downloadSvg(svgRootElement, _this.fileName, backgroundColor);
};
/* 获取Blob对象,用户图片上传 */
lf.getSnapshotBlob = function (backgroundColor) {
_this.offsetX = Number.MAX_SAFE_INTEGER;
_this.offsetY = Number.MAX_SAFE_INTEGER;
var svgRootElement = _this.getSvgRootElement(lf);
return _this.getBlob(svgRootElement, backgroundColor);
};
/* 获取Base64对象,用户图片上传 */
lf.getSnapshotBase64 = function (backgroundColor) {
_this.offsetX = Number.MAX_SAFE_INTEGER;
_this.offsetY = Number.MAX_SAFE_INTEGER;
var svgRootElement = _this.getSvgRootElement(lf);
return _this.getBase64(svgRootElement, backgroundColor);
};
},
/* 获取svgRoot对象 */
getSvgRootElement: function (lf) {
var _this = this;
lf.graphModel.nodes.forEach(function (item) {
var x = item.x, width = item.width, y = item.y, height = item.height;
var offsetX = x - width / 2;
var offsetY = y - height / 2;
if (offsetX < _this.offsetX) {
_this.offsetX = offsetX - 5;
}
if (offsetY < _this.offsetY) {
_this.offsetY = offsetY - 5;
}
});
lf.graphModel.edges.forEach(function (edge) {
if (edge.pointsList) {
edge.pointsList.forEach(function (point) {
var x = point.x, y = point.y;
if (x < _this.offsetX) {
_this.offsetX = x - 5;
}
if (y < _this.offsetY) {
_this.offsetY = y - 5;
}
});
}
});
var svgRootElement = lf.container.querySelector('.lf-canvas-overlay');
return svgRootElement;
},
triggerDownload: function (imgURI) {
var evt = new MouseEvent('click', {
view: window,
bubbles: false,
cancelable: true,
});
var a = document.createElement('a');
a.setAttribute('download', this.fileName);
a.setAttribute('href', imgURI);
a.setAttribute('target', '_blank');
a.dispatchEvent(evt);
},
removeAnchor: function (element) {
var childNodes = element.childNodes;
var childLength = element.childNodes && element.childNodes.length;
for (var i = 0; i < childLength; i++) {
var child = childNodes[i];
var classList = (child.classList && Array.from(child.classList)) || [];
if (classList.indexOf('lf-anchor') > -1) {
element.removeChild(element.childNodes[i]);
childLength--;
i--;
}
}
},
/* 下载图片 */
downloadSvg: function (svg, fileName, backgroundColor) {
var _this = this;
this.getCanvasData(svg, backgroundColor).then(function (canvas) {
var imgURI = canvas
.toDataURL('image/png')
.replace('image/png', 'image/octet-stream');
_this.triggerDownload(imgURI, fileName);
});
},
/* 获取base64对象 */
getBase64: function (svg, backgroundColor) {
var _this = this;
return new Promise(function (resolve) {
_this.getCanvasData(svg, backgroundColor).then(function (canvas) {
var base64 = canvas.toDataURL('image/png');
// 输出图片数据以及图片宽高
resolve({ data: base64, width: canvas.width, height: canvas.height });
});
});
},
/* 获取Blob对象 */
getBlob: function (svg, backgroundColor) {
var _this = this;
return new Promise(function (resolve) {
_this.getCanvasData(svg, backgroundColor).then(function (canvas) {
canvas.toBlob(function (blob) {
// 输出图片数据以及图片宽高
resolve({ data: blob, width: canvas.width, height: canvas.height });
}, 'image/png');
});
});
},
getClassRules: function () {
var rules = '';
var styleSheets = document.styleSheets;
for (var i = 0; i < styleSheets.length; i++) {
var sheet = styleSheets[i];
for (var j = 0; j < sheet.cssRules.length; j++) {
rules += sheet.cssRules[j].cssText;
}
}
return rules;
},
// 获取图片生成中中间产物canvas对象,用户转换为其他需要的格式
getCanvasData: function (svg, backgroundColor) {
var _this = this;
var copy = svg.cloneNode(true);
var graph = copy.lastChild;
var childLength = graph.childNodes && graph.childNodes.length;
if (childLength) {
for (var i = 0; i < childLength; i++) {
var lfLayer = graph.childNodes[i];
// 只保留包含节点和边的基础图层进行下载,其他图层删除
var layerClassList = lfLayer.classList && Array.from(lfLayer.classList);
if (layerClassList && layerClassList.indexOf('lf-base') < 0) {
graph.removeChild(graph.childNodes[i]);
childLength--;
i--;
}
else {
// 删除锚点
var lfBase = graph.childNodes[i];
lfBase && lfBase.childNodes.forEach(function (item) {
var element = item;
_this.removeAnchor(element.firstChild);
});
}
}
}
// offset值加10,保证图形不会紧贴着下载图片的左边和上边
copy.lastChild.style.transform = "matrix(1, 0, 0, 1, " + (-this.offsetX + 10) + ", " + (-this.offsetY + 10) + ")";
var dpr = window.devicePixelRatio || 1;
var canvas = document.createElement('canvas');
/*
为了计算真实宽高需要取图的真实dom
真实dom存在缩放影响其宽高数值
在得到真实宽高后除以缩放比例即可得到正常宽高
*/
var base = document.getElementsByClassName('lf-base')[0];
var bbox = base.getBoundingClientRect();
var graphModel = this.lf.graphModel;
var transformModel = graphModel.transformModel;
var SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y;
var bboxWidth = Math.ceil(bbox.width / SCALE_X);
var bboxHeight = Math.ceil(bbox.height / SCALE_Y);
// width,height 值加40,保证图形不会紧贴着下载图片的右边和下边
canvas.style.width = bboxWidth + "px";
canvas.style.height = bboxHeight + "px";
canvas.width = bboxWidth * dpr + 80;
canvas.height = bboxHeight * dpr + 80;
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.scale(dpr, dpr);
// 如果有背景色,设置流程图导出的背景色
if (backgroundColor) {
ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, bboxWidth * dpr + 80, bboxHeight * dpr + 80);
}
else {
ctx.clearRect(0, 0, bboxWidth, bboxHeight);
}
var img = new Image();
var style = document.createElement('style');
style.innerHTML = this.getClassRules();
var foreignObject = document.createElement('foreignObject');
foreignObject.appendChild(style);
copy.appendChild(foreignObject);
return new Promise(function (resolve) {
img.onload = function () {
ctx.drawImage(img, 0, 0);
resolve(canvas);
};
/*
因为svg中存在dom存放在foreignObject元素中
SVG图形转成img对象
todo: 会导致一些清晰度问题这个需要再解决
*/
var svg2Img = "data:image/svg+xml;charset=utf-8," + new XMLSerializer().serializeToString(copy);
var imgSrc = svg2Img.replace(/\n/g, '').replace(/\t/g, '').replace(/#/g, '%23');
img.src = imgSrc;
});
},
};
export default Snapshot;
export { Snapshot, };
@@ -0,0 +1,22 @@
export declare function toTurboData(data: any): {
flowElementList: any[];
};
export declare function toLogicflowData(data: any): {
nodes: any[];
edges: any[];
};
declare const TurboAdapter: {
pluginName: string;
install(lf: any): void;
shapeConfigMap: Map<any, any>;
setCustomShape(key: any, val: any): void;
adapterOut(logicflowData: any): {
flowElementList: any[];
};
adapterIn(turboData: any): {
nodes: any[];
edges: any[];
};
};
export { TurboAdapter };
export default TurboAdapter;
@@ -0,0 +1,176 @@
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var TurboType;
(function (TurboType) {
TurboType[TurboType["SEQUENCE_FLOW"] = 1] = "SEQUENCE_FLOW";
TurboType[TurboType["START_EVENT"] = 2] = "START_EVENT";
TurboType[TurboType["END_EVENT"] = 3] = "END_EVENT";
TurboType[TurboType["USER_TASK"] = 4] = "USER_TASK";
// SERVICE_TASK = 5, 暂不支持
TurboType[TurboType["EXCLUSIVE_GATEWAY"] = 6] = "EXCLUSIVE_GATEWAY";
})(TurboType || (TurboType = {}));
// 转换Turbo识别的类型
function getTurboType(type) {
switch (type) {
case 'bpmn:sequenceFlow':
return TurboType.SEQUENCE_FLOW;
case 'bpmn:startEvent':
return TurboType.START_EVENT;
case 'bpmn:endEvent':
return TurboType.END_EVENT;
case 'bpmn:userTask':
return TurboType.USER_TASK;
// case 'bpmn:serviceTask':
// return TurboType.SERVICE_TASK;
case 'bpmn:exclusiveGateway':
return TurboType.EXCLUSIVE_GATEWAY;
default:
return type;
}
}
// 将LogicFlow中的Node数据转换为Turbo元素数据
function convertNodeToTurboElement(node) {
var id = node.id, type = node.type, x = node.x, y = node.y, _a = node.text, text = _a === void 0 ? '' : _a, properties = node.properties;
return {
incoming: [],
outgoing: [],
dockers: [],
type: getTurboType(node.type),
properties: __assign(__assign({}, properties), { name: (text && text.value) || '', x: x,
y: y,
text: text, logicFlowType: type }),
key: id,
};
}
// 将LogicFlow中的Eedg数据转换为Turbo元素数据
function convertEdgeToTurboElement(edge) {
var id = edge.id, type = edge.type, sourceNodeId = edge.sourceNodeId, targetNodeId = edge.targetNodeId, startPoint = edge.startPoint, endPoint = edge.endPoint, pointsList = edge.pointsList, _a = edge.text, text = _a === void 0 ? '' : _a, properties = edge.properties;
return {
incoming: [sourceNodeId],
outgoing: [targetNodeId],
type: getTurboType(type),
dockers: [],
properties: __assign(__assign({}, properties), { name: (text && text.value) || '', text: text,
startPoint: startPoint,
endPoint: endPoint,
pointsList: pointsList, logicFlowType: type }),
key: id,
};
}
// 将LogicFlow中数据转换为Turbo数据
export function toTurboData(data) {
var nodeMap = new Map();
var turboData = {
flowElementList: [],
};
data.nodes.forEach(function (node) {
var flowElement = convertNodeToTurboElement(node);
turboData.flowElementList.push(flowElement);
nodeMap.set(node.id, flowElement);
});
data.edges.forEach(function (edge) {
var flowElement = convertEdgeToTurboElement(edge);
var sourceElement = nodeMap.get(edge.sourceNodeId);
sourceElement.outgoing.push(flowElement.key);
var targetElement = nodeMap.get(edge.targetNodeId);
targetElement.incoming.push(flowElement.key);
turboData.flowElementList.push(flowElement);
});
return turboData;
}
// 将Turbo元素数据转换为LogicFlow中的Eedg数据
function convertFlowElementToEdge(element) {
var incoming = element.incoming, outgoing = element.outgoing, properties = element.properties, key = element.key;
var text = properties.text, startPoint = properties.startPoint, endPoint = properties.endPoint, pointsList = properties.pointsList, logicFlowType = properties.logicFlowType;
var edge = {
id: key,
type: logicFlowType,
sourceNodeId: incoming[0],
targetNodeId: outgoing[0],
text: text,
startPoint: startPoint,
endPoint: endPoint,
pointsList: pointsList,
properties: {},
};
// 这种转换方式,在自定义属性中不能与excludeProperties中的属性重名,否则将在转换过程中丢失
var excludeProperties = ['startPoint', 'endPoint', 'pointsList', 'text', 'logicFlowType'];
Object.keys(element.properties).forEach(function (property) {
if (excludeProperties.indexOf(property) === -1) {
edge.properties[property] = element.properties[property];
}
});
return edge;
}
// 将Turbo元素数据转换为LogicFlow中的Node数据
function convertFlowElementToNode(element) {
var properties = element.properties, key = element.key;
var x = properties.x, y = properties.y, text = properties.text, logicFlowType = properties.logicFlowType;
var node = {
id: key,
type: logicFlowType,
x: x,
y: y,
text: text,
properties: {},
};
// 这种转换方式,在自定义属性中不能与excludeProperties中的属性重名,否则将在转换过程中丢失
var excludeProperties = ['x', 'y', 'text', 'logicFlowType'];
Object.keys(element.properties).forEach(function (property) {
if (excludeProperties.indexOf(property) === -1) {
node.properties[property] = element.properties[property];
}
});
return node;
}
// 将Turbo元素数据转换为LogicFlow数据
export function toLogicflowData(data) {
var lfData = {
nodes: [],
edges: [],
};
var list = data.flowElementList;
list && list.length > 0 && list.forEach(function (element) {
if (element.type === TurboType.SEQUENCE_FLOW) {
var edge = convertFlowElementToEdge(element);
lfData.edges.push(edge);
}
else {
var node = convertFlowElementToNode(element);
lfData.nodes.push(node);
}
});
return lfData;
}
var TurboAdapter = {
pluginName: 'turboAdapter',
install: function (lf) {
lf.adapterIn = this.adapterIn;
lf.adapterOut = this.adapterOut;
},
shapeConfigMap: new Map(),
setCustomShape: function (key, val) {
this.shapeConfigMap.set(key, val);
},
adapterOut: function (logicflowData) {
if (logicflowData) {
return toTurboData(logicflowData);
}
},
adapterIn: function (turboData) {
if (turboData) {
return toLogicflowData(turboData);
}
},
};
export { TurboAdapter };
export default TurboAdapter;
+6
View File
@@ -0,0 +1,6 @@
import { BaseNodeModel } from '@logicflow/core';
declare type PointTuple = [number, number];
export declare type ExclusiveGatewayAttribute = BaseNodeModel & {
points?: PointTuple[] & string;
};
export {};
Whitespace-only changes.