本地logicflow依赖包
This commit is contained in:
1 parent
8ff82208ad
commit
30f225df00
290 files changed
+18624
-16276
No files matched your search
@@ -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, };
|
||||
Reference in new issue
Block a user