更新logicflow包
This commit is contained in:
1 parent
e78ebb747d
commit
2583575725
113 files changed
+41211
-588
No files matched your search
@@ -98,10 +98,18 @@ declare class GroupNodeModel extends RectResize.model {
|
||||
};
|
||||
getData(): import("@logicflow/core").NodeData;
|
||||
getHistoryData(): import("@logicflow/core").NodeData;
|
||||
/**
|
||||
* 是否允许此节点添加到此分组中
|
||||
*/
|
||||
isAllowAppendIn(nodeData: any): boolean;
|
||||
/**
|
||||
* 当groupA被添加到groupB中时,将groupB及groupB所属的group的zIndex减1
|
||||
*/
|
||||
toBack(): void;
|
||||
}
|
||||
declare class GroupNode extends RectResize.view {
|
||||
getControlGroup(): h.JSX.Element;
|
||||
getAddedableShape(): import("preact").VNode<any>;
|
||||
getAddableShape(): import("preact").VNode<any>;
|
||||
getFoldIcon(): import("preact").VNode<any>;
|
||||
getResizeShape(): import("preact").VNode<any>;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import { h } from '@logicflow/core';
|
||||
import { RectResize } from '../../NodeResize';
|
||||
var defaultWidth = 500;
|
||||
var defaultHeight = 300;
|
||||
var DEFAULT_BOTTOM_Z_INDEX = -10000;
|
||||
var GroupNodeModel = /** @class */ (function (_super) {
|
||||
__extends(GroupNodeModel, _super);
|
||||
function GroupNodeModel() {
|
||||
@@ -68,8 +69,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;
|
||||
@@ -220,7 +220,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;
|
||||
};
|
||||
@@ -274,6 +274,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) { // 如果分组被折叠
|
||||
@@ -282,6 +283,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;
|
||||
}(RectResize.model));
|
||||
var GroupNode = /** @class */ (function (_super) {
|
||||
@@ -293,7 +306,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;
|
||||
@@ -339,7 +352,7 @@ var GroupNode = /** @class */ (function (_super) {
|
||||
};
|
||||
GroupNode.prototype.getResizeShape = function () {
|
||||
return h('g', {}, [
|
||||
this.getAddedableShape(),
|
||||
this.getAddableShape(),
|
||||
_super.prototype.getResizeShape.call(this),
|
||||
this.getFoldIcon(),
|
||||
]);
|
||||
|
||||
@@ -11,13 +11,18 @@ declare type Bounds = {
|
||||
declare class Group {
|
||||
static pluginName: string;
|
||||
lf: LogicFlow;
|
||||
topGroupZIndex: number;
|
||||
activeGroup: any;
|
||||
nodeGroupMap: Map<BaseNodeId, GroupId>;
|
||||
constructor({ lf }: {
|
||||
lf: any;
|
||||
});
|
||||
/**
|
||||
* 获取一个节点内部所有的子节点,包裹分组的子节点
|
||||
*/
|
||||
getNodeAllChild(model: any): any[];
|
||||
graphRendered: (data: any) => void;
|
||||
appendNodeToGrop: ({ data }: {
|
||||
appendNodeToGroup: ({ data }: {
|
||||
data: any;
|
||||
}) => void;
|
||||
deleteGroupChild: ({ data }: {
|
||||
@@ -27,9 +32,20 @@ declare class Group {
|
||||
data: any;
|
||||
}) => void;
|
||||
/**
|
||||
* 获取自定位置其所属分组
|
||||
* 1. 分组节点默认在普通节点下面。
|
||||
* 2. 分组节点被选中后,会将分组节点以及其内部的其他分组节点放到其余分组节点的上面。
|
||||
* 3. 分组节点取消选中后,不会将分组节点重置为原来的高度。
|
||||
* 4. 由于LogicFlow核心目标是支持用户手动绘制流程图,所以不考虑一张流程图超过1000个分组节点的情况。
|
||||
*/
|
||||
getGroup(bounds: Bounds): BaseNodeModel | undefined;
|
||||
nodeSelected: ({ data }: {
|
||||
data: any;
|
||||
}) => void;
|
||||
toFrontGroup: (model: any) => void;
|
||||
/**
|
||||
* 获取自定位置其所属分组
|
||||
* 当分组重合时,优先返回最上层的分组
|
||||
*/
|
||||
getGroup(bounds: Bounds, nodeData: BaseNodeModel): BaseNodeModel | undefined;
|
||||
/**
|
||||
* 获取某个节点所属的groupModel
|
||||
*/
|
||||
|
||||
@@ -1,28 +1,11 @@
|
||||
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 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) {
|
||||
// 如果节点
|
||||
@@ -36,7 +19,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);
|
||||
@@ -47,24 +30,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);
|
||||
@@ -75,25 +73,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);
|
||||
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));
|
||||
@@ -110,24 +149,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
|
||||
|
||||
Reference in new issue
Block a user