更新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));