更新logicflow包

This commit is contained in:
Jam committed 2022-11-28 14:55:01 +08:00
1 parent e78ebb747d
commit 2583575725
113 files changed
+41211 -588

No files matched your search

@@ -23,6 +23,22 @@ var __assign = (this && this.__assign) || function () {
};
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
var preact_1 = require("preact");
var core_1 = require("@logicflow/core");
@@ -43,8 +59,64 @@ var Control = /** @class */ (function (_super) {
};
// 计算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 };
var index = _a.index, deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height, PCTResizeInfo = _a.PCTResizeInfo, _b = _a.pct, pct = _b === void 0 ? 1 : _b;
var resize = { width: width, height: height, deltaX: deltaX, deltaY: deltaY };
if (PCTResizeInfo) {
var sensitivity = 4; // 越低越灵敏
var deltaScale = 0;
var combineDleta = 0;
switch (index) {
case 0:
combineDleta = (deltaX * -1 - deltaY) / sensitivity;
break;
case 1:
combineDleta = (deltaX - deltaY) / sensitivity;
break;
case 2:
combineDleta = (deltaX + deltaY) / sensitivity;
break;
case 3:
combineDleta = (deltaX * -1 + deltaY) / sensitivity;
break;
default:
break;
}
if (combineDleta !== 0) {
deltaScale = Math.round((combineDleta / PCTResizeInfo.ResizeBasis.basisHeight)
* 100000) / 1000;
}
PCTResizeInfo.ResizePCT.widthPCT = Math.max(Math.min(PCTResizeInfo.ResizePCT.widthPCT + deltaScale, PCTResizeInfo.ScaleLimit.maxScaleLimit), PCTResizeInfo.ScaleLimit.minScaleLimit);
PCTResizeInfo.ResizePCT.hightPCT = Math.max(Math.min(PCTResizeInfo.ResizePCT.hightPCT + deltaScale, PCTResizeInfo.ScaleLimit.maxScaleLimit), PCTResizeInfo.ScaleLimit.minScaleLimit);
var spcWidth = Math.round((PCTResizeInfo.ResizePCT.widthPCT
* PCTResizeInfo.ResizeBasis.basisWidth) / 100);
var spcHeight = Math.round((PCTResizeInfo.ResizePCT.hightPCT
* PCTResizeInfo.ResizeBasis.basisHeight) / 100);
switch (index) {
case 0:
deltaX = width - spcWidth;
deltaY = height - spcHeight;
break;
case 1:
deltaX = spcWidth - width;
deltaY = height - spcHeight;
break;
case 2:
deltaX = spcWidth - width;
deltaY = spcHeight - height;
break;
case 3:
deltaX = width - spcWidth;
deltaY = spcHeight - height;
break;
default:
break;
}
resize.width = spcWidth;
resize.height = spcHeight;
resize.deltaX = deltaX / pct;
resize.deltaY = deltaY / pct;
return resize;
}
switch (index) {
case 0:
resize.width = width - deltaX * pct;
@@ -55,7 +127,7 @@ var Control = /** @class */ (function (_super) {
resize.height = height - deltaY * pct;
break;
case 2:
resize.width = width + deltaX;
resize.width = width + deltaX * pct;
resize.height = height + deltaY * pct;
break;
case 3:
@@ -70,7 +142,7 @@ var Control = /** @class */ (function (_super) {
// 矩形更新
_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 _b = _this.nodeModel, id = _b.id, x = _b.x, y = _b.y, width = _b.width, height = _b.height, radius = _b.radius, PCTResizeInfo = _b.PCTResizeInfo;
// 更新中心点位置,更新文案位置
var index = _this.index;
var size = _this.getResize({
@@ -79,6 +151,7 @@ var Control = /** @class */ (function (_super) {
deltaY: deltaY,
width: width,
height: height,
PCTResizeInfo: PCTResizeInfo,
pct: 1,
});
// 限制放大缩小的最大最小范围
@@ -91,7 +164,7 @@ var Control = /** @class */ (function (_super) {
_this.dragHandler.cancelDrag();
return;
}
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
_this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
// 更新宽高
_this.nodeModel.width = size.width;
_this.nodeModel.height = size.height;
@@ -138,7 +211,7 @@ var Control = /** @class */ (function (_super) {
// 椭圆更新
_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 _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y, PCTResizeInfo = _b.PCTResizeInfo;
var index = _this.index;
var width = rx;
var height = ry;
@@ -148,6 +221,7 @@ var Control = /** @class */ (function (_super) {
deltaY: deltaY,
width: width,
height: height,
PCTResizeInfo: PCTResizeInfo,
pct: 1 / 2,
});
// 限制放大缩小的最大最小范围
@@ -160,12 +234,12 @@ var Control = /** @class */ (function (_super) {
return;
}
// 更新中心点位置,更新文案位置
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
_this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
// 更新rx ry,宽高为计算属性自动更新
// @ts-ignore
_this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
_this.nodeModel.rx = size.width;
// @ts-ignore
_this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
_this.nodeModel.ry = size.height;
_this.nodeModel.setProperties({
nodeSize: {
rx: size.width,
@@ -202,7 +276,7 @@ var Control = /** @class */ (function (_super) {
// 菱形更新
_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 _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y, PCTResizeInfo = _b.PCTResizeInfo;
var index = _this.index;
var width = rx;
var height = ry;
@@ -212,6 +286,7 @@ var Control = /** @class */ (function (_super) {
deltaY: deltaY,
width: width,
height: height,
PCTResizeInfo: PCTResizeInfo,
pct: 1 / 2,
});
// 限制放大缩小的最大最小范围
@@ -224,12 +299,12 @@ var Control = /** @class */ (function (_super) {
return;
}
// 更新中心点位置,更新文案位置
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
_this.updatePosition({ deltaX: size.deltaX, deltaY: size.deltaY });
// 更新rx ry,宽高为计算属性自动更新
// @ts-ignore
_this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
_this.nodeModel.rx = size.width;
// @ts-ignore
_this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
_this.nodeModel.ry = size.height;
_this.nodeModel.setProperties({
nodeSize: {
rx: size.width,
@@ -271,8 +346,11 @@ var Control = /** @class */ (function (_super) {
_this.graphModel.eventCenter.emit('node:resize', { oldNodeSize: oldNodeSize, newNodeSize: newNodeSize });
};
_this.onDraging = function (_a) {
var _b;
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var transformModel = _this.graphModel.transformModel;
var modelType = _this.nodeModel.modelType;
_b = __read(transformModel.fixDeltaXY(deltaX, deltaY), 2), deltaX = _b[0], deltaY = _b[1];
// html和矩形的计算方式是一样的,共用一个方法
if (modelType === Util_1.ModelType.RECT_NODE || modelType === Util_1.ModelType.HTML_NODE) {
_this.updateRect({ deltaX: deltaX, deltaY: deltaY });
@@ -285,23 +363,32 @@ var Control = /** @class */ (function (_super) {
_this.updateDiamond({ deltaX: deltaX, deltaY: deltaY });
}
};
/**
* 由于将拖拽放大缩小改成丝滑模式,这个时候需要在拖拽结束的时候,将节点的位置更新到grid上.
*/
_this.onDragEnd = function () {
var _a = _this.graphModel.gridSize, gridSize = _a === void 0 ? 1 : _a;
var x = gridSize * Math.round(_this.nodeModel.x / gridSize);
var y = gridSize * Math.round(_this.nodeModel.y / gridSize);
_this.nodeModel.moveTo(x, y);
};
_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;
}
// let 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,
onDragEnd: _this.onDragEnd,
step: 1,
});
return _this;
}
@@ -48,6 +48,9 @@ var DiamondResizeModel = /** @class */ (function (_super) {
};
DiamondResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
var isSilentMode = this.graphModel.editConfigModel.isSilentMode;
if (isSilentMode)
return style;
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
@@ -69,6 +72,22 @@ var DiamondResizeModel = /** @class */ (function (_super) {
stroke: '#000000',
};
};
// 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
DiamondResizeModel.prototype.enableProportionResize = function (turnOn) {
if (turnOn === void 0) { turnOn = true; }
if (turnOn) {
var ResizePCT = { widthPCT: 100, hightPCT: 100 };
var ResizeBasis = { basisWidth: this.rx, basisHeight: this.ry };
var ScaleLimit = {
maxScaleLimit: Math.min((this.maxWidth / (this.rx * 2)) * 100, (this.maxHeight / (this.ry * 2)) * 100),
minScaleLimit: Math.max((this.minWidth / (this.rx * 2)) * 100, (this.minHeight / (this.ry * 2)) * 100),
};
this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
}
else {
delete this.PCTResizeInfo;
}
};
return DiamondResizeModel;
}(core_1.DiamondNodeModel));
var DiamondResizeView = /** @class */ (function (_super) {
@@ -89,10 +108,10 @@ var DiamondResizeView = /** @class */ (function (_super) {
core_1.h(Polygon_1.default, __assign({}, style, { points: points }))));
};
DiamondResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
var _a = this.props, isSelected = _a.model.isSelected, isSilentMode = _a.graphModel.editConfigModel.isSilentMode;
return (core_1.h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
isSelected && !isSilentMode ? this.getControlGroup() : ''));
};
return DiamondResizeView;
}(core_1.DiamondNode));
@@ -35,6 +35,9 @@ var EllipseResizeModel = /** @class */ (function (_super) {
};
EllipseResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
var isSilentMode = this.graphModel.editConfigModel.isSilentMode;
if (isSilentMode)
return style;
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
@@ -56,6 +59,22 @@ var EllipseResizeModel = /** @class */ (function (_super) {
stroke: '#000000',
};
};
// 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
EllipseResizeModel.prototype.enableProportionResize = function (turnOn) {
if (turnOn === void 0) { turnOn = true; }
if (turnOn) {
var ResizePCT = { widthPCT: 100, hightPCT: 100 };
var ResizeBasis = { basisWidth: this.rx, basisHeight: this.ry };
var ScaleLimit = {
maxScaleLimit: Math.min((this.maxWidth / (this.rx * 2)) * 100, (this.maxHeight / (this.ry * 2)) * 100),
minScaleLimit: Math.max((this.minWidth / (this.rx * 2)) * 100, (this.minHeight / (this.ry * 2)) * 100),
};
this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
}
else {
delete this.PCTResizeInfo;
}
};
return EllipseResizeModel;
}(core_1.EllipseNodeModel));
var EllipseResizeView = /** @class */ (function (_super) {
@@ -72,10 +91,10 @@ var EllipseResizeView = /** @class */ (function (_super) {
return _super.prototype.getShape.call(this);
};
EllipseResizeView.prototype.getShape = function () {
var model = this.props.model;
var _a = this.props, model = _a.model, isSilentMode = _a.graphModel.editConfigModel.isSilentMode;
return (core_1.h("g", null,
this.getResizeShape(),
model.isSelected ? this.getControlGroup() : ''));
model.isSelected && !isSilentMode ? this.getControlGroup() : ''));
};
return EllipseResizeView;
}(core_1.EllipseNode));
@@ -35,6 +35,9 @@ var HtmlResizeModel = /** @class */ (function (_super) {
};
HtmlResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
var isSilentMode = this.graphModel.editConfigModel.isSilentMode;
if (isSilentMode)
return style;
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
@@ -56,6 +59,22 @@ var HtmlResizeModel = /** @class */ (function (_super) {
stroke: '#000000',
};
};
// 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
HtmlResizeModel.prototype.enableProportionResize = function (turnOn) {
if (turnOn === void 0) { turnOn = true; }
if (turnOn) {
var ResizePCT = { widthPCT: 100, hightPCT: 100 };
var ResizeBasis = { basisWidth: this.width, basisHeight: this.height };
var ScaleLimit = {
maxScaleLimit: Math.min((this.maxWidth / this.width) * 100, (this.maxHeight / this.height) * 100),
minScaleLimit: Math.max((this.minWidth / this.width) * 100, (this.minHeight / this.height) * 100),
};
this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
}
else {
delete this.PCTResizeInfo;
}
};
return HtmlResizeModel;
}(core_1.HtmlNodeModel));
var HtmlResizeView = /** @class */ (function (_super) {
@@ -72,10 +91,10 @@ var HtmlResizeView = /** @class */ (function (_super) {
return _super.prototype.getShape.call(this);
};
HtmlResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
var _a = this.props, isSelected = _a.model.isSelected, isSilentMode = _a.graphModel.editConfigModel.isSilentMode;
return (core_1.h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
isSelected && !isSilentMode ? this.getControlGroup() : ''));
};
return HtmlResizeView;
}(core_1.HtmlNode));
@@ -35,6 +35,9 @@ var RectResizeModel = /** @class */ (function (_super) {
};
RectResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
var isSilentMode = this.graphModel.editConfigModel.isSilentMode;
if (isSilentMode)
return style;
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
@@ -60,6 +63,22 @@ var RectResizeModel = /** @class */ (function (_super) {
RectResizeModel.prototype.resize = function (deltaX, deltaY) {
console.log(deltaX, deltaY);
};
// 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
RectResizeModel.prototype.enableProportionResize = function (turnOn) {
if (turnOn === void 0) { turnOn = true; }
if (turnOn) {
var ResizePCT = { widthPCT: 100, hightPCT: 100 };
var ResizeBasis = { basisWidth: this.width, basisHeight: this.height };
var ScaleLimit = {
maxScaleLimit: Math.min((this.maxWidth / this.width) * 100, (this.maxHeight / this.height) * 100),
minScaleLimit: Math.max((this.minWidth / this.width) * 100, (this.minHeight / this.height) * 100),
};
this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
}
else {
delete this.PCTResizeInfo;
}
};
return RectResizeModel;
}(core_1.RectNodeModel));
var RectResizeView = /** @class */ (function (_super) {
@@ -76,10 +95,10 @@ var RectResizeView = /** @class */ (function (_super) {
return _super.prototype.getShape.call(this);
};
RectResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
var _a = this.props, isSelected = _a.model.isSelected, isSilentMode = _a.graphModel.editConfigModel.isSilentMode;
return (core_1.h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
isSelected && !isSilentMode ? this.getControlGroup() : ''));
};
return RectResizeView;
}(core_1.RectNode));
@@ -0,0 +1,187 @@
"use strict";
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Highlight = void 0;
// 后续并入FlowPath
var getPath = function (id, lf) {
var el = lf.getModelById(id);
return getNodePath(el.BaseType === 'node' ? el : el.targetNode, lf);
};
// dfs + 动态规划
// todo 算法优化
var getNodePath = function (node, lf) {
var incomingPaths = [];
var outgoingPaths = [];
var getIncomingPaths = function (curNode, path, prevNode) {
if (prevNode === void 0) { prevNode = null; }
if (prevNode) {
// * 上个节点和当前节点中间边
path.unshift.apply(path, __spread(lf
.getEdgeModels({
sourceNodeId: curNode.id,
targetNodeId: prevNode.id,
})
.map(function (item) { return item.id; })));
}
// * 路径中存在节点,则不再继续查找,说明出现环情况
if (path.includes(curNode.id)) {
incomingPaths.push(path);
return;
}
// * 路径中当前加入节点
path.unshift(curNode.id);
if (!curNode.incoming.nodes.length) {
incomingPaths.push(path);
return;
}
// * 往下找
curNode.incoming.nodes.forEach(function (nextNode) {
getIncomingPaths(nextNode, path.slice(), curNode);
});
};
// * 同上逻辑
var getOutgoingPaths = function (curNode, path, prevNode) {
if (prevNode === void 0) { prevNode = null; }
if (prevNode) {
path.push.apply(path, __spread(lf
.getEdgeModels({
sourceNodeId: prevNode.id,
targetNodeId: curNode.id,
})
.map(function (item) { return item.id; })));
}
if (path.includes(curNode.id)) {
outgoingPaths.push(path);
return;
}
path.push(curNode.id);
if (!curNode.outgoing.nodes.length) {
outgoingPaths.push(path);
return;
}
curNode.outgoing.nodes.forEach(function (nextNode) {
getOutgoingPaths(nextNode, path.slice(), curNode);
});
};
getIncomingPaths(node, []);
getOutgoingPaths(node, []);
return __spread(new Set(__spread(incomingPaths.flat(), outgoingPaths.flat())));
};
var Highlight = /** @class */ (function () {
function Highlight(_a) {
var lf = _a.lf;
this.mode = 'path';
this.manual = false;
this.tempStyles = {};
this.lf = lf;
}
Highlight.prototype.setMode = function (mode) {
this.mode = mode;
};
Highlight.prototype.setManual = function (manual) {
this.manual = manual;
};
Highlight.prototype.highlightSingle = function (id) {
var model = this.lf.getModelById(id);
if (model.BaseType === 'node') {
// 高亮节点
model.updateStyles(this.tempStyles[id]);
}
else if (model.BaseType === 'edge') {
// 高亮边及对应的节点
model.updateStyles(this.tempStyles[id]);
model.sourceNode.updateStyles(this.tempStyles[model.sourceNode.id]);
model.targetNode.updateStyles(this.tempStyles[model.targetNode.id]);
}
};
Highlight.prototype.highlightPath = function (id) {
var _this = this;
var path = getPath(id, this.lf);
path.forEach(function (_id) {
// 高亮路径上所有的边和节点
_this.lf.getModelById(_id).updateStyles(_this.tempStyles[_id]);
});
};
Highlight.prototype.highlight = function (id, mode) {
var _this = this;
if (mode === void 0) { mode = this.mode; }
if (this.manual)
return;
if (Object.keys(this.tempStyles).length) {
this.restoreHighlight();
}
Object.values(this.lf.graphModel.modelsMap).forEach(function (item) {
// 所有节点样式都进行备份
// eslint-disable-next-line operator-linebreak
var oStyle = item.BaseType === 'node' ? item.getNodeStyle() : item.getEdgeStyle();
_this.tempStyles[item.id] = __assign({}, oStyle);
// 所有节点都设置透明度为0.1
item.setStyles({ opacity: 0.1 });
});
var modeTrigger = {
single: this.highlightSingle.bind(this),
path: this.highlightPath.bind(this),
};
modeTrigger[mode](id);
};
Highlight.prototype.restoreHighlight = function () {
var _this = this;
// 恢复所有节点的样式
if (!Object.keys(this.tempStyles).length)
return;
Object.values(this.lf.graphModel.modelsMap).forEach(function (item) {
var _a;
var oStyle = (_a = _this.tempStyles[item.id]) !== null && _a !== void 0 ? _a : {};
item.updateStyles(__assign({}, oStyle));
});
this.tempStyles = {};
};
Highlight.prototype.render = function (lf, domContainer) {
var _this = this;
this.lf.on('node:mouseenter', function (_a) {
var data = _a.data;
return _this.highlight(data.id);
});
this.lf.on('edge:mouseenter', function (_a) {
var data = _a.data;
return _this.highlight(data.id);
});
this.lf.on('node:mouseleave', this.restoreHighlight.bind(this));
this.lf.on('edge:mouseleave', this.restoreHighlight.bind(this));
this.lf.on('history:change', this.restoreHighlight.bind(this));
};
Highlight.prototype.destroy = function () { };
Highlight.pluginName = 'highlight';
return Highlight;
}());
exports.Highlight = Highlight;
@@ -64,12 +64,17 @@ var MiniMap = /** @class */ (function () {
y: e.y,
};
};
this.__drag = function (e) {
this.moveViewport = function (top, left) {
var viewStyle = _this.__viewport.style;
_this.__viewPortTop += e.y - _this.__startPosition.y;
_this.__viewPortLeft += e.x - _this.__startPosition.x;
_this.__viewPortTop = top;
_this.__viewPortLeft = left;
viewStyle.top = _this.__viewPortTop + "px";
viewStyle.left = _this.__viewPortLeft + "px";
};
this.__drag = function (e) {
var top = _this.__viewPortTop + e.y - _this.__startPosition.y;
var left = _this.__viewPortLeft + e.x - _this.__startPosition.x;
_this.moveViewport(top, left);
_this.__startPosition = {
x: e.x,
y: e.y,
@@ -88,6 +93,21 @@ var MiniMap = /** @class */ (function () {
this.__drop = function () {
document.removeEventListener('mousemove', _this.__drag);
document.removeEventListener('mouseup', _this.__drop);
var top = _this.__viewPortTop;
var left = _this.__viewPortLeft;
if (_this.__viewPortLeft > _this.__width) {
left = _this.__width - _this.__viewPortWidth;
}
if (_this.__viewPortTop > _this.__height) {
top = _this.__height - _this.__viewPortHeight;
}
if (_this.__viewPortLeft < -_this.__width) {
left = 0;
}
if (_this.__viewPortTop < -_this.__height) {
top = 0;
}
_this.moveViewport(top, left);
};
this.__lf = lf;
this.__miniMapWidth = lf.graphModel.width;
@@ -103,6 +123,11 @@ var MiniMap = /** @class */ (function () {
_this.__setView();
}
});
this.__lf.on('blank:drop', function () {
if (_this.__isShow) {
_this.__setView();
}
});
};
MiniMap.prototype.init = function (option) {
this.__disabledPlugins = this.__disabledPlugins.concat(option.disabledPlugins || []);
@@ -306,7 +331,7 @@ var MiniMap = /** @class */ (function () {
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.__viewPortLeft = TRANSLATE_X > 0 ? 0 : -TRANSLATE_X * scale;
this.__viewPortWidth = realViewPortWidth;
this.__viewPortHeight = realViewPortHeight;
viewStyle.top = this.__viewPortTop + "px";
@@ -6,7 +6,7 @@ var SelectionSelect = /** @class */ (function () {
var _this = this;
var lf = _a.lf;
this.__disabled = false;
this.isDefalutStopMoveGraph = false;
this.isDefaultStopMoveGraph = false;
this.isWholeNode = true;
this.isWholeEdge = true;
this.__draw = function (ev) {
@@ -34,6 +34,7 @@ var SelectionSelect = /** @class */ (function () {
this.__drawOff = function () {
document.removeEventListener('mousemove', _this.__draw);
document.removeEventListener('mouseup', _this.__drawOff);
_this.wrapper.oncontextmenu = null;
_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;
@@ -43,16 +44,20 @@ var SelectionSelect = /** @class */ (function () {
}
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);
var elements = _this.lf.graphModel.getAreaElement(lt, rt, _this.isWholeEdge, _this.isWholeNode, true);
var group = _this.lf.graphModel.group;
elements.forEach(function (element) {
_this.lf.selectElementById(element.id, true);
// 如果节点属于分组,则不不选中节点
if (!group || !group.getNodeGroup(element.id)) {
_this.lf.selectElementById(element.id, true);
}
});
_this.lf.emit('selection:selected', elements);
};
this.lf = lf;
// 初始化isDefalutStopMoveGraph取值
// 初始化isDefaultStopMoveGraph取值
var stopMoveGraph = lf.getEditConfig().stopMoveGraph;
this.isDefalutStopMoveGraph = stopMoveGraph;
this.isDefaultStopMoveGraph = stopMoveGraph;
lf.openSelectionSelect = function () {
_this.openSelectionSelect();
};
@@ -75,6 +80,9 @@ var SelectionSelect = /** @class */ (function () {
_this.endPoint = { x: x, y: y };
var wrapper = document.createElement('div');
wrapper.className = 'lf-selection-select';
wrapper.oncontextmenu = function prevent(ev) {
ev.preventDefault();
};
wrapper.style.top = _this.startPoint.y + "px";
wrapper.style.left = _this.startPoint.x + "px";
domContainer.appendChild(wrapper);
@@ -100,7 +108,7 @@ var SelectionSelect = /** @class */ (function () {
SelectionSelect.prototype.openSelectionSelect = function () {
var stopMoveGraph = this.lf.getEditConfig().stopMoveGraph;
if (!stopMoveGraph) {
this.isDefalutStopMoveGraph = false;
this.isDefaultStopMoveGraph = false;
this.lf.updateEditConfig({
stopMoveGraph: true,
});
@@ -111,7 +119,7 @@ var SelectionSelect = /** @class */ (function () {
* 关闭选区
*/
SelectionSelect.prototype.closeSelectionSelect = function () {
if (!this.isDefalutStopMoveGraph) {
if (!this.isDefaultStopMoveGraph) {
this.lf.updateEditConfig({
stopMoveGraph: false,
});
@@ -29,3 +29,4 @@ __exportStar(require("./tools/flow-path"), exports);
__exportStar(require("./tools/auto-layout"), exports);
__exportStar(require("./bpmn-adapter/xml2json"), exports);
__exportStar(require("./bpmn-adapter/json2xml"), exports);
__exportStar(require("./components/highlight"), exports);
@@ -12,6 +12,17 @@ var __extends = (this && this.__extends) || (function () {
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;
@@ -29,17 +40,36 @@ var __read = (this && this.__read) || function (o, n) {
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CurvedEdge = void 0;
exports.CurvedEdgeModel = exports.CurvedEdge = void 0;
var core_1 = require("@logicflow/core");
var CurvedEdgeView = /** @class */ (function (_super) {
__extends(CurvedEdgeView, _super);
function CurvedEdgeView() {
var CurvedEdge = /** @class */ (function (_super) {
__extends(CurvedEdge, _super);
function CurvedEdge() {
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); }); });
CurvedEdge.prototype.pointFilter = function (points) {
var allPoints = points;
var i = 1;
while (i < allPoints.length - 1) {
var _a = __read(allPoints[i - 1], 2), x = _a[0], y = _a[1];
var _b = __read(allPoints[i], 2), x1 = _b[0], y1 = _b[1];
var _c = __read(allPoints[i + 1], 2), x2 = _c[0], y2 = _c[1];
if ((x === x1 && x1 === x2)
|| (y === y1 && y1 === y2)) {
allPoints.splice(i, 1);
}
else {
i++;
}
}
return allPoints;
};
CurvedEdge.prototype.getEdge = function () {
var model = this.props.model;
var points = model.points, isAnimation = model.isAnimation, arrowConfig = model.arrowConfig, _a = model.radius, radius = _a === void 0 ? 5 : _a;
var style = model.getEdgeStyle();
var animationStyle = model.getEdgeAnimationStyle();
var points2 = this.pointFilter(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) 如果一个点不为开始和结束,则在这个点的前后增加弧度开始和结束点。
@@ -47,43 +77,36 @@ var CurvedEdgeView = /** @class */ (function (_super) {
// 如果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;
var y = currentY > preY ? currentY - radius : currentY + radius;
d = d + " L " + currentX + " " + y;
}
if (currentY === preY && currentX !== preX) {
var x = currentX > preX ? currentX - space : currentX + space;
var x = currentX > preX ? currentX - radius : currentX + radius;
d = d + " L " + x + " " + currentY;
}
d = d + " Q " + currentX + " " + currentY;
if (currentX === nextX && currentY !== nextY) {
var y = currentY > nextY ? currentY - space : currentY + space;
var y = currentY > nextY ? currentY - radius : currentY + radius;
d = d + " " + currentX + " " + y;
}
if (currentY === nextY && currentX !== nextX) {
var x = currentX > nextX ? currentX - space : currentX + space;
var x = currentX > nextX ? currentX - radius : currentX + radius;
d = d + " " + x + " " + currentY;
}
}
var _f = __read(points2[points2.length - 1], 2), endX = _f[0], endY = _f[1];
d = d + " L " + endX + " " + endY;
return core_1.h('path', {
d: d,
strokeWidth: strokeWidth,
stroke: stroke,
fill: 'none',
strokeDashArray: strokeDashArray,
});
var attrs = __assign(__assign(__assign({ d: d, style: isAnimation ? animationStyle : {} }, style), arrowConfig), { fill: 'none' });
return core_1.h('path', __assign({ d: d }, attrs));
};
CurvedEdgeView.extendKey = 'curvedEdge';
return CurvedEdgeView;
return CurvedEdge;
}(core_1.PolylineEdge));
exports.CurvedEdge = CurvedEdge;
var CurvedEdgeModel = /** @class */ (function (_super) {
__extends(CurvedEdgeModel, _super);
function CurvedEdgeModel() {
@@ -91,20 +114,4 @@ var CurvedEdgeModel = /** @class */ (function (_super) {
}
return CurvedEdgeModel;
}(core_1.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,
});
},
};
exports.CurvedEdge = CurvedEdge;
exports.default = CurvedEdge;
exports.CurvedEdgeModel = CurvedEdgeModel;
@@ -48,6 +48,7 @@ var core_1 = require("@logicflow/core");
var NodeResize_1 = require("../../NodeResize");
var defaultWidth = 500;
var defaultHeight = 300;
var DEFAULT_BOTTOM_Z_INDEX = -10000;
var GroupNodeModel = /** @class */ (function (_super) {
__extends(GroupNodeModel, _super);
function GroupNodeModel() {
@@ -70,8 +71,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
this.height = defaultHeight;
this.foldedWidth = 80;
this.foldedHeight = 60;
// todo: 参考bpmn.js, 分组和未加入分组的节点重合时,未加入分组的节点在分组之下。方便标识。
this.zIndex = -1;
this.zIndex = DEFAULT_BOTTOM_Z_INDEX;
this.radius = 0;
this.text.editable = false;
this.text.draggable = false;
@@ -222,7 +222,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
var model = this.graphModel.addEdge(edgeData);
model.virtual = true;
// 强制不保存group连线数据
model.getData = function () { return null; };
// model.getData = () => null;
model.text.editable = false;
model.isFoldedEdge = true;
};
@@ -276,6 +276,7 @@ var GroupNodeModel = /** @class */ (function (_super) {
GroupNodeModel.prototype.getHistoryData = function () {
var data = _super.prototype.getData.call(this);
data.children = __spread(this.children);
data.isGroup = true;
var properties = data.properties;
delete properties.groupAddable;
if (properties.isFolded) { // 如果分组被折叠
@@ -284,6 +285,18 @@ var GroupNodeModel = /** @class */ (function (_super) {
}
return data;
};
/**
* 是否允许此节点添加到此分组中
*/
GroupNodeModel.prototype.isAllowAppendIn = function (nodeData) {
return true;
};
/**
* 当groupA被添加到groupB中时,将groupB及groupB所属的group的zIndex减1
*/
GroupNodeModel.prototype.toBack = function () {
this.zIndex--;
};
return GroupNodeModel;
}(NodeResize_1.RectResize.model));
var GroupNode = /** @class */ (function (_super) {
@@ -295,7 +308,7 @@ var GroupNode = /** @class */ (function (_super) {
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 () {
GroupNode.prototype.getAddableShape = 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;
@@ -341,7 +354,7 @@ var GroupNode = /** @class */ (function (_super) {
};
GroupNode.prototype.getResizeShape = function () {
return core_1.h('g', {}, [
this.getAddedableShape(),
this.getAddableShape(),
_super.prototype.getResizeShape.call(this),
this.getFoldIcon(),
]);
@@ -1,32 +1,15 @@
"use strict";
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GroupNode = exports.Group = void 0;
var GroupNode_1 = require("./GroupNode");
exports.GroupNode = GroupNode_1.default;
var DEFAULT_TOP_Z_INDEX = -1000;
var DEFAULT_BOTTOM_Z_INDEX = -10000;
var Group = /** @class */ (function () {
function Group(_a) {
var _this = this;
var lf = _a.lf;
this.topGroupZIndex = DEFAULT_BOTTOM_Z_INDEX;
this.nodeGroupMap = new Map();
this.graphRendered = function (data) {
// 如果节点
@@ -40,7 +23,7 @@ var Group = /** @class */ (function () {
});
}
};
this.appendNodeToGrop = function (_a) {
this.appendNodeToGroup = function (_a) {
var data = _a.data;
// 如果这个节点之前已经在group中了,则将其从之前的group中移除
var preGroupId = _this.nodeGroupMap.get(data.id);
@@ -51,24 +34,39 @@ var Group = /** @class */ (function () {
preGroup.setAllowAppendChild(false);
}
// 然后再判断这个节点是否在某个group中,如果在,则将其添加到对应的group中
var bounds = _this.lf.getNodeModelById(data.id).getBounds();
var group = _this.getGroup(bounds);
var nodeModel = _this.lf.getNodeModelById(data.id);
var bounds = nodeModel.getBounds();
var group = _this.getGroup(bounds, data);
if (!group)
return;
if (data.id !== group.id) {
group.addChild(data.id);
_this.nodeGroupMap.set(data.id, group.id);
group.setAllowAppendChild(false);
var isAllowAppendIn = group.isAllowAppendIn(data);
if (!isAllowAppendIn) {
_this.lf.emit('group:not-allowed', {
group: group.getData(),
node: data,
});
return;
}
else if (data.children && data.children.length > 0) {
// 表示当前添加的节点是一个新增的group
group.addChild(data.id);
_this.nodeGroupMap.set(data.id, group.id);
group.setAllowAppendChild(false);
// 如果这个节点是分组,那么将其子节点也记录下来
if (nodeModel.isGroup) {
data.children.forEach(function (nodeId) {
_this.nodeGroupMap.set(nodeId, data.id);
});
_this.nodeSelected({ data: data });
}
};
this.deleteGroupChild = function (_a) {
var data = _a.data;
// 如果删除的是分组节点,则同时删除分组的子节点
if (data.children) {
data.children.forEach(function (nodeId) {
_this.nodeGroupMap.delete(nodeId);
_this.lf.deleteNode(nodeId);
});
}
var groupId = _this.nodeGroupMap.get(data.id);
if (groupId) {
var group = _this.lf.getNodeModelById(groupId);
@@ -79,25 +77,66 @@ var Group = /** @class */ (function () {
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);
var newGroup = _this.getGroup(bounds, data);
if (_this.activeGroup) {
_this.activeGroup.setAllowAppendChild(false);
}
if (!newGroup || (nodeModel.isGroup && newGroup.id === data.id))
return;
var isAllowAppendIn = newGroup.isAllowAppendIn(data);
if (!isAllowAppendIn) {
return;
}
_this.activeGroup = newGroup;
_this.activeGroup.setAllowAppendChild(true);
};
/**
* 1. 分组节点默认在普通节点下面。
* 2. 分组节点被选中后,会将分组节点以及其内部的其他分组节点放到其余分组节点的上面。
* 3. 分组节点取消选中后,不会将分组节点重置为原来的高度。
* 4. 由于LogicFlow核心目标是支持用户手动绘制流程图,所以不考虑一张流程图超过1000个分组节点的情况。
*/
this.nodeSelected = function (_a) {
var data = _a.data;
var nodeModel = _this.lf.getNodeModelById(data.id);
_this.toFrontGroup(nodeModel);
// 重置所有的group zIndex,防止group节点zIndex增长为正。
if (_this.topGroupZIndex > DEFAULT_TOP_Z_INDEX) {
_this.topGroupZIndex = DEFAULT_BOTTOM_Z_INDEX;
var allGroups = _this.lf.graphModel.nodes
.filter(function (node) { return node.isGroup; })
.sort(function (a, b) { return a.zIndex - b.zIndex; });
var preZIndex = 0;
for (var i = 0; i < allGroups.length; i++) {
var group = allGroups[i];
if (group.zIndex !== preZIndex) {
_this.topGroupZIndex++;
preZIndex = group.zIndex;
}
group.setZIndex(_this.topGroupZIndex);
}
}
};
this.toFrontGroup = function (model) {
if (!model || !model.isGroup) {
return;
}
_this.topGroupZIndex++;
model.setZIndex(_this.topGroupZIndex);
if (model.children) {
model.children.forEach(function (nodeId) {
var node = _this.lf.getNodeModelById(nodeId);
_this.toFrontGroup(node);
});
}
};
lf.register(GroupNode_1.default);
this.lf = lf;
lf.graphModel.addNodeMoveRules(function (model, deltaX, deltaY) {
if (model.isGroup) { // 如果移动的是分组,那么分组的子节点也跟着移动。
lf.graphModel.moveNodes(__spread(model.children), deltaX, deltaY, true);
var nodeIds = _this.getNodeAllChild(model);
lf.graphModel.moveNodes(nodeIds, deltaX, deltaY, true);
return true;
}
var groupModel = lf.getNodeModelById(_this.nodeGroupMap.get(model.id));
@@ -114,24 +153,47 @@ var Group = /** @class */ (function () {
return true;
});
lf.graphModel.group = this;
lf.on('node:add', this.appendNodeToGrop);
lf.on('node:add,node:drop', this.appendNodeToGroup);
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('node:dnd-drag,node:drag', this.setActiveGroup);
lf.on('node:click', this.nodeSelected);
lf.on('graph:rendered', this.graphRendered);
}
/**
* 获取自定位置其所属分组
* 获取一个节点内部所有的子节点,包裹分组的子节点
*/
Group.prototype.getGroup = function (bounds) {
Group.prototype.getNodeAllChild = function (model) {
var _this = this;
var nodeIds = [];
if (model.children) {
model.children.forEach(function (nodeId) {
nodeIds.push(nodeId);
var nodeModel = _this.lf.getNodeModelById(nodeId);
if (nodeModel.isGroup) {
nodeIds = nodeIds.concat(_this.getNodeAllChild(nodeModel));
}
});
}
return nodeIds;
};
/**
* 获取自定位置其所属分组
* 当分组重合时,优先返回最上层的分组
*/
Group.prototype.getGroup = function (bounds, nodeData) {
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;
var groups = nodes.filter(function (node) { return node.isGroup && node.isInRange(bounds) && node.id !== nodeData.id; });
if (groups.length === 0)
return;
if (groups.length === 1)
return groups[0];
var topGroup = groups[groups.length - 1];
for (var i = groups.length - 2; i >= 0; i--) {
if (groups[i].zIndex > topGroup.zIndex) {
topGroup = groups[i];
}
}
return topGroup;
};
/**
* 获取某个节点所属的groupModel
@@ -4,37 +4,27 @@
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Snapshot = void 0;
var Snapshot = {
pluginName: 'snapshot',
install: function (lf) {
var Snapshot = /** @class */ (function () {
function Snapshot(_a) {
var _this = this;
var lf = _a.lf;
this.lf = lf;
this.customCssRules = '';
this.useGlobalRules = true;
/* 下载快照 */
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);
_this.getSnapshot(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);
};
lf.getSnapshotBlob = function (backgroundColor) { return _this.getSnapshotBlob(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);
};
},
lf.getSnapshotBase64 = function (backgroundColor) { return _this.getSnapshotBase64(backgroundColor); };
}
/* 获取svgRoot对象 */
getSvgRootElement: function (lf) {
Snapshot.prototype.getSvgRootElement = function (lf) {
var _this = this;
this.offsetX = Number.MAX_SAFE_INTEGER;
this.offsetY = Number.MAX_SAFE_INTEGER;
lf.graphModel.nodes.forEach(function (item) {
var x = item.x, width = item.width, y = item.y, height = item.height;
var offsetX = x - width / 2;
@@ -61,8 +51,8 @@ var Snapshot = {
});
var svgRootElement = lf.container.querySelector('.lf-canvas-overlay');
return svgRootElement;
},
triggerDownload: function (imgURI) {
};
Snapshot.prototype.triggerDownload = function (imgURI) {
var evt = new MouseEvent('click', {
view: window,
bubbles: false,
@@ -73,8 +63,8 @@ var Snapshot = {
a.setAttribute('href', imgURI);
a.setAttribute('target', '_blank');
a.dispatchEvent(evt);
},
removeAnchor: function (element) {
};
Snapshot.prototype.removeAnchor = function (element) {
var childNodes = element.childNodes;
var childLength = element.childNodes && element.childNodes.length;
for (var i = 0; i < childLength; i++) {
@@ -86,20 +76,22 @@ var Snapshot = {
i--;
}
}
},
};
/* 下载图片 */
downloadSvg: function (svg, fileName, backgroundColor) {
Snapshot.prototype.getSnapshot = function (fileName, backgroundColor) {
var _this = this;
this.fileName = fileName || "logic-flow." + Date.now() + ".png";
var svg = this.getSvgRootElement(this.lf);
this.getCanvasData(svg, backgroundColor).then(function (canvas) {
var imgURI = canvas
.toDataURL('image/png')
var imgURI = canvas.toDataURL('image/png')
.replace('image/png', 'image/octet-stream');
_this.triggerDownload(imgURI, fileName);
_this.triggerDownload(imgURI);
});
},
};
/* 获取base64对象 */
getBase64: function (svg, backgroundColor) {
Snapshot.prototype.getSnapshotBase64 = function (backgroundColor) {
var _this = this;
var svg = this.getSvgRootElement(this.lf);
return new Promise(function (resolve) {
_this.getCanvasData(svg, backgroundColor).then(function (canvas) {
var base64 = canvas.toDataURL('image/png');
@@ -107,10 +99,11 @@ var Snapshot = {
resolve({ data: base64, width: canvas.width, height: canvas.height });
});
});
},
};
/* 获取Blob对象 */
getBlob: function (svg, backgroundColor) {
Snapshot.prototype.getSnapshotBlob = function (backgroundColor) {
var _this = this;
var svg = this.getSvgRootElement(this.lf);
return new Promise(function (resolve) {
_this.getCanvasData(svg, backgroundColor).then(function (canvas) {
canvas.toBlob(function (blob) {
@@ -119,20 +112,25 @@ var Snapshot = {
}, 'image/png');
});
});
},
getClassRules: function () {
};
Snapshot.prototype.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;
if (this.useGlobalRules) {
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;
}
}
}
if (this.customCssRules) {
rules += this.customCssRules;
}
return rules;
},
};
// 获取图片生成中中间产物canvas对象,用户转换为其他需要的格式
getCanvasData: function (svg, backgroundColor) {
Snapshot.prototype.getCanvasData = function (svg, backgroundColor) {
var _this = this;
var copy = svg.cloneNode(true);
var graph = copy.lastChild;
@@ -166,7 +164,7 @@ var Snapshot = {
真实dom存在缩放影响其宽高数值
在得到真实宽高后除以缩放比例即可得到正常宽高
*/
var base = document.getElementsByClassName('lf-base')[0];
var base = this.lf.graphModel.rootEl.querySelector('.lf-base');
var bbox = base.getBoundingClientRect();
var graphModel = this.lf.graphModel;
var transformModel = graphModel.transformModel;
@@ -204,12 +202,15 @@ var Snapshot = {
因为svg中存在dom存放在foreignObject元素中
SVG图形转成img对象
todo: 会导致一些清晰度问题这个需要再解决
fixme: XMLSerializer的中的css background url不会下载图片
*/
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;
});
},
};
};
Snapshot.pluginName = 'snapshot';
return Snapshot;
}());
exports.Snapshot = Snapshot;
exports.default = Snapshot;
@@ -10,17 +10,39 @@ var __assign = (this && this.__assign) || function () {
};
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboAdapter = exports.toLogicflowData = exports.toTurboData = void 0;
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";
exports.toLogicflowData = exports.toTurboData = void 0;
var TurboType = {
SEQUENCE_FLOW: 1,
START_EVENT: 2,
END_EVENT: 3,
USER_TASK: 4,
// SERVICE_TASK = 5, 暂不支持
TurboType[TurboType["EXCLUSIVE_GATEWAY"] = 6] = "EXCLUSIVE_GATEWAY";
})(TurboType || (TurboType = {}));
EXCLUSIVE_GATEWAY: 6,
};
var TurboTypeMap = {
1: 'bpmn:sequenceFlow',
2: 'bpmn:startEvent',
3: 'bpmn:endEvent',
4: 'bpmn:userTask',
6: 'bpmn:exclusiveGateway',
};
// 转换Turbo识别的类型
function getTurboType(type) {
switch (type) {
@@ -50,11 +72,11 @@ function convertNodeToTurboElement(node) {
type: getTurboType(node.type),
properties: __assign(__assign({}, properties), { name: (text && text.value) || '', x: x,
y: y,
text: text, logicFlowType: type }),
text: text }),
key: id,
};
}
// 将LogicFlow中的Eedg数据转换为Turbo元素数据
// 将LogicFlow中的Edge数据转换为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 {
@@ -62,10 +84,7 @@ function convertEdgeToTurboElement(edge) {
outgoing: [targetNodeId],
type: getTurboType(type),
dockers: [],
properties: __assign(__assign({}, properties), { name: (text && text.value) || '', text: text,
startPoint: startPoint,
endPoint: endPoint,
pointsList: pointsList, logicFlowType: type }),
properties: __assign(__assign({}, properties), { name: (text && text.value) || '', text: text, startPoint: JSON.stringify(startPoint), endPoint: JSON.stringify(endPoint), pointsList: JSON.stringify(pointsList) }),
key: id,
};
}
@@ -91,23 +110,29 @@ function toTurboData(data) {
return turboData;
}
exports.toTurboData = toTurboData;
// 将Turbo元素数据转换为LogicFlow中的Eedg数据
// 将Turbo元素数据转换为LogicFlow中的Edge数据
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 incoming = element.incoming, outgoing = element.outgoing, properties = element.properties, key = element.key, type = element.type;
var text = properties.text, name = properties.name, startPoint = properties.startPoint, endPoint = properties.endPoint, pointsList = properties.pointsList;
var edge = {
id: key,
type: logicFlowType,
type: TurboTypeMap[type],
sourceNodeId: incoming[0],
targetNodeId: outgoing[0],
text: text,
startPoint: startPoint,
endPoint: endPoint,
pointsList: pointsList,
text: text || name,
properties: {},
};
if (startPoint) {
edge.startPoint = JSON.parse(startPoint);
}
if (endPoint) {
edge.endPoint = JSON.parse(endPoint);
}
if (pointsList) {
edge.pointsList = JSON.parse(pointsList);
}
// 这种转换方式,在自定义属性中不能与excludeProperties中的属性重名,否则将在转换过程中丢失
var excludeProperties = ['startPoint', 'endPoint', 'pointsList', 'text', 'logicFlowType'];
var excludeProperties = ['startPoint', 'endPoint', 'pointsList', 'text'];
Object.keys(element.properties).forEach(function (property) {
if (excludeProperties.indexOf(property) === -1) {
edge.properties[property] = element.properties[property];
@@ -117,18 +142,24 @@ function convertFlowElementToEdge(element) {
}
// 将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 properties = element.properties, key = element.key, type = element.type, bounds = element.bounds;
var x = properties.x, y = properties.y;
var text = properties.text;
if (x === undefined) {
var _a = __read(bounds, 2), _b = _a[0], x1 = _b.x, y1 = _b.y, _c = _a[1], x2 = _c.x, y2 = _c.y;
x = (x1 + x2) / 2;
y = (y1 + y2) / 2;
}
var node = {
id: key,
type: logicFlowType,
type: TurboTypeMap[type],
x: x,
y: y,
text: text,
properties: {},
};
// 这种转换方式,在自定义属性中不能与excludeProperties中的属性重名,否则将在转换过程中丢失
var excludeProperties = ['x', 'y', 'text', 'logicFlowType'];
var excludeProperties = ['x', 'y', 'text'];
Object.keys(element.properties).forEach(function (property) {
if (excludeProperties.indexOf(property) === -1) {
node.properties[property] = element.properties[property];
@@ -156,26 +187,23 @@ function toLogicflowData(data) {
return lfData;
}
exports.toLogicflowData = toLogicflowData;
var TurboAdapter = {
pluginName: 'turboAdapter',
install: function (lf) {
var TurboAdapter = /** @class */ (function () {
function TurboAdapter(_a) {
var lf = _a.lf;
lf.adapterIn = this.adapterIn;
lf.adapterOut = this.adapterOut;
},
shapeConfigMap: new Map(),
setCustomShape: function (key, val) {
this.shapeConfigMap.set(key, val);
},
adapterOut: function (logicflowData) {
}
TurboAdapter.prototype.adapterOut = function (logicflowData) {
if (logicflowData) {
return toTurboData(logicflowData);
}
},
adapterIn: function (turboData) {
};
TurboAdapter.prototype.adapterIn = function (turboData) {
if (turboData) {
return toLogicflowData(turboData);
}
},
};
exports.TurboAdapter = TurboAdapter;
};
TurboAdapter.pluginName = 'turboAdapter';
return TurboAdapter;
}());
exports.default = TurboAdapter;