wetrade-design
Version:
一款多语言支持Vue3的UI框架
1,458 lines (1,451 loc) • 113 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Node = exports.Meta = exports.Link = void 0;
exports.appendDragNode = appendDragNode;
exports.appendNode = appendNode;
exports.cancelMerge = cancelMerge;
exports.changeNodeHeight = changeNodeHeight;
exports.changeNodeWidth = changeNodeWidth;
exports.checkMergeNodeList = checkMergeNodeList;
exports.cleanExtraLink = cleanExtraLink;
exports.containsAll = containsAll;
exports.deleteDragNodeAndLink = deleteDragNodeAndLink;
exports.deleteNode = deleteNode;
exports.disabledNodeDrag = disabledNodeDrag;
exports.editMerge = editMerge;
exports.findChildrenNodeList = findChildrenNodeList;
exports.findNodeByCoordinate = findNodeByCoordinate;
exports.getAllFinalNode = getAllFinalNode;
exports.getNodeIdActiveMap = getNodeIdActiveMap;
exports.hasErrorToolInLink = hasErrorToolInLink;
exports.initShrinkNode = initShrinkNode;
exports.insertNode = insertNode;
exports.isNodeInMerge = isNodeInMerge;
exports.lightenPath = lightenPath;
exports.mergeNode = mergeNode;
exports.shrinkOrExpandNode = shrinkOrExpandNode;
exports.updateDragNode = updateDragNode;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _index2 = require("./index");
var _lodash = _interopRequireDefault(require("lodash"));
var _types = require("./types");
// X轴的间距
var X_GAP = 140;
// Y轴的间距
var Y_GAP = 40;
// 拖拽占位的间距
var Y_DRAG_GAP = 12;
// 拖拽占位节点高度
var DRAG_NODE_HEIGHT = 16;
// 节点头部高度
var NODE_HEADER = 32;
// 合并x间距
var MERGE_X_GAP = 64;
var Meta = /*#__PURE__*/(0, _createClass2.default)(function Meta(_ref) {
var _ref$compare = _ref.compare,
compare = _ref$compare === void 0 ? null : _ref$compare,
_ref$configKey = _ref.configKey,
configKey = _ref$configKey === void 0 ? null : _ref$configKey,
_ref$configName = _ref.configName,
configName = _ref$configName === void 0 ? null : _ref$configName,
_ref$extParam = _ref.extParam,
extParam = _ref$extParam === void 0 ? null : _ref$extParam,
_ref$processorPrefix = _ref.processorPrefix,
processorPrefix = _ref$processorPrefix === void 0 ? null : _ref$processorPrefix,
_ref$reboundRetreatPr = _ref.reboundRetreatPriceDiff,
reboundRetreatPriceDiff = _ref$reboundRetreatPr === void 0 ? null : _ref$reboundRetreatPr,
_ref$regionType = _ref.regionType,
regionType = _ref$regionType === void 0 ? null : _ref$regionType,
_ref$stockRange = _ref.stockRange,
stockRange = _ref$stockRange === void 0 ? null : _ref$stockRange,
_ref$strategyPoints = _ref.strategyPoints,
strategyPoints = _ref$strategyPoints === void 0 ? null : _ref$strategyPoints,
_ref$targetBuySell = _ref.targetBuySell,
targetBuySell = _ref$targetBuySell === void 0 ? null : _ref$targetBuySell,
_ref$type = _ref.type,
type = _ref$type === void 0 ? null : _ref$type,
_ref$values = _ref.values,
values = _ref$values === void 0 ? null : _ref$values,
_ref$children = _ref.children,
children = _ref$children === void 0 ? [] : _ref$children,
_ref$mergeNode = _ref.mergeNode,
mergeNode = _ref$mergeNode === void 0 ? null : _ref$mergeNode,
_ref$preNode = _ref.preNode,
preNode = _ref$preNode === void 0 ? null : _ref$preNode,
_ref$buyAndSellType = _ref.buyAndSellType,
buyAndSellType = _ref$buyAndSellType === void 0 ? null : _ref$buyAndSellType;
(0, _classCallCheck2.default)(this, Meta);
this.compare = compare;
this.configKey = configKey;
this.configName = configName;
this.extParam = (0, _extends2.default)({
// 按钮后增加的线能否 【添加】
canAdd: true,
// 合并内判断是否有增加按钮
canInsert: true,
// 是否隐藏增加按钮
hiddenInsert: false,
// 是否标红
isError: false,
// 是否高亮
isHighLight: false,
// 是否为合并的特殊节点
isMergeNode: false,
// 是否展开
isOpen: true,
// 工具配置信息
configParams: null,
// 菜单选项是否被禁用
menuDisabled: false,
// 是否可拖拽
isDrag: false,
// 是否在拖拽中
isDragging: false,
// 工具是否校验通过
verifyStatus: false,
// 工具是否是编辑态
toolsIsEdit: false,
// 收起数量
shrinkNum: 0,
// 是否为拖拽占位元素
isDragElement: false,
// 是否可拖入,仅在合并内拖动有效
dropTop: true,
dropBottom: true,
errorStatus: null // 错误状态 1 条件错误 请重新选择
}, extParam);
this.processorPrefix = processorPrefix;
this.reboundRetreatPriceDiff = reboundRetreatPriceDiff;
this.regionType = regionType;
this.stockRange = stockRange;
this.strategyPoints = strategyPoints;
this.targetBuySell = targetBuySell;
this.type = type;
this.values = values;
this.children = children;
this.type = type;
this.mergeNode = mergeNode;
this.preNode = preNode;
this.buyAndSellType = buyAndSellType;
});
exports.Meta = Meta;
var Node = /*#__PURE__*/(0, _createClass2.default)(
// 宽度
// 高度
// 坐标
// meta
// // 前端存值
// extParam: any
// // 是否有添加按钮 默认为true
// canAdd: boolean;
// // 是否标红 默认为false
// isError: boolean;
// // 是否高亮 默认为false
// isHighLight: boolean;
function Node(_ref2) {
var _ref2$width = _ref2.width,
width = _ref2$width === void 0 ? 240 : _ref2$width,
_ref2$height = _ref2.height,
height = _ref2$height === void 0 ? 68 : _ref2$height,
_ref2$coordinate = _ref2.coordinate,
coordinate = _ref2$coordinate === void 0 ? [0, 0] : _ref2$coordinate,
_ref2$meta = _ref2.meta,
meta = _ref2$meta === void 0 ? new Meta({}) : _ref2$meta;
(0, _classCallCheck2.default)(this, Node);
(0, _defineProperty2.default)(this, "id", (0, _index2.uuid)());
this.width = width;
this.height = height;
this.coordinate = coordinate;
this.meta = new Meta(meta);
});
exports.Node = Node;
var Link = /*#__PURE__*/(0, _createClass2.default)(
// // 是否有添加按钮 默认为true
// canAdd: boolean;
// // 是否展开 默认为true
// isOpen: boolean;
// // 合并线路点击同时高亮标记id 默认为-1
// activeId: number;
// // 是否高亮 默认为false
// isHighLight: boolean;
function Link(_ref3) {
var startId = _ref3.startId,
endId = _ref3.endId,
_ref3$startAt = _ref3.startAt,
startAt = _ref3$startAt === void 0 ? [240, 50] : _ref3$startAt,
_ref3$endAt = _ref3.endAt,
endAt = _ref3$endAt === void 0 ? [0, 50] : _ref3$endAt,
_ref3$meta = _ref3.meta,
meta = _ref3$meta === void 0 ? null : _ref3$meta;
(0, _classCallCheck2.default)(this, Link);
(0, _defineProperty2.default)(this, "id", (0, _index2.uuid)());
this.startId = startId;
this.endId = endId;
this.startAt = startAt;
this.endAt = endAt;
this.meta = (0, _extends2.default)({
canAdd: true,
dropTop: true,
isOpen: false,
activeId: -1,
isHighLight: false,
// 途径点
stationPoint: []
}, meta);
}); // targetArr 是否为 Arr 的子集 true-是 false-否
exports.Link = Link;
function containsAll(arr, targetArr) {
var result = targetArr.every(function (item) {
return arr.includes(item);
});
return result;
}
// 二维数组去重
function drop2DArrayDuplicate(arr) {
var result = _lodash.default.uniqWith(arr, _lodash.default.isEqual);
return result;
}
// 判断节点是否在 合并中
function isNodeInMerge(_ref4) {
var nodeId = _ref4.nodeId,
modelPathList = _ref4.modelPathList,
nodeList = _ref4.nodeList;
var childrenList = findChildrenNodeList({
nodeId: nodeId,
modelPathList: modelPathList,
nodeList: nodeList
});
var childrenIds = childrenList.map(function (item) {
return item.id;
});
var otherPathList = modelPathList.filter(function (item) {
return !item.includes(nodeId);
});
var flag = false;
for (var index = 0; index < otherPathList.length && !flag; index++) {
var path = otherPathList[index];
// 取交集
var intersectionNodeIds = _lodash.default.intersectionWith(childrenIds, path, _lodash.default.isEqual);
if (intersectionNodeIds.length) {
flag = true;
}
}
return flag;
}
// 判断节点所在链路后面中是否有工具为编辑态或错误
function hasErrorToolInLink(_ref5) {
var nodeId = _ref5.nodeId,
modelPathList = _ref5.modelPathList,
nodeList = _ref5.nodeList;
var _iterator = (0, _createForOfIteratorHelper2.default)(modelPathList),
_step;
try {
var _loop = function _loop() {
var item = _step.value;
if (item.includes(nodeId)) {
var _nodeList$inAllIndex, _curNodeMeta$extParam;
var findIndex = item.findIndex(function (ele) {
return ele === nodeId;
});
var inAllIndex = nodeList.findIndex(function (ele) {
return ele.id === nodeId;
});
var afterList = item.slice(findIndex);
var list = nodeList.filter(function (ele) {
return afterList.includes(ele.id);
});
var curNodeMeta = (_nodeList$inAllIndex = nodeList[inAllIndex]) === null || _nodeList$inAllIndex === void 0 ? void 0 : _nodeList$inAllIndex.meta;
var curNodeError = inAllIndex > -1 && (curNodeMeta === null || curNodeMeta === void 0 ? void 0 : curNodeMeta.type) === _types.TreeNodeType.TOOLS && (!curNodeMeta.configName || ((_curNodeMeta$extParam = curNodeMeta.extParam) === null || _curNodeMeta$extParam === void 0 ? void 0 : _curNodeMeta$extParam.toolsIsEdit));
var has = list.some(function (node) {
return node.meta.type === _types.TreeNodeType.TOOLS && (!node.meta.configName || node.meta.extParam.toolsIsEdit);
}) && !curNodeError;
if (has) {
return {
v: true
};
}
}
};
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _ret = _loop();
if ((0, _typeof2.default)(_ret) === "object") return _ret.v;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return false;
}
// 根据id 获取节点
function findNodeById(_ref6) {
var nodeId = _ref6.nodeId,
nodeList = _ref6.nodeList;
var node = nodeList.find(function (node) {
return node.id === nodeId;
});
return node || null;
}
// 根据id 获取线路
function findLinkById(_ref7) {
var linkId = _ref7.linkId,
linkList = _ref7.linkList;
var link = linkList.find(function (link) {
return link.id === linkId;
});
return link || null;
}
// 根据线路 获取节点
function findNodeByLink(_ref8) {
var link = _ref8.link,
nodeList = _ref8.nodeList;
return {
start: findNodeById({
nodeId: link.startId,
nodeList: nodeList
}),
end: findNodeById({
nodeId: link.endId,
nodeList: nodeList
})
};
}
// 遍历nodeList根据nodeId,找到startId对应的其中一条link,将该link的activeId与nodeId映射
function getNodeIdActiveMap(_ref9) {
var nodeList = _ref9.nodeList,
linkList = _ref9.linkList;
var map = new Map();
nodeList.forEach(function (node) {
var _link$meta$activeId, _link$meta;
var link = findLinkByStartId({
nodeId: node.id,
linkList: linkList
});
var activeId = (_link$meta$activeId = link === null || link === void 0 ? void 0 : (_link$meta = link.meta) === null || _link$meta === void 0 ? void 0 : _link$meta.activeId) !== null && _link$meta$activeId !== void 0 ? _link$meta$activeId : -1;
map.set(node.id, activeId);
});
return map;
}
/**
* 设置高亮路径
* @param param0
*/
function lightenPath(_ref10) {
var nodeIds = _ref10.nodeIds,
nodeList = _ref10.nodeList,
linkList = _ref10.linkList;
// 设置高亮节点
var lightenNodeList = nodeIds.map(function (nodeId) {
return (0, _objectSpread2.default)({}, findNodeById({
nodeId: nodeId,
nodeList: nodeList
}));
});
lightenNodeList.forEach(function (node) {
node.meta && (node.meta.isHighLight = true);
});
// 设置高亮连线
var endLinkList = linkList.filter(function (link) {
return !!findNodeById({
nodeId: link.endId,
nodeList: lightenNodeList
});
});
var lightenLinkList = endLinkList.filter(function (link) {
return !!findNodeById({
nodeId: link.startId,
nodeList: lightenNodeList
});
});
lightenLinkList.forEach(function (link) {
link.meta.isHighLight = true;
});
}
function findLinkByStartId(_ref11) {
var nodeId = _ref11.nodeId,
linkList = _ref11.linkList;
var link = linkList.find(function (link) {
return link.startId === nodeId;
});
return link || null;
}
// 根据结束id 获取第一个线路
function findLinkByEndId(_ref12) {
var nodeId = _ref12.nodeId,
linkList = _ref12.linkList;
var link = linkList.find(function (link) {
return link.endId === nodeId;
});
return link || null;
}
// 删除多余的 线路
function cleanExtraLink(_ref13) {
var nodeList = _ref13.nodeList,
linkList = _ref13.linkList;
var nodeIdList = nodeList.map(function (item) {
return item.id;
});
for (var i = linkList.length - 1; i >= 0; i--) {
var _nodeObj$start, _nodeObj$end;
var link = linkList[i];
var nodeObj = findNodeByLink({
link: link,
nodeList: nodeList
});
var startFlag = nodeIdList.includes((_nodeObj$start = nodeObj.start) === null || _nodeObj$start === void 0 ? void 0 : _nodeObj$start.id);
var endFlag = nodeIdList.includes((_nodeObj$end = nodeObj.end) === null || _nodeObj$end === void 0 ? void 0 : _nodeObj$end.id);
if (!startFlag || !endFlag) {
// 若 线路 任意一端不存在,则删除线路
linkList.splice(i, 1);
}
}
}
// 获取 所有终点节点数据(y值升序)
function getAllFinalNode(_ref14) {
var nodeList = _ref14.nodeList,
modelPathList = _ref14.modelPathList;
// 页面上展示的渲染节点
var renderNodeList = initShrinkNode({
modelPathList: modelPathList,
nodeList: nodeList
});
if (renderNodeList.length <= 1) {
// 仅有起始节点
return renderNodeList;
}
// 收起的node集合
var shrinkNodes = nodeList.reduce(function (prev, cur) {
if (!cur.meta.extParam.isOpen) {
return [].concat((0, _toConsumableArray2.default)(prev), [cur.id]);
}
return prev;
}, []);
// 渲染链路
var renderPathList = modelPathList.map(function (item) {
if (item.every(function (ele) {
return !shrinkNodes.includes(ele);
})) {
// 不经过该节点,则不处理
return item;
} else {
// 经过该节点,则截取该节点前的数据
var index = item.findIndex(function (nodeId) {
return shrinkNodes.includes(nodeId);
});
return item.slice(0, index + 1);
}
});
var finalIdList = [];
renderPathList.forEach(function (path) {
finalIdList.push(path[path.length - 1]);
});
finalIdList = Array.from(new Set(finalIdList));
var finalNodeList = finalIdList.map(function (id) {
return findNodeById({
nodeId: id,
nodeList: renderNodeList
});
});
finalNodeList.sort(function (a, b) {
return (a === null || a === void 0 ? void 0 : a.coordinate[1]) - (b === null || b === void 0 ? void 0 : b.coordinate[1]);
});
return finalNodeList;
}
// 判断 合并的数组存在不相邻或非尾部节点 true-校验通过 false-校验失败
function checkMergeNodeList(_ref15) {
var mergeNodeList = _ref15.mergeNodeList,
nodeList = _ref15.nodeList,
modelPathList = _ref15.modelPathList;
if (mergeNodeList.length <= 1) {
return;
}
var allFinalNodeList = getAllFinalNode({
nodeList: nodeList,
modelPathList: modelPathList
});
var allFinalNodeIds = allFinalNodeList.map(function (node) {
return node.id;
});
var flag = true;
var mergeIndexList = [];
mergeNodeList.forEach(function (node) {
if (!allFinalNodeIds.includes(node.id)) {
flag = false;
}
var index = allFinalNodeIds.findIndex(function (item) {
return item === node.id;
});
mergeIndexList.push(index);
});
mergeIndexList.sort(function (a, b) {
return a - b;
});
for (var i = 0; i < mergeIndexList.length - 1; i++) {
var curIndex = mergeIndexList[i];
var nextIndex = mergeIndexList[i + 1];
if (nextIndex - curIndex > 1) {
flag = false;
break;
}
}
return flag;
}
/**
* @Description: 查询子孙节点数组(包括自身)
* @param {*} param1
* @return {*}
*/
function findChildrenNodeList(_ref16) {
var nodeId = _ref16.nodeId,
modelPathList = _ref16.modelPathList,
nodeList = _ref16.nodeList;
var list = [];
modelPathList.forEach(function (path) {
if (path.includes(nodeId)) {
// 当前节点所在的位置
var index = path.findIndex(function (id) {
return id === nodeId;
});
var sonList = path.slice(index, path.length);
list.push.apply(list, (0, _toConsumableArray2.default)(sonList));
}
});
if (!list.length) {
return [];
}
var ids = Array.from(new Set(list));
return nodeList.filter(function (node) {
return ids.includes(node.id);
});
}
/**
* @Description: 获取nodeList中 最底部的y值
* @param {*} nodeList
* @return {*}
*/
function calcMaxY(nodeList) {
var maxYTop = 0;
var maxYBottom = 0;
nodeList.forEach(function (node) {
maxYTop = Math.max(maxYTop, node.coordinate[1]);
maxYBottom = Math.max(maxYBottom, node.height + node.coordinate[1]);
});
return {
top: maxYTop,
bottom: maxYBottom
};
}
// 找到 传入的 modelPathList 最上方的链路
function findTopPathFromPathList(_ref17) {
var modelPathList = _ref17.modelPathList,
nodeList = _ref17.nodeList;
if (!modelPathList.length) return [];
if (modelPathList.length === 1) return modelPathList[0];
var result = modelPathList[0];
var _loop2 = function _loop2() {
var intersectionNodeIds = _lodash.default.intersectionWith(modelPathList[i], result, _lodash.default.isEqual);
var list1 = result.filter(function (item) {
return !intersectionNodeIds.includes(item);
});
var list2 = modelPathList[i].filter(function (item) {
return !intersectionNodeIds.includes(item);
});
var min1 = list1.reduce(function (min, cur) {
var node = findNodeById({
nodeId: cur,
nodeList: nodeList
});
var y = node.coordinate[1];
return Math.min(min, y);
}, 0);
var min2 = list2.reduce(function (min, cur) {
var node = findNodeById({
nodeId: cur,
nodeList: nodeList
});
var y = node.coordinate[1];
return Math.min(min, y);
}, 0);
if (min2 > min1) {
result = modelPathList[i];
}
};
for (var i = 1; i < modelPathList.length; i++) {
_loop2();
}
return result;
}
// 找到 传入的 modelPathList 最下方的链路
function findBottomPathFromPathList(_ref18) {
var modelPathList = _ref18.modelPathList,
nodeList = _ref18.nodeList;
if (!modelPathList.length) return [];
if (modelPathList.length === 1) return modelPathList[0];
var result = modelPathList[0];
var _loop3 = function _loop3() {
var intersectionNodeIds = _lodash.default.intersectionWith(modelPathList[i], result, _lodash.default.isEqual);
var list1 = result.filter(function (item) {
return !intersectionNodeIds.includes(item);
});
var list2 = modelPathList[i].filter(function (item) {
return !intersectionNodeIds.includes(item);
});
var max1 = list1.reduce(function (max, cur) {
var node = findNodeById({
nodeId: cur,
nodeList: nodeList
});
var y = node.coordinate[1];
return Math.max(max, y);
}, 0);
var max2 = list2.reduce(function (max, cur) {
var node = findNodeById({
nodeId: cur,
nodeList: nodeList
});
var y = node.coordinate[1];
return Math.max(max, y);
}, 0);
if (max2 > max1) {
result = modelPathList[i];
}
};
for (var i = 1; i < modelPathList.length; i++) {
_loop3();
}
return result;
}
// 获取当前节点合并范围内的所有链路
// function findNodeMergePathList({ nodeId, modelPathList, nodeList, linkList, nextNodeActiveId }) {
// // const map = getNodeIdActiveMap({ nodeList, linkList })
// const nodeIdActiveMap = getNodeIdActiveMap({ nodeList, linkList });
// const map = new Map();
// modelPathList.forEach(item => {
// // 倒序遍历
// for (let i = item.length - 1; i >= 0; i--) {
// const activeId = nodeIdActiveMap.get(item[i]) || -1;
// if (activeId !== -1) {
// if (map.has(activeId)) {
// map.set(activeId, Array.from(new Set([...map.get(activeId), ...item])));
// } else {
// map.set(activeId, [...item]);
// }
// break;
// }
// }
// });
// console.log('map', map)
// }
/**
* @Description: 插入(增加)节点
* @param {number} id
* @param {any[]} modelPathList
* @param {any[]} nodeList
* @param {any[]} linkList
* @return {void}
*/
function insertNode(_ref19) {
var _node$meta, _node$meta$extParam, _node$meta2, _node$meta2$extParam, _node$meta3, _node$meta3$extParam;
var nodeId = _ref19.nodeId,
modelPathList = _ref19.modelPathList,
nodeList = _ref19.nodeList,
linkList = _ref19.linkList,
_ref19$width = _ref19.width,
width = _ref19$width === void 0 ? 240 : _ref19$width,
_ref19$height = _ref19.height,
height = _ref19$height === void 0 ? 68 : _ref19$height,
_ref19$meta = _ref19.meta,
meta = _ref19$meta === void 0 ? new Meta({}) : _ref19$meta;
var childrenList = findChildrenNodeList({
nodeId: nodeId,
modelPathList: modelPathList,
nodeList: nodeList
});
var node = findNodeById({
nodeId: nodeId,
nodeList: nodeList
});
// 处理 节点
var newX = X_GAP + node.width + node.coordinate[0];
var isMergeNode = (_node$meta = node.meta) === null || _node$meta === void 0 ? void 0 : (_node$meta$extParam = _node$meta.extParam) === null || _node$meta$extParam === void 0 ? void 0 : _node$meta$extParam.isMergeNode;
var newY = isMergeNode ? node.coordinate[1] - NODE_HEADER / 2 : node.coordinate[1];
var newNode = new Node({
width: width,
height: height,
coordinate: [newX, newY],
meta: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, meta), {}, {
extParam: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, meta.extParam), {}, {
dropTop: (_node$meta2 = node.meta) === null || _node$meta2 === void 0 ? void 0 : (_node$meta2$extParam = _node$meta2.extParam) === null || _node$meta2$extParam === void 0 ? void 0 : _node$meta2$extParam.dropTop,
canAdd: (_node$meta3 = node.meta) === null || _node$meta3 === void 0 ? void 0 : (_node$meta3$extParam = _node$meta3.extParam) === null || _node$meta3$extParam === void 0 ? void 0 : _node$meta3$extParam.canAdd
})
})
});
/** 偏移y轴 START */
// y坐标大于nodeId.y 的node集合
var otherUpperNodeList = nodeList.filter(function (item) {
var _item$meta;
return item.coordinate[1] <= node.coordinate[1] && (item === null || item === void 0 ? void 0 : (_item$meta = item.meta) === null || _item$meta === void 0 ? void 0 : _item$meta.configKey) !== 'start_node';
});
// nodeY1 为 otherUpperNodeList 中 y+height 最大值
var nodeY1Max = 0;
otherUpperNodeList.forEach(function (item) {
if (item.coordinate[1] + item.height > nodeY1Max) {
nodeY1Max = item.coordinate[1] + item.height;
}
});
if (nodeY1Max > 0) {
var offsetY = newNode.coordinate[1] + height - nodeY1Max;
if (offsetY > 0) {
nodeList.forEach(function (item) {
// if (item.meta?.extParam?.isMergeNode) {
// if (item.coordinate[1] - NODE_HEADER / 2 > node.coordinate[1]) {
// item.coordinate[1] += offsetY;
// }
// } else {
// if (item.coordinate[1] > node.coordinate[1]) {
// item.coordinate[1] += offsetY;
// }
// }
if (item.coordinate[1] > node.coordinate[1] + NODE_HEADER / 2) {
item.coordinate[1] += offsetY;
}
});
}
}
/** 偏移x轴 START */
// 需要偏移的节点集合
var needOffsetNodeList = [];
// 子孙节点中的合并节点集合
var childrenNodeListOfMerge = childrenList.filter(function (item) {
var _item$meta2, _item$meta2$extParam;
return ((_item$meta2 = item.meta) === null || _item$meta2 === void 0 ? void 0 : (_item$meta2$extParam = _item$meta2.extParam) === null || _item$meta2$extParam === void 0 ? void 0 : _item$meta2$extParam.isMergeNode) && item.id !== nodeId;
});
// 子孙节点中的合并节点id集合
var childrenIdsOfMerge = childrenNodeListOfMerge.map(function (item) {
return item.id;
});
// 若子孙节点中无合并节点则所有子孙节点都需要向后偏移
if (!childrenIdsOfMerge.length) {
needOffsetNodeList = childrenList;
} else {
// 否则若路径了合并节点和当前节点的每条链路中,合并节点和前节点如果都有预留位置能装下新节点,那么该合并节点及它子孙节点无需向后偏移
// 途径当前节点、当前节点的子孙节点中的合并节点 的所有链路
var curNodeAndChildMergeNodePathList = modelPathList.filter(function (item) {
return item.includes(nodeId) && item.some(function (ele) {
return childrenIdsOfMerge.includes(ele);
});
});
// 需要过滤的合并子节点
var needFilterMergeNodeIdList = [];
var _iterator2 = (0, _createForOfIteratorHelper2.default)(childrenIdsOfMerge),
_step2;
try {
var _loop4 = function _loop4() {
var _childrenNodeListOfMe, _childrenNodeListOfMe2;
var id = _step2.value;
// 途径当前节点、当前子孙合并节点 的所有链路
var pathCurMergeNodePathList = curNodeAndChildMergeNodePathList.filter(function (item) {
return item.includes(id);
});
// 当前子孙合并节点的x
var curMergeNodeX = (_childrenNodeListOfMe = childrenNodeListOfMerge.find(function (item) {
return item.id === id;
})) === null || _childrenNodeListOfMe === void 0 ? void 0 : (_childrenNodeListOfMe2 = _childrenNodeListOfMe.coordinate) === null || _childrenNodeListOfMe2 === void 0 ? void 0 : _childrenNodeListOfMe2[0];
var sameNum = 0;
var _iterator4 = (0, _createForOfIteratorHelper2.default)(pathCurMergeNodePathList),
_step4;
try {
var _loop5 = function _loop5() {
var item = _step4.value;
// 当前子孙合并节点索引
var preNodeIndex = item.findIndex(function (ele) {
return ele === id;
}) - 1;
// 当前子孙合并节点id
var preNodeId = item[preNodeIndex];
// 如果每条链路中的子孙合并节点和前以一个节点的预留位置能装下新节点,则记录该合并节点
if (curMergeNodeX - (childrenList.find(function (ele) {
return ele.id === preNodeId;
}).coordinate[0] + childrenList.find(function (ele) {
return ele.id === preNodeId;
}).width) > X_GAP + newNode.width) {
sameNum++;
}
};
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
_loop5();
}
} catch (err) {
_iterator4.e(err);
} finally {
_iterator4.f();
}
if (sameNum === pathCurMergeNodePathList.length && sameNum !== 0) {
needFilterMergeNodeIdList.push(id);
}
};
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
_loop4();
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
if (!needFilterMergeNodeIdList.length) {
needOffsetNodeList = childrenList;
} else {
// 需要过滤的合并子节点的子孙节点
var needFilterMergeNodeChildrenIds = [];
var _iterator3 = (0, _createForOfIteratorHelper2.default)(needFilterMergeNodeIdList),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var item = _step3.value;
var list = findChildrenNodeList({
nodeId: item,
modelPathList: modelPathList,
nodeList: nodeList
});
needFilterMergeNodeChildrenIds.push.apply(needFilterMergeNodeChildrenIds, (0, _toConsumableArray2.default)(list.map(function (ele) {
return ele.id;
})));
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
needOffsetNodeList = childrenList.filter(function (item) {
return !needFilterMergeNodeChildrenIds.includes(item.id);
});
}
}
needOffsetNodeList.forEach(function (childNode) {
if (childNode.id !== nodeId) {
// 自身节点无需向后偏移
childNode.coordinate[0] += X_GAP + newNode.width;
// (node.meta?.extParam?.isMergeNode ? X_GAP * 2 : X_GAP) + newNode.width;
}
});
/** 偏移x轴 END */
nodeList.push(newNode);
/** 偏移y轴 END */
var canAdd = node.meta.extParam.canAdd;
var dropTop = node.meta.extParam.dropTop;
// 处理 线路
var newLink = new Link({
startId: nodeId,
endId: newNode.id,
meta: {
canAdd: canAdd,
dropTop: dropTop
}
});
linkList.forEach(function (linkItem) {
if (linkItem.startId === nodeId) {
linkItem.startId = newNode.id;
linkItem.startAt[0] = 240;
}
});
linkList.push(newLink);
// 处理 链路
modelPathList.forEach(function (path) {
if (path.includes(nodeId)) {
// 当前节点所在的位置
var index = path.findIndex(function (id) {
return id === nodeId;
});
path.splice(index + 1, 0, newNode.id);
}
});
}
/**
* @Description: 添加 节点
* @param {*} linkId 点击添加的 线路id
* @param {*} modelPathList
* @param {*} nodeList
* @param {*} linkList
* @return {*}
*/
function appendNode(_ref20) {
var _link$meta$stationPoi, _link$meta2;
var linkId = _ref20.linkId,
modelPathList = _ref20.modelPathList,
nodeList = _ref20.nodeList,
linkList = _ref20.linkList,
_ref20$width = _ref20.width,
width = _ref20$width === void 0 ? 240 : _ref20$width,
_ref20$height = _ref20.height,
height = _ref20$height === void 0 ? 68 : _ref20$height,
_ref20$meta = _ref20.meta,
meta = _ref20$meta === void 0 ? new Meta({}) : _ref20$meta;
var link = findLinkById({
linkId: linkId,
linkList: linkList
});
var nodeObj = findNodeByLink({
link: link,
nodeList: nodeList
});
var endNode = nodeObj.end;
var startNode = nodeObj.start;
// 该节点的子孙节点(包括收起的)
var childrenList = findChildrenNodeList({
nodeId: endNode.id,
modelPathList: modelPathList,
nodeList: nodeList
});
// 页面上展示的渲染节点
var renderNodeList = initShrinkNode({
modelPathList: modelPathList,
nodeList: nodeList
});
// 该节点的子孙节点-不包括收起的
var renderChildrenList = findChildrenNodeList({
nodeId: endNode.id,
modelPathList: modelPathList,
nodeList: renderNodeList
});
// 在展示的子孙节点中找出y最大的
var newX = endNode.coordinate[0];
var maxY = calcMaxY(renderChildrenList);
var newY = Y_GAP + maxY.bottom;
var newNode = new Node({
width: width,
height: height,
coordinate: [newX, newY],
meta: meta
});
nodeList.forEach(function (nodeItem) {
// 子孙节点y不变,剩余节点中y比(展示的子孙节点中找出y最大的)大的增加偏移量
if (!childrenList.some(function (ele) {
return ele.id === nodeItem.id;
})) {
var _nodeItem$meta, _nodeItem$meta$extPar;
if ((_nodeItem$meta = nodeItem.meta) !== null && _nodeItem$meta !== void 0 && (_nodeItem$meta$extPar = _nodeItem$meta.extParam) !== null && _nodeItem$meta$extPar !== void 0 && _nodeItem$meta$extPar.isMergeNode) {
if (nodeItem.coordinate[1] - NODE_HEADER / 2 > maxY.top) {
nodeItem.coordinate[1] += Y_GAP + newNode.height;
}
} else {
if (nodeItem.coordinate[1] > maxY.top) {
nodeItem.coordinate[1] += Y_GAP + newNode.height;
}
}
}
});
nodeList.push(newNode);
// 处理 线路
var newLink = new Link({
startId: startNode.id,
endId: newNode.id,
meta: {
stationPoint: JSON.parse(JSON.stringify((_link$meta$stationPoi = (_link$meta2 = link.meta) === null || _link$meta2 === void 0 ? void 0 : _link$meta2.stationPoint) !== null && _link$meta$stationPoi !== void 0 ? _link$meta$stationPoi : []))
}
});
linkList.push(newLink);
// 处理 链路
var newPathList = [];
modelPathList.forEach(function (path) {
if (path.includes(startNode.id)) {
// 当前节点所在的位置
var index = path.findIndex(function (id) {
return id === startNode.id;
});
newPathList.push([].concat((0, _toConsumableArray2.default)(path.slice(0, index + 1)), [newNode.id]));
}
});
modelPathList.push.apply(modelPathList, newPathList);
// modelPathList 去重
modelPathList.splice.apply(modelPathList, [0, modelPathList.length].concat((0, _toConsumableArray2.default)(drop2DArrayDuplicate(modelPathList))));
}
/**
* @Description: 删除 节点
* @param {*} nodeId 被删除的 节点id
* @param {*} modelPathList
* @param {*} nodeList
* @param {*} linkList
* @return {*}
*/
function deleteNode(_ref21) {
var nodeId = _ref21.nodeId,
modelPathList = _ref21.modelPathList,
nodeList = _ref21.nodeList,
linkList = _ref21.linkList;
// 删除的节点是否在合并内
var isInMerge = isNodeInMerge({
nodeId: nodeId,
modelPathList: modelPathList,
nodeList: nodeList
});
var node = findNodeById({
nodeId: nodeId,
nodeList: nodeList
});
if (isInMerge) {
// 判断后一个节点是否是合并节点 && 前一个节点是否为fatherNode 不需要拼接link
var startLink = findLinkByStartId({
nodeId: nodeId,
linkList: linkList
});
var nextNodeActiveId = startLink.meta.activeId;
if (nextNodeActiveId !== -1) {
// if (node.meta.extParam.dropTop || node.meta.extParam.dropBottom) {
// findNodeMergePathList({nodeId, modelPathList, nodeList, linkList, nextNodeActiveId})
// }
// 找fatherNode
// 获取需要删除的链路集合(未处理链路前的)
var mergeNodeId = startLink.endId;
var tempNodeIds = [];
linkList.forEach(function (item) {
if (item.endId === mergeNodeId) {
tempNodeIds.push(item.startId);
}
});
// 经过合并节点的链路,截取合并节点其前面的链路集合(不含合并)
var tempAllTodoPath = [];
// 经过合并节点的链路,截取合并节点其后续的链路集合(不含合并)
var tempAllSubPath = [];
modelPathList.forEach(function (path) {
if (path.includes(mergeNodeId)) {
tempAllTodoPath.push(path.slice(0, path.findIndex(function (item) {
return mergeNodeId === item;
})));
}
if (path.includes(nodeId)) {
var _tempAllSubPath;
var mergeIndex = path.findIndex(function (item) {
return mergeNodeId === item;
});
(_tempAllSubPath = tempAllSubPath).push.apply(_tempAllSubPath, (0, _toConsumableArray2.default)(path.slice(mergeIndex + 1)));
}
});
tempAllSubPath = Array.from(new Set(tempAllSubPath));
var intersectionNodeIds = tempAllTodoPath[0];
for (var i = 1; i < tempAllTodoPath.length; i++) {
var path = tempAllTodoPath[i];
intersectionNodeIds = _lodash.default.intersectionWith(intersectionNodeIds, path, _lodash.default.isEqual);
}
// 上一个环节的起点
var fatherId = intersectionNodeIds[intersectionNodeIds.length - 1];
var deleteFlag = false;
var endLink = findLinkByEndId({
nodeId: nodeId,
linkList: linkList
});
modelPathList.forEach(function (path) {
var _arr = _lodash.default.intersectionWith(tempAllSubPath, path, _lodash.default.isEqual);
// 不经过前一个节点 && 与后续节点有交集(经过后续节点)
if (path.includes(endLink.startId) && !path.includes(nodeId) && _arr.length) {
deleteFlag = true;
}
});
if (deleteFlag) {
// 需要判断当前合并有多少个节点
var mergeLink = linkList.filter(function (item) {
return item.meta.activeId === nextNodeActiveId;
});
// 删除 当前节点,前后连线,链路
// 删除link,node,modelPath, 不需要拼接link
linkList.splice(linkList.findIndex(function (item) {
return item.id === startLink.id;
}), 1);
linkList.splice(linkList.findIndex(function (item) {
return item.id === endLink.id;
}), 1);
// 删除node
nodeList.splice(nodeList.findIndex(function (item) {
return item.id === nodeId;
}), 1);
// 更改modelPath
modelPathList.forEach(function (path) {
var pathIndex = path.findIndex(function (item) {
return item === nodeId;
});
if (pathIndex !== -1) {
path.splice(pathIndex);
}
});
if (mergeLink.length === 2) {
// 需要把合并节点也删除
// deleteNode({ nodeId: mergeLink[0].endId, modelPathList, nodeList, linkList });
// mergeLink中startId!==nodeId的另一条删除,找到合并后的另一条线,接过去,把合并节点删除
var otherLink = mergeLink.find(function (item) {
return item.startId !== nodeId;
});
var tempArr = findChildrenNodeList({
nodeId: otherLink.endId,
modelPathList: modelPathList,
nodeList: nodeList
});
tempArr.forEach(function (item) {
item.coordinate[0] -= MERGE_X_GAP / 2;
});
// 删除 mergeNode
nodeList.splice(nodeList.findIndex(function (item) {
return item.id === otherLink.endId;
}), 1);
linkList.splice(linkList.findIndex(function (item) {
return item.id === otherLink.id;
}), 1);
// 拼接link
linkList.forEach(function (item) {
if (item.startId === otherLink.endId) {
item.startId = otherLink.startId;
item.startAt = [240, 50];
}
});
// 更改modelPath
modelPathList.forEach(function (path) {
var pathIndex = path.findIndex(function (item) {
return item === otherLink.endId;
});
if (pathIndex !== -1) {
path.splice(pathIndex, 1);
}
});
// 偏移节点 mergeNode后的节点 ??
}
// 将只剩下的起始节点的链路全部删除
for (var _i = modelPathList.length - 1; _i >= 0; _i--) {
var _path = modelPathList[_i];
if (_path.length <= 1) {
modelPathList.splice(_i, 1);
}
}
modelPathList.splice.apply(modelPathList, [0, modelPathList.length].concat((0, _toConsumableArray2.default)(drop2DArrayDuplicate(modelPathList))));
} else {
if (endLink.startId === fatherId) {
var mergeNodeList = linkList.filter(function (item) {
return item.meta.activeId === nextNodeActiveId;
});
if (mergeNodeList.length === 2) {
cancelMerge({
selectLinkList: mergeNodeList,
nodeList: nodeList,
linkList: linkList,
modelPathList: modelPathList
});
deleteNode({
nodeId: nodeId,
modelPathList: modelPathList,
nodeList: nodeList,
linkList: linkList
});
} else {
// 删除link,node,modelPath, 不需要拼接link
linkList.splice(linkList.findIndex(function (item) {
return item.id === startLink.id;
}), 1);
linkList.splice(linkList.findIndex(function (item) {
return item.id === endLink.id;
}), 1);
// 删除node
nodeList.splice(nodeList.findIndex(function (item) {
return item.id === nodeId;
}), 1);
// 更改modelPath
modelPathList.forEach(function (path) {
var pathIndex = path.findIndex(function (item) {
return item === nodeId;
});
if (pathIndex !== -1) {
path.splice(pathIndex);
}
});
// 将只剩下的起始节点的链路全部删除
for (var _i2 = modelPathList.length - 1; _i2 >= 0; _i2--) {
var _path2 = modelPathList[_i2];
if (_path2.length <= 1) {
modelPathList.splice(_i2, 1);
}
}
modelPathList.splice.apply(modelPathList, [0, modelPathList.length].concat((0, _toConsumableArray2.default)(drop2DArrayDuplicate(modelPathList))));
}
} else {
// 删除link,拼接link
var allNextLink = [];
linkList.forEach(function (item) {
if (item.startId === nodeId) {
allNextLink.push(item);
}
});
var _endLink = findLinkByEndId({
nodeId: node.id,
linkList: linkList
});
var prevNodeId = _endLink.startId;
allNextLink.forEach(function (item) {
var _item$meta3, _item$meta3$stationPo, _item$meta4, _item$meta4$stationPo;
var endNode = findNodeById({
nodeId: item.endId,
nodeList: nodeList
});
(_item$meta3 = item.meta) === null || _item$meta3 === void 0 ? void 0 : (_item$meta3$stationPo = _item$meta3.stationPoint) === null || _item$meta3$stationPo === void 0 ? void 0 : _item$meta3$stationPo.push([endNode.coordinate[0] - node.coordinate[0], endNode.coordinate[1] - (node.coordinate[1] + NODE_HEADER / 2)
// endNode.coordinate[1],
]);
(_item$meta4 = item.meta) === null || _item$meta4 === void 0 ? void 0 : (_item$meta4$stationPo = _item$meta4.stationPoint) === null || _item$meta4$stationPo === void 0 ? void 0 : _item$meta4$stationPo.sort(function (a, b) {
return a[0] - b[0];
});
item.startId = prevNodeId;
});
var linkIndex = linkList.findIndex(function (item) {
return item.id === _endLink.id;
});
linkList.splice(linkIndex, 1);
// 删除node
nodeList.splice(nodeList.findIndex(function (item) {
return item.id === nodeId;
}), 1);
// 更改modelPath
modelPathList.forEach(function (path) {
var pathIndex = path.findIndex(function (item) {
return item === nodeId;
});
if (pathIndex !== -1) {
path.splice(pathIndex, 1);
}
});
modelPathList.splice.apply(modelPathList, [0, modelPathList.length].concat((0, _toConsumableArray2.default)(drop2DArrayDuplicate(modelPathList))));
}
}
} else {
// 删除link
var _allNextLink = [];
linkList.forEach(function (item) {
if (item.startId === nodeId) {
_allNextLink.push(item);
}
});
var _endLink2 = findLinkByEndId({
nodeId: node.id,
linkList: linkList
});
var _prevNodeId = _endLink2.startId;
_allNextLink.forEach(function (item) {
var _item$meta5, _item$meta5$stationPo, _item$meta6, _item$meta6$stationPo;
var endNode = findNodeById({
nodeId: item.endId,
nodeList: nodeList
});
(_item$meta5 = item.meta) === null || _item$meta5 === void 0 ? void 0 : (_item$meta5$stationPo = _item$meta5.stationPoint) === null || _item$meta5$stationPo === void 0 ? void 0 : _item$meta5$stationPo.push([endNode.coordinate[0] - node.coordinate[0], 0
// endNode.coordinate[1] - node.coordinate[1],
]);
(_item$meta6 = item.meta) === null || _item$meta6 === void 0 ? void 0 : (_item$meta6$stationPo = _item$meta6.stationPoint) === null || _item$meta6$stationPo === void 0 ? void 0 : _item$meta6$stationPo.sort(function (a, b) {
return a[0] - b[0];
});
item.startId = _prevNodeId;
});
var _linkIndex = linkList.findIndex(function (item) {
return item.id === _endLink2.id;
});
linkList.splice(_linkIndex, 1);
// 更改modelPathList
modelPathList.forEach(function (path) {
var pathIndex = path.findIndex(function (item) {
return item === nodeId;
});
if (pathIndex !== -1) {
path.splice(pathIndex, 1);
}
});
modelPathList.splice.apply(modelPathList, [0, modelPathList.length].concat((0, _toConsumableArray2.default)(drop2DArrayDuplicate(modelPathList))));
}
} else {
// 判断有无后续节点
var allNextNodeIds = [];
var _allNextLink2 = [];
linkList.forEach(function (item) {
if (item.startId === nodeId) {
_allNextLink2.push(item);
allNextNodeIds.push(item.endId);
}
});
if (allNextNodeIds.length) {
// 有后续节点(子孙节点x偏移)
var childrenList = findChildrenNodeList({
nodeId: nodeId,
modelPathList: modelPathList,
nodeList: nodeList
});
var minNextX = allNextNodeIds.reduce(function (min, item) {
var nodeItem = findNodeById({
nodeId: item,
nodeList: nodeList
});
if (min > nodeItem.coordinate[0]) {
min = nodeItem.coordinate[0];
}
return min;
}, +Infinity);
var moveX = minNextX - node.coordinate[0];
// 删除node
var index = nodeList.findIndex(function (item) {
return item.id === nodeId;
});
nodeList.splice(index, 1);
// 修改坐标
childrenList.forEach(function (item) {
if (item.id !== nodeId) {
item.coordinate[0] -= moveX;
}
});
// 删除link
var _endLink3 = findLinkByEndId({
nodeId: node.id,
linkList: linkList
});
var _prevNodeId2 = _endLink3.startId;
_allNextLink2.forEach(function (item) {
item.startId = _prevNodeId2;
});
var _linkIndex2 = linkList.findIndex(function (item) {
return item.id === _endLink3.id;
});
linkList.splice(_linkIndex2, 1);
// 更改modelPathList
modelPathList.forEach(function (path) {
var pathIndex = path.findIndex(function (item) {
return item === nodeId;
});
if (pathIndex !== -1) {
path.splice(pathIndex, 1);
}
});
modelPathList.splice.apply(modelPathList, [0, modelPathList.length].concat((0, _toConsumableArray2.default)(drop2DArrayDuplicate(modelPathList))));
} else {
// 无后续节点 && 上一个节点有多个子节点(y偏移)
var _endLink4 = findLinkByEndId({
nodeId: node.id,
linkList: linkList
});
var _prevNodeId3 = _endLink4.startId;
var prevAllNextNodeIds = [];
linkList.forEach(function (item) {
if (item.startId === _prevNodeId3) {
prevAllNextNodeIds.push(item.endId);
}
});
if (prevAllNextNodeIds.length >= 2) {
// 存在更下方的同级节点 偏移y
nodeList.forEach(function (item) {
if (item.coordinate[1] > node.coordinate[1] + NODE_HEADER / 2) {
item.coordinate[1] -= node.height + Y_GAP;
}
});
}
// 删除node
var _index = nodeList.findIndex(function (item) {
return item.id === nodeId;
});
nodeList.splice(_index, 1);
// 删除link
cleanExtraLink({
nodeList: nodeList,
linkList: linkList
});
// 更改modelPathList
modelPathList.forEach(function (path) {
var pathIndex = path.findIndex(function (item) {
return item === nodeId;
});
if (pathIndex !== -1) {
path.splice(pathIndex, 1);
}
});
// 将只剩下的起始节点的链路全部删除
for (var _i3 = modelPathList.length - 1; _i3 >= 0; _i3--) {
var _path3 = modelPathList[_i3];
if (_path3.length <= 1) {
modelPathList.splice(_i3, 1);
}
}
if (!modelPathList.length) {
// 若空,则需要置为默认值
modelPathList.splice(0, modelPathList.length, [nodeList[0].id]);
}
modelPathList.splice.apply(modelPathList, [0, modelPathList.length].concat((0, _toConsumableArray2.default)(drop2DArrayDuplicate(modelPathList))));
}
}
}
// export function deleteNode({ nodeId, modelPathList, nodeList, linkList }) {
// const node = findNodeById({ nodeId, nodeList });
// // 未处理的链路 临时变量
// const _tempModelPathList = JSON.parse(JSON.stringify(modelPathList));
// // 需要被删除的节点 集合
// const childrenList = findChildrenNodeList({ nodeId, modelPathList, nodeList });
// const childrenIds = childrenList.map(child => child.id);
// // const maxY = calcMaxY(childrenList);
// // const baseOffsetY = maxY.bottom - (node.height + node.coordinate[1]);
// // let extraOffsetY = 0;
// const endLink = findLinkByEndId({ nodeId: node.id, linkList });
// // 上一个节点
// const prevNode = findNodeByLink({ link: endLink, nodeList }).start;
// // 判断 prevNode 是否被其他节点复用
// let isPrevNodeMult = false;
// modelPathList.forEach(path => {
// if (path.includes(prevNode.id)) {
// // 当前节点所在的位置
// if (!path.includes(nodeId)) {
// isPrevNodeMult = true;
// }
// }
// });
// // if (isPrevNodeMult) {
// // extraOffsetY = Y_GAP + node.height;
// // }
// // const moveY = baseOffsetY + extraOffsetY;
// // 删除 所有需要被删除的节点
// for (let i = nodeList.length - 1; i >= 0; i--) {
// const nodeItem = nodeList[i];
// if (childrenIds.includes(nodeItem.id)) {
// nodeList.splice(i, 1);
// }
// }
// // 找到删除后,上下的两个节点
// // y坐标大于nodeId.y 的node集合
// const otherUpperNodeList = nodeList.filter(
// item =>
// item.coordinate[1] <= node.coordinate[1] + NODE_HEADER / 2 &&
// item?.meta?.configKey !== 'start_node',
// );
// // nodeY1 为 otherUpperNodeList 中 y+height 最大值
// let nodeY1 = null;
// let nodeY1Max = -Infinity;
// // 分割线
// let divisionHeight = 0;
// otherUpperNodeList.forEach(item => {
// // 计算分割线
// if (item.coordinate[1] + item.height > divisionHeight) {
// divisionHeight = item.coordinate[1] + item.height;
// }
// // 计算nodeY1
// // if (!item.meta.extParam.isMergeNode && item.coordinate[1] + item.height > nodeY1Max) {
// if (item.coordinate[1] + item.height > nodeY1Max) {
// nodeY1Max = item.coordinate[1] + item.height;
// nodeY1 = item;
// }
// });
// const otherUnderNodeList = nodeList.filter(
// item => item.coordinate[1] > node.coordinate[1] + NODE_HEADER / 2,
// );
// otherUnderNodeList.sort((a, b) => a.coordinate[1] - b.coordinate[1]);
// const nodeY2 = otherUnderNodeList.length ? otherUnderNodeList[0] : null;
// let baseOffsetY = 0;
// let extraOffsetY = 0;
// if (nodeY1 === null) {
// baseOffsetY = nodeY2 ? nodeY2.coordinate[1] : 0;
// extraOffsetY = 0;
// } else {
// // 计算需要偏