wetrade-design
Version:
一款多语言支持Vue3的UI框架
140 lines (139 loc) • 5.28 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _graphLink = _interopRequireDefault(require("./graphLink"));
var _graphNode = _interopRequireDefault(require("./graphNode"));
var _index = require("./index");
var Graph = /*#__PURE__*/function () {
function Graph(options) {
(0, _classCallCheck2.default)(this, Graph);
var relationMark = options.relationMark,
startMark = options.startMark,
endMark = options.endMark,
_options$linkList = options.linkList,
linkList = _options$linkList === void 0 ? [] : _options$linkList,
_options$nodeList = options.nodeList,
nodeList = _options$nodeList === void 0 ? [] : _options$nodeList,
origin = options.origin,
readonly = options.readonly,
hiddenAppend = options.hiddenAppend;
(0, _extends2.default)(_index.mark, {
relationMark: relationMark,
startMark: startMark,
endMark: endMark
});
this.nodeList = [];
this.linkList = [];
this.origin = origin;
this.mouseOnLink = null;
this.mouseonNode = null;
this.maskBoundingClientRect = {};
this.readonly = readonly;
this.hiddenAppend = hiddenAppend;
this.initNode(nodeList);
this.initLink(linkList);
this.initButtonAndLine(linkList);
}
// 源数组map映射节点
(0, _createClass2.default)(Graph, [{
key: "originPointMap",
value: function originPointMap(nodeList) {
var map = {};
nodeList.forEach(function (point) {
map[point[_index.mark.relationMark]] = point;
});
return map;
}
// 节点映射 创建连线时需要用到
}, {
key: "pointMap",
value: function pointMap() {
var map = {};
this.nodeList.forEach(function (point) {
map[point[_index.mark.relationMark]] = point;
});
return map;
}
}, {
key: "initNode",
value: function initNode(nodeList) {
var _this = this;
(0, _index.arrayReplace)(this.nodeList, nodeList.map(function (node) {
return _this.createNode(node);
}));
this.nodeMap = this.originPointMap(nodeList);
}
}, {
key: "initLink",
value: function initLink(linkList) {
var _this2 = this;
(0, _index.arrayReplace)(this.linkList, linkList.map(function (link) {
return _this2.createLink(link);
}));
}
}, {
key: "createNode",
value: function createNode(options) {
return new _graphNode.default(options, this);
}
}, {
key: "createLink",
value: function createLink(options) {
return new _graphLink.default(options, this);
}
}, {
key: "clearButtonAndLine",
value: function clearButtonAndLine() {
this.insertNodeList = [];
this.shrinkNodeList = [];
this.appendNodeList = [];
this.insertLineList = [];
this.shrinkLineList = [];
}
// 初始化按钮和线段
}, {
key: "initButtonAndLine",
value: function initButtonAndLine(linkList) {
var _this3 = this;
this.clearButtonAndLine();
this.nodeList.forEach(function (node) {
var _node$meta, _node$meta$extParam, _node$meta2;
// 初始化【+】
if (node.meta.extParam.isOpen && node.meta.extParam.canInsert && !node.meta.extParam.isDragElement && !_this3.readonly) {
_this3.insertNodeList.push(node);
}
//【展开收起】
var hasNextNodeAndNotEmpty = linkList.some(function (link) {
var _link$meta, _link$meta2;
return link.startId === node.id && (link === null || link === void 0 ? void 0 : (_link$meta = link.meta) === null || _link$meta === void 0 ? void 0 : _link$meta.activeId) === -1 && !((_link$meta2 = link.meta) !== null && _link$meta2 !== void 0 && _link$meta2.isDragElement);
});
if (hasNextNodeAndNotEmpty) {
_this3.shrinkNodeList.push(node);
}
// 初始化【添】
if (!((_node$meta = node.meta) !== null && _node$meta !== void 0 && (_node$meta$extParam = _node$meta.extParam) !== null && _node$meta$extParam !== void 0 && _node$meta$extParam.isDragElement) && !['start_node', 'empty'].includes((_node$meta2 = node.meta) === null || _node$meta2 === void 0 ? void 0 : _node$meta2.configKey) && !_this3.readonly && !_this3.hiddenAppend) {
_this3.appendNodeList.push(node);
}
// 【+】的连线
if (node.meta.extParam.isOpen && node.meta.extParam.canInsert && !_this3.linkList.some(function (link) {
return link.startId === node.id;
}) && !node.meta.extParam.isDragElement) {
_this3.insertLineList.push(node);
}
// 【展开收起】的连线
if (!node.meta.extParam.isOpen && !node.meta.extParam.isDragElement) {
_this3.shrinkLineList.push(node);
}
});
}
}]);
return Graph;
}();
var _default = Graph;
exports.default = _default;