本地logicflow依赖包
This commit is contained in:
1 parent
8ff82208ad
commit
30f225df00
290 files changed
+18624
-16276
No files matched your search
@@ -0,0 +1,225 @@
|
||||
"use strict";
|
||||
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 });
|
||||
exports.ContextMenu = void 0;
|
||||
var COMMON_TYPE_KEY = 'menu-common';
|
||||
var NEXT_X_DISTANCE = 200;
|
||||
var NEXT_Y_DISTANCE = 100;
|
||||
var ContextMenu = /** @class */ (function () {
|
||||
function ContextMenu(_a) {
|
||||
var _this = this;
|
||||
var lf = _a.lf;
|
||||
this.menuTypeMap = new Map();
|
||||
this.listenDelete = function () {
|
||||
_this.hideContextMenu();
|
||||
};
|
||||
this.lf = lf;
|
||||
this.__menuDOM = document.createElement('div');
|
||||
this.__menuDOM.className = 'lf-inner-context';
|
||||
this.menuTypeMap.set(COMMON_TYPE_KEY, []);
|
||||
this.lf.setContextMenuByType = function (type, menus) {
|
||||
_this.setContextMenuByType(type, menus);
|
||||
};
|
||||
this.lf.setContextMenuItems = function (menus) {
|
||||
_this.setContextMenuItems(menus);
|
||||
};
|
||||
this.lf.showContextMenu = function (data) {
|
||||
_this.showContextMenu(data);
|
||||
};
|
||||
this.lf.hideContextMenu = function () {
|
||||
_this.hideContextMenu();
|
||||
};
|
||||
}
|
||||
ContextMenu.prototype.render = function (lf, container) {
|
||||
var _this = this;
|
||||
this.container = container;
|
||||
lf.on('node:click', function (_a) {
|
||||
var data = _a.data;
|
||||
_this._activeData = data;
|
||||
_this.createContextMenu();
|
||||
});
|
||||
lf.on('edge:click', function (_a) {
|
||||
var data = _a.data;
|
||||
// 获取右上角坐标
|
||||
_this._activeData = data;
|
||||
_this.createContextMenu();
|
||||
});
|
||||
lf.on('blank:click', function () {
|
||||
_this.hideContextMenu();
|
||||
});
|
||||
};
|
||||
ContextMenu.prototype.setContextMenuByType = function (type, menus) {
|
||||
this.menuTypeMap.set(type, menus);
|
||||
};
|
||||
/**
|
||||
* 隐藏菜单
|
||||
*/
|
||||
ContextMenu.prototype.hideContextMenu = function () {
|
||||
this.__menuDOM.innerHTML = '';
|
||||
this.__menuDOM.style.display = 'none';
|
||||
if (this.isShow) {
|
||||
this.container.removeChild(this.__menuDOM);
|
||||
}
|
||||
this.lf.off('node:delete,edge:delete,node:drag,graph:transform', this.listenDelete);
|
||||
this.isShow = false;
|
||||
};
|
||||
/**
|
||||
* 显示指定元素菜单
|
||||
* @param data 节点id、节点类型、菜单位置
|
||||
*/
|
||||
ContextMenu.prototype.showContextMenu = function (data) {
|
||||
if (!data || !data.id) {
|
||||
console.warn('请检查传入的参数');
|
||||
return;
|
||||
}
|
||||
this._activeData = data;
|
||||
this.createContextMenu();
|
||||
};
|
||||
ContextMenu.prototype.setContextMenuItems = function (menus) {
|
||||
this.menuTypeMap.set(COMMON_TYPE_KEY, menus);
|
||||
};
|
||||
/**
|
||||
* 获取新菜单位置
|
||||
*/
|
||||
ContextMenu.prototype.getContextMenuPosition = function () {
|
||||
var data = this._activeData;
|
||||
var Model = this.lf.graphModel.getElement(data.id);
|
||||
if (!Model) {
|
||||
console.warn("\u627E\u4E0D\u5230\u5143\u7D20" + data.id);
|
||||
return;
|
||||
}
|
||||
var x;
|
||||
var y;
|
||||
if (Model.BaseType === 'edge') {
|
||||
x = Number.MIN_SAFE_INTEGER;
|
||||
y = Number.MAX_SAFE_INTEGER;
|
||||
var edgeData = Model.getData();
|
||||
x = Math.max(edgeData.startPoint.x, x);
|
||||
y = Math.min(edgeData.startPoint.y, y);
|
||||
x = Math.max(edgeData.endPoint.x, x);
|
||||
y = Math.min(edgeData.endPoint.y, y);
|
||||
if (edgeData.pointsList) {
|
||||
edgeData.pointsList.forEach(function (point) {
|
||||
x = Math.max(point.x, x);
|
||||
y = Math.min(point.y, y);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (Model.BaseType === 'node') {
|
||||
x = data.x + Model.width / 2;
|
||||
y = data.y - Model.height / 2;
|
||||
}
|
||||
return this.lf.graphModel.transformModel.CanvasPointToHtmlPoint([x, y]);
|
||||
};
|
||||
ContextMenu.prototype.createContextMenu = function () {
|
||||
var _this = this;
|
||||
var isSilentMode = this.lf.options.isSilentMode;
|
||||
// 静默模式不显示菜单
|
||||
if (isSilentMode) {
|
||||
return;
|
||||
}
|
||||
var items = this.menuTypeMap.get(this._activeData.type) || [];
|
||||
items = items.concat(this.menuTypeMap.get(COMMON_TYPE_KEY));
|
||||
var menus = document.createDocumentFragment();
|
||||
items.forEach(function (item) {
|
||||
var menuItem = document.createElement('div');
|
||||
menuItem.className = 'lf-context-item';
|
||||
var img = document.createElement('img');
|
||||
img.src = item.icon;
|
||||
img.className = 'lf-context-img';
|
||||
if (item.className) {
|
||||
menuItem.className = menuItem.className + " " + item.className;
|
||||
}
|
||||
img.addEventListener('click', function () {
|
||||
_this.hideContextMenu();
|
||||
if (item.callback) {
|
||||
item.callback(_this._activeData);
|
||||
}
|
||||
else {
|
||||
_this.addNode({
|
||||
sourceId: _this._activeData.id,
|
||||
x: _this._activeData.x,
|
||||
y: _this._activeData.y,
|
||||
properties: item.properties,
|
||||
type: item.type,
|
||||
});
|
||||
}
|
||||
});
|
||||
menuItem.appendChild(img);
|
||||
menus.appendChild(menuItem);
|
||||
});
|
||||
this.__menuDOM.innerHTML = '';
|
||||
this.__menuDOM.appendChild(menus);
|
||||
this.showMenu();
|
||||
};
|
||||
ContextMenu.prototype.addNode = function (node, y) {
|
||||
var isDeep = y !== undefined;
|
||||
if (y === undefined) {
|
||||
y = node.y;
|
||||
}
|
||||
var nodeModel = this.lf.getNodeModelById(node.sourceId);
|
||||
var leftTopX = node.x - nodeModel.width + NEXT_X_DISTANCE;
|
||||
var leftTopY = y - node.y / 2 - 20;
|
||||
var rightBottomX = node.x + nodeModel.width + NEXT_X_DISTANCE;
|
||||
var rightBottomY = y + node.y / 2 + 20;
|
||||
var exsitElements = this.lf.getAreaElement([leftTopX, leftTopY], [rightBottomX, rightBottomY]);
|
||||
if (exsitElements.length) {
|
||||
y = y + NEXT_Y_DISTANCE;
|
||||
this.addNode(node, y);
|
||||
return;
|
||||
}
|
||||
var newNode = this.lf.addNode({
|
||||
type: node.type,
|
||||
x: node.x + 200,
|
||||
y: y,
|
||||
properties: node.properties,
|
||||
});
|
||||
var startPoint;
|
||||
var endPoint;
|
||||
if (isDeep) {
|
||||
startPoint = {
|
||||
x: node.x,
|
||||
y: node.y + nodeModel.height / 2,
|
||||
};
|
||||
endPoint = {
|
||||
x: newNode.x - newNode.width / 2,
|
||||
y: newNode.y,
|
||||
};
|
||||
}
|
||||
this.lf.addEdge({
|
||||
sourceNodeId: node.sourceId,
|
||||
targetNodeId: newNode.id,
|
||||
startPoint: startPoint,
|
||||
endPoint: endPoint,
|
||||
});
|
||||
};
|
||||
ContextMenu.prototype.showMenu = function () {
|
||||
var _a = __read(this.getContextMenuPosition(), 2), x = _a[0], y = _a[1];
|
||||
this.__menuDOM.style.display = 'flex';
|
||||
this.__menuDOM.style.top = y + "px";
|
||||
this.__menuDOM.style.left = x + 10 + "px";
|
||||
this.container.appendChild(this.__menuDOM);
|
||||
// 菜单显示的时候,监听删除,同时隐藏
|
||||
!this.isShow && this.lf.on('node:delete,edge:delete,node:drag,graph:transform', this.listenDelete);
|
||||
this.isShow = true;
|
||||
};
|
||||
ContextMenu.pluginName = 'contextMenu';
|
||||
return ContextMenu;
|
||||
}());
|
||||
exports.ContextMenu = ContextMenu;
|
||||
exports.default = ContextMenu;
|
||||
@@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
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;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Control = void 0;
|
||||
var Control = /** @class */ (function () {
|
||||
function Control(_a) {
|
||||
var _this = this;
|
||||
var lf = _a.lf;
|
||||
this.controlItems = [
|
||||
{
|
||||
key: 'zoom-out',
|
||||
iconClass: 'lf-control-zoomOut',
|
||||
title: '缩小流程图',
|
||||
text: '缩小',
|
||||
onClick: function () {
|
||||
_this.lf.zoom(false);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'zoom-in',
|
||||
iconClass: 'lf-control-zoomIn',
|
||||
title: '放大流程图',
|
||||
text: '放大',
|
||||
onClick: function () {
|
||||
_this.lf.zoom(true);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'reset',
|
||||
iconClass: 'lf-control-fit',
|
||||
title: '恢复流程原有尺寸',
|
||||
text: '适应',
|
||||
onClick: function () {
|
||||
_this.lf.resetZoom();
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'undo',
|
||||
iconClass: 'lf-control-undo',
|
||||
title: '回到上一步',
|
||||
text: '上一步',
|
||||
onClick: function () {
|
||||
_this.lf.undo();
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'redo',
|
||||
iconClass: 'lf-control-redo',
|
||||
title: '移到下一步',
|
||||
text: '下一步',
|
||||
onClick: function () {
|
||||
_this.lf.redo();
|
||||
},
|
||||
},
|
||||
];
|
||||
this.lf = lf;
|
||||
}
|
||||
Control.prototype.render = function (lf, domContainer) {
|
||||
this.destroy();
|
||||
var toolEl = this.getControlTool();
|
||||
this.toolEl = toolEl;
|
||||
domContainer.appendChild(toolEl);
|
||||
this.domContainer = domContainer;
|
||||
};
|
||||
Control.prototype.destroy = function () {
|
||||
if (this.domContainer && this.toolEl && this.domContainer.contains(this.toolEl)) {
|
||||
this.domContainer.removeChild(this.toolEl);
|
||||
}
|
||||
};
|
||||
Control.prototype.addItem = function (item) {
|
||||
this.controlItems.push(item);
|
||||
};
|
||||
Control.prototype.removeItem = function (key) {
|
||||
var index = this.controlItems.findIndex(function (item) { return item.key === key; });
|
||||
return this.controlItems.splice(index, 1)[0];
|
||||
};
|
||||
Control.prototype.getControlTool = function () {
|
||||
var _this = this;
|
||||
var NORMAL = 'lf-control-item';
|
||||
var DISABLED = 'lf-control-item disabled';
|
||||
var controlTool = document.createElement('div');
|
||||
var controlElements = [];
|
||||
controlTool.className = 'lf-control';
|
||||
this.controlItems.forEach(function (item) {
|
||||
var itemContainer = document.createElement('div');
|
||||
var icon = document.createElement('i');
|
||||
var text = document.createElement('span');
|
||||
itemContainer.className = DISABLED;
|
||||
item.onClick && (itemContainer.onclick = item.onClick.bind(null, _this.lf));
|
||||
item.onMouseEnter && (itemContainer.onmouseenter = item.onMouseEnter.bind(null, _this.lf));
|
||||
item.onMouseLeave && (itemContainer.onmouseleave = item.onMouseLeave.bind(null, _this.lf));
|
||||
icon.className = item.iconClass;
|
||||
text.className = 'lf-control-text';
|
||||
text.title = item.title;
|
||||
text.innerText = item.text;
|
||||
itemContainer.append(icon, text);
|
||||
switch (item.text) {
|
||||
case '上一步':
|
||||
_this.lf.on('history:change', function (_a) {
|
||||
var undoAble = _a.data.undoAble;
|
||||
itemContainer.className = undoAble ? NORMAL : DISABLED;
|
||||
});
|
||||
break;
|
||||
case '下一步':
|
||||
_this.lf.on('history:change', function (_a) {
|
||||
var redoAble = _a.data.redoAble;
|
||||
itemContainer.className = redoAble ? NORMAL : DISABLED;
|
||||
});
|
||||
break;
|
||||
default:
|
||||
itemContainer.className = NORMAL;
|
||||
break;
|
||||
}
|
||||
controlElements.push(itemContainer);
|
||||
});
|
||||
controlTool.append.apply(controlTool, __spread(controlElements));
|
||||
return controlTool;
|
||||
};
|
||||
Control.pluginName = 'control';
|
||||
return Control;
|
||||
}());
|
||||
exports.Control = Control;
|
||||
exports.default = Control;
|
||||
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DndPanel = void 0;
|
||||
var DndPanel = /** @class */ (function () {
|
||||
function DndPanel(_a) {
|
||||
var _this = this;
|
||||
var lf = _a.lf;
|
||||
this.lf = lf;
|
||||
this.lf.setPatternItems = function (shapeList) {
|
||||
_this.setPatternItems(shapeList);
|
||||
};
|
||||
}
|
||||
DndPanel.prototype.render = function (lf, domContainer) {
|
||||
var _this = this;
|
||||
this.destroy();
|
||||
if (!this.shapeList || this.shapeList.length === 0) {
|
||||
// 首次render后失败后,后续调用setPatternItems支持渲染
|
||||
this.domContainer = domContainer;
|
||||
return;
|
||||
}
|
||||
this.panelEl = document.createElement('div');
|
||||
this.panelEl.className = 'lf-dndpanel';
|
||||
this.shapeList.forEach(function (shapeItem) {
|
||||
_this.panelEl.appendChild(_this.createDndItem(shapeItem));
|
||||
});
|
||||
domContainer.appendChild(this.panelEl);
|
||||
this.domContainer = domContainer;
|
||||
};
|
||||
DndPanel.prototype.destroy = function () {
|
||||
if (this.domContainer && this.panelEl && this.domContainer.contains(this.panelEl)) {
|
||||
this.domContainer.removeChild(this.panelEl);
|
||||
}
|
||||
};
|
||||
DndPanel.prototype.setPatternItems = function (shapeList) {
|
||||
this.shapeList = shapeList;
|
||||
// 支持渲染后重新设置拖拽面板
|
||||
if (this.domContainer) {
|
||||
this.render(this.lf, this.domContainer);
|
||||
}
|
||||
};
|
||||
DndPanel.prototype.createDndItem = function (shapeItem) {
|
||||
var _this = this;
|
||||
var el = document.createElement('div');
|
||||
el.className = shapeItem.className ? "lf-dnd-item " + shapeItem.className : 'lf-dnd-item';
|
||||
var shape = document.createElement('div');
|
||||
shape.className = 'lf-dnd-shape';
|
||||
if (shapeItem.icon) {
|
||||
shape.style.backgroundImage = "url(" + shapeItem.icon + ")";
|
||||
}
|
||||
el.appendChild(shape);
|
||||
if (shapeItem.label) {
|
||||
var text = document.createElement('div');
|
||||
text.innerText = shapeItem.label;
|
||||
text.className = 'lf-dnd-text';
|
||||
el.appendChild(text);
|
||||
}
|
||||
el.onmousedown = function () {
|
||||
if (shapeItem.type) {
|
||||
_this.lf.dnd.startDrag({
|
||||
type: shapeItem.type,
|
||||
properties: shapeItem.properties,
|
||||
text: shapeItem.text,
|
||||
});
|
||||
}
|
||||
if (shapeItem.callback) {
|
||||
shapeItem.callback(_this.lf, _this.domContainer);
|
||||
}
|
||||
};
|
||||
return el;
|
||||
};
|
||||
DndPanel.pluginName = 'dndPanel';
|
||||
return DndPanel;
|
||||
}());
|
||||
exports.DndPanel = DndPanel;
|
||||
@@ -0,0 +1,303 @@
|
||||
"use strict";
|
||||
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;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Menu = void 0;
|
||||
var DefalutNodeMenuKey = 'lf:defaultNodeMenu';
|
||||
var DefalutEdgeMenuKey = 'lf:defaultEdgeMenu';
|
||||
var DefalutGraphMenuKey = 'lf:defaultGraphMenu';
|
||||
var DefalutSelectionMenuKey = 'lf:defaultSelectionMenu';
|
||||
var Menu = /** @class */ (function () {
|
||||
function Menu(_a) {
|
||||
var _this = this;
|
||||
var lf = _a.lf;
|
||||
this.__menuDOM = document.createElement('ul');
|
||||
this.lf = lf;
|
||||
this.menuTypeMap = new Map();
|
||||
this.init();
|
||||
this.lf.setMenuConfig = function (config) {
|
||||
_this.setMenuConfig(config);
|
||||
};
|
||||
this.lf.addMenuConfig = function (config) {
|
||||
_this.addMenuConfig(config);
|
||||
};
|
||||
this.lf.setMenuByType = function (config) {
|
||||
_this.setMenuByType(config);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 初始化设置默认内置菜单栏
|
||||
*/
|
||||
Menu.prototype.init = function () {
|
||||
var _this = this;
|
||||
var defalutNodeMenu = [
|
||||
{
|
||||
text: '删除',
|
||||
callback: function (node) {
|
||||
_this.lf.deleteNode(node.id);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: '编辑文本',
|
||||
callback: function (node) {
|
||||
_this.lf.graphModel.editText(node.id);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: '复制',
|
||||
callback: function (node) {
|
||||
_this.lf.cloneNode(node.id);
|
||||
},
|
||||
},
|
||||
];
|
||||
this.menuTypeMap.set(DefalutNodeMenuKey, defalutNodeMenu);
|
||||
var defaultEdgeMenu = [
|
||||
{
|
||||
text: '删除',
|
||||
callback: function (edge) {
|
||||
_this.lf.deleteEdge(edge.id);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: '编辑文本',
|
||||
callback: function (edge) {
|
||||
_this.lf.graphModel.editText(edge.id);
|
||||
},
|
||||
},
|
||||
];
|
||||
this.menuTypeMap.set(DefalutEdgeMenuKey, defaultEdgeMenu);
|
||||
this.menuTypeMap.set(DefalutGraphMenuKey, []);
|
||||
var DefalutSelectionMenu = [
|
||||
{
|
||||
text: '删除',
|
||||
callback: function (elements) {
|
||||
_this.lf.clearSelectElements();
|
||||
elements.edges.forEach(function (edge) { return _this.lf.deleteEdge(edge.id); });
|
||||
elements.nodes.forEach(function (node) { return _this.lf.deleteNode(node.id); });
|
||||
},
|
||||
},
|
||||
];
|
||||
this.menuTypeMap.set(DefalutSelectionMenuKey, DefalutSelectionMenu);
|
||||
};
|
||||
Menu.prototype.render = function (lf, container) {
|
||||
var _this = this;
|
||||
this.__container = container;
|
||||
this.__currentData = null; // 当前展示的菜单所属元素的model数据
|
||||
this.__menuDOM.className = 'lf-menu';
|
||||
container.appendChild(this.__menuDOM);
|
||||
// 将选项的click事件委托至menu容器
|
||||
// 在捕获阶段拦截并执行
|
||||
this.__menuDOM.addEventListener('click', function (event) {
|
||||
event.stopPropagation();
|
||||
var target = event.target;
|
||||
// 菜单有多层dom,需要精确获取菜单项所对应的dom
|
||||
// 除菜单项dom外,应考虑两种情况
|
||||
// 1. 菜单项的子元素 2. 菜单外层容器
|
||||
while (Array.from(target.classList).indexOf('lf-menu-item') === -1 && Array.from(target.classList).indexOf('lf-menu') === -1) {
|
||||
target = target.parentElement;
|
||||
}
|
||||
if (Array.from(target.classList).indexOf('lf-menu-item') > -1) {
|
||||
// 如果点击区域在菜单项内
|
||||
target.onclickCallback(_this.__currentData);
|
||||
// 点击后隐藏menu
|
||||
_this.__menuDOM.style.display = 'none';
|
||||
_this.__currentData = null;
|
||||
}
|
||||
else {
|
||||
// 如果点击区域不在菜单项内
|
||||
console.warn('点击区域不在菜单项内,请检查代码!');
|
||||
}
|
||||
}, true);
|
||||
// 通过事件控制菜单的显示和隐藏
|
||||
this.lf.on('node:contextmenu', function (_a) {
|
||||
var data = _a.data, position = _a.position;
|
||||
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
|
||||
var id = data.id;
|
||||
var model = _this.lf.graphModel.getNodeModelById(id);
|
||||
var menuList = [];
|
||||
var typeMenus = _this.menuTypeMap.get(model.type);
|
||||
// 如果单个节点自定义了节点,以单个节点自定义为准
|
||||
if (model && model.menu && Array.isArray(model.menu)) {
|
||||
menuList = model.menu;
|
||||
}
|
||||
else if (typeMenus) { // 如果定义当前节点类型的元素
|
||||
menuList = typeMenus;
|
||||
}
|
||||
else { // 最后取全局默认
|
||||
menuList = _this.menuTypeMap.get(DefalutNodeMenuKey);
|
||||
}
|
||||
_this.__currentData = data;
|
||||
_this.showMenu(x, y, menuList);
|
||||
});
|
||||
this.lf.on('edge:contextmenu', function (_a) {
|
||||
var data = _a.data, position = _a.position;
|
||||
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
|
||||
var id = data.id;
|
||||
var model = _this.lf.graphModel.getEdgeModelById(id);
|
||||
var menuList = [];
|
||||
var typeMenus = _this.menuTypeMap.get(model.type);
|
||||
// 如果单个节点自定义了边
|
||||
if (model && model.menu && Array.isArray(model.menu)) {
|
||||
menuList = model.menu;
|
||||
}
|
||||
else if (typeMenus) { // 如果定义当前边类型的元素
|
||||
menuList = typeMenus;
|
||||
}
|
||||
else { // 最后取全局默认
|
||||
menuList = _this.menuTypeMap.get(DefalutEdgeMenuKey);
|
||||
}
|
||||
_this.__currentData = data;
|
||||
_this.showMenu(x, y, menuList);
|
||||
});
|
||||
this.lf.on('blank:contextmenu', function (_a) {
|
||||
var position = _a.position;
|
||||
var menuList = _this.menuTypeMap.get(DefalutGraphMenuKey);
|
||||
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
|
||||
_this.showMenu(x, y, menuList);
|
||||
});
|
||||
this.lf.on('selection:contextmenu', function (_a) {
|
||||
var data = _a.data, position = _a.position;
|
||||
var menuList = _this.menuTypeMap.get(DefalutSelectionMenuKey);
|
||||
var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
|
||||
_this.__currentData = data;
|
||||
_this.showMenu(x, y, menuList);
|
||||
});
|
||||
this.lf.on('node:mousedown', function () {
|
||||
_this.__menuDOM.style.display = 'none';
|
||||
});
|
||||
this.lf.on('edge:click', function () {
|
||||
_this.__menuDOM.style.display = 'none';
|
||||
});
|
||||
this.lf.on('blank:click', function () {
|
||||
_this.__menuDOM.style.display = 'none';
|
||||
});
|
||||
};
|
||||
Menu.prototype.destroy = function () {
|
||||
var _a;
|
||||
(_a = this === null || this === void 0 ? void 0 : this.__container) === null || _a === void 0 ? void 0 : _a.removeChild(this.__menuDOM);
|
||||
this.__menuDOM = null;
|
||||
};
|
||||
Menu.prototype.showMenu = function (x, y, menuList) {
|
||||
if (!menuList || !menuList.length)
|
||||
return;
|
||||
var menu = this.__menuDOM;
|
||||
// 菜单容器不变,需要先清空内部的菜单项
|
||||
menu.innerHTML = '';
|
||||
menu.append.apply(menu, __spread(this.__getMenuDom(menuList)));
|
||||
// 菜单中没有项,不显示
|
||||
if (!menu.children.length)
|
||||
return;
|
||||
menu.style.display = 'block';
|
||||
menu.style.top = y + "px";
|
||||
menu.style.left = x + "px";
|
||||
};
|
||||
/**
|
||||
* 设置指定类型元素的菜单
|
||||
*/
|
||||
Menu.prototype.setMenuByType = function (config) {
|
||||
if (!config.type || !config.menu) {
|
||||
return;
|
||||
}
|
||||
this.menuTypeMap.set(config.type, config.menu);
|
||||
};
|
||||
/**
|
||||
* 获取 Menu DOM
|
||||
* @param list 菜单项
|
||||
* @return 菜单项 DOM
|
||||
*/
|
||||
Menu.prototype.__getMenuDom = function (list) {
|
||||
var menuList = [];
|
||||
list && list.length > 0 && list.forEach(function (item) {
|
||||
var element = document.createElement('li');
|
||||
if (item.className) {
|
||||
element.className = "lf-menu-item " + item.className;
|
||||
}
|
||||
else {
|
||||
element.className = 'lf-menu-item';
|
||||
}
|
||||
if (item.icon === true) {
|
||||
var icon = document.createElement('span');
|
||||
icon.className = 'lf-menu-item-icon';
|
||||
element.appendChild(icon);
|
||||
}
|
||||
var text = document.createElement('span');
|
||||
text.className = 'lf-menu-item-text';
|
||||
if (item.text) {
|
||||
text.innerText = item.text;
|
||||
}
|
||||
element.appendChild(text);
|
||||
element.onclickCallback = item.callback;
|
||||
menuList.push(element);
|
||||
});
|
||||
return menuList;
|
||||
};
|
||||
// 复写菜单
|
||||
Menu.prototype.setMenuConfig = function (config) {
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
// node
|
||||
config.nodeMenu !== undefined
|
||||
&& this.menuTypeMap.set(DefalutNodeMenuKey, config.nodeMenu ? config.nodeMenu : []);
|
||||
// edge
|
||||
config.edgeMenu !== undefined
|
||||
&& this.menuTypeMap.set(DefalutEdgeMenuKey, config.edgeMenu ? config.edgeMenu : []);
|
||||
// graph
|
||||
config.graphMenu !== undefined
|
||||
&& this.menuTypeMap.set(DefalutGraphMenuKey, config.graphMenu ? config.graphMenu : []);
|
||||
};
|
||||
// 在默认菜单后面追加菜单项
|
||||
Menu.prototype.addMenuConfig = function (config) {
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
// 追加项时,只支持数组类型,对false不做操作
|
||||
if (Array.isArray(config.nodeMenu)) {
|
||||
var menuList = this.menuTypeMap.get(DefalutNodeMenuKey);
|
||||
this.menuTypeMap.set(DefalutNodeMenuKey, menuList.concat(config.nodeMenu));
|
||||
}
|
||||
if (Array.isArray(config.edgeMenu)) {
|
||||
var menuList = this.menuTypeMap.get(DefalutEdgeMenuKey);
|
||||
this.menuTypeMap.set(DefalutEdgeMenuKey, menuList.concat(config.edgeMenu));
|
||||
}
|
||||
if (Array.isArray(config.graphMenu)) {
|
||||
var menuList = this.menuTypeMap.get(DefalutGraphMenuKey);
|
||||
this.menuTypeMap.set(DefalutGraphMenuKey, menuList.concat(config.graphMenu));
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @deprecated
|
||||
* 复写添加
|
||||
*/
|
||||
Menu.prototype.changeMenuItem = function (type, config) {
|
||||
if (type === 'add')
|
||||
this.addMenuConfig(config);
|
||||
else if (type === 'reset')
|
||||
this.setMenuConfig(config);
|
||||
else {
|
||||
throw new Error('The first parameter of changeMenuConfig should be \'add\' or \'reset\'');
|
||||
}
|
||||
};
|
||||
Menu.pluginName = 'menu';
|
||||
return Menu;
|
||||
}());
|
||||
exports.Menu = Menu;
|
||||
exports.default = Menu;
|
||||
@@ -0,0 +1,328 @@
|
||||
"use strict";
|
||||
var __values = (this && this.__values) || function(o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) return m.call(o);
|
||||
if (o && typeof o.length === "number") return {
|
||||
next: function () {
|
||||
if (o && i >= o.length) o = void 0;
|
||||
return { value: o && o[i++], done: !o };
|
||||
}
|
||||
};
|
||||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MiniMap = void 0;
|
||||
var MiniMap = /** @class */ (function () {
|
||||
function MiniMap(_a) {
|
||||
var _this = this;
|
||||
var lf = _a.lf, LogicFlow = _a.LogicFlow;
|
||||
this.__lf = null;
|
||||
this.__container = null;
|
||||
this.__miniMapWrap = null;
|
||||
this.__miniMapContainer = null;
|
||||
this.__lfMap = null;
|
||||
this.__viewport = null;
|
||||
this.__width = 150;
|
||||
this.__height = 220;
|
||||
this.__miniMapWidth = 450;
|
||||
this.__miniMapHeight = 660;
|
||||
this.__viewPortTop = 0;
|
||||
this.__viewPortLeft = 0;
|
||||
this.__startPosition = null;
|
||||
this.__viewPortScale = 1;
|
||||
this.__viewPortWidth = 150;
|
||||
this.__viewPortHeight = 75;
|
||||
this.__resetDataX = 0;
|
||||
this.__resetDataY = 0;
|
||||
this.__LogicFlow = null;
|
||||
this.__isShow = false;
|
||||
this.__disabledPlugins = ['miniMap', 'control', 'selectionSelect'];
|
||||
/**
|
||||
* 显示mini map
|
||||
*/
|
||||
this.show = function (leftPosition, topPosition) {
|
||||
_this.__setView();
|
||||
if (!_this.__isShow) {
|
||||
_this.__createMiniMap(leftPosition, topPosition);
|
||||
}
|
||||
_this.__isShow = true;
|
||||
};
|
||||
/**
|
||||
* 隐藏mini map
|
||||
*/
|
||||
this.hide = function () {
|
||||
if (_this.__isShow) {
|
||||
_this.__removeMiniMap();
|
||||
}
|
||||
_this.__isShow = false;
|
||||
};
|
||||
this.__startDrag = function (e) {
|
||||
document.addEventListener('mousemove', _this.__drag);
|
||||
document.addEventListener('mouseup', _this.__drop);
|
||||
_this.__startPosition = {
|
||||
x: e.x,
|
||||
y: e.y,
|
||||
};
|
||||
};
|
||||
this.__drag = function (e) {
|
||||
var viewStyle = _this.__viewport.style;
|
||||
_this.__viewPortTop += e.y - _this.__startPosition.y;
|
||||
_this.__viewPortLeft += e.x - _this.__startPosition.x;
|
||||
viewStyle.top = _this.__viewPortTop + "px";
|
||||
viewStyle.left = _this.__viewPortLeft + "px";
|
||||
_this.__startPosition = {
|
||||
x: e.x,
|
||||
y: e.y,
|
||||
};
|
||||
var centerX = (_this.__viewPortLeft + _this.__viewPortWidth / 2)
|
||||
/ _this.__viewPortScale;
|
||||
var centerY = (_this.__viewPortTop + _this.__viewPortHeight / 2)
|
||||
/ _this.__viewPortScale;
|
||||
_this.__lf.focusOn({
|
||||
coordinate: {
|
||||
x: centerX + _this.__resetDataX,
|
||||
y: centerY + _this.__resetDataY,
|
||||
},
|
||||
});
|
||||
};
|
||||
this.__drop = function () {
|
||||
document.removeEventListener('mousemove', _this.__drag);
|
||||
document.removeEventListener('mouseup', _this.__drop);
|
||||
};
|
||||
this.__lf = lf;
|
||||
this.__miniMapWidth = lf.graphModel.width;
|
||||
this.__miniMapHeight = (lf.graphModel.width * 220) / 150;
|
||||
this.__LogicFlow = LogicFlow;
|
||||
this.__init();
|
||||
}
|
||||
MiniMap.prototype.render = function (lf, container) {
|
||||
var _this = this;
|
||||
this.__container = container;
|
||||
this.__lf.on('history:change', function () {
|
||||
if (_this.__isShow) {
|
||||
_this.__setView();
|
||||
}
|
||||
});
|
||||
};
|
||||
MiniMap.prototype.init = function (option) {
|
||||
this.__disabledPlugins = this.__disabledPlugins.concat(option.disabledPlugins || []);
|
||||
};
|
||||
MiniMap.prototype.__init = function () {
|
||||
var miniMapWrap = document.createElement('div');
|
||||
miniMapWrap.className = 'lf-mini-map-graph';
|
||||
miniMapWrap.style.width = this.__width + "px";
|
||||
miniMapWrap.style.height = this.__height + "px";
|
||||
this.__lfMap = new this.__LogicFlow({
|
||||
width: this.__lf.graphModel.width,
|
||||
height: (this.__lf.graphModel.width * 220) / 150,
|
||||
container: miniMapWrap,
|
||||
isSilentMode: true,
|
||||
stopZoomGraph: true,
|
||||
stopScrollGraph: true,
|
||||
stopMoveGraph: true,
|
||||
hideAnchors: true,
|
||||
hoverOutline: false,
|
||||
disabledPlugins: this.__disabledPlugins,
|
||||
});
|
||||
// minimap中禁用adapter。
|
||||
this.__lfMap.adapterIn = function (a) { return a; };
|
||||
this.__lfMap.adapterOut = function (a) { return a; };
|
||||
this.__miniMapWrap = miniMapWrap;
|
||||
this.__createViewPort();
|
||||
};
|
||||
MiniMap.prototype.__createMiniMap = function (left, top) {
|
||||
var miniMapContainer = document.createElement('div');
|
||||
var miniMapWrap = this.__miniMapWrap;
|
||||
miniMapContainer.appendChild(miniMapWrap);
|
||||
if (typeof left !== 'undefined' && typeof top !== 'undefined') {
|
||||
miniMapContainer.style.left = left + "px";
|
||||
miniMapContainer.style.top = top + "px";
|
||||
}
|
||||
miniMapContainer.style.position = 'absolute';
|
||||
miniMapContainer.className = 'lf-mini-map';
|
||||
this.__container.appendChild(miniMapContainer);
|
||||
this.__miniMapWrap.appendChild(this.__viewport);
|
||||
var header = document.createElement('div');
|
||||
header.className = 'lf-mini-map-header';
|
||||
header.innerText = '导航';
|
||||
miniMapContainer.appendChild(header);
|
||||
var close = document.createElement('span');
|
||||
close.className = 'lf-mini-map-close';
|
||||
close.addEventListener('click', this.hide);
|
||||
miniMapContainer.appendChild(close);
|
||||
this.__miniMapContainer = miniMapContainer;
|
||||
};
|
||||
MiniMap.prototype.__removeMiniMap = function () {
|
||||
this.__container.removeChild(this.__miniMapContainer);
|
||||
};
|
||||
/**
|
||||
* 计算所有图形一起,占领的区域范围。
|
||||
* @param data
|
||||
*/
|
||||
MiniMap.prototype.__getBounds = function (data) {
|
||||
var left = 0;
|
||||
var right = this.__miniMapWidth;
|
||||
var top = 0;
|
||||
var bottom = this.__miniMapHeight;
|
||||
var nodes = data.nodes;
|
||||
if (nodes && nodes.length > 0) {
|
||||
// 因为获取的节点不知道真实的宽高,这里需要补充一点数值
|
||||
nodes.forEach(function (_a) {
|
||||
var x = _a.x, y = _a.y, _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c;
|
||||
var nodeLeft = x - width / 2;
|
||||
var noderight = x + width / 2;
|
||||
var nodeTop = y - height / 2;
|
||||
var nodeBottom = y + height / 2;
|
||||
left = nodeLeft < left ? nodeLeft : left;
|
||||
right = noderight > right ? noderight : right;
|
||||
top = nodeTop < top ? nodeTop : top;
|
||||
bottom = nodeBottom > bottom ? nodeBottom : bottom;
|
||||
});
|
||||
}
|
||||
return {
|
||||
left: left,
|
||||
top: top,
|
||||
bottom: bottom,
|
||||
right: right,
|
||||
};
|
||||
};
|
||||
/**
|
||||
* 将负值的平移转换为正值。
|
||||
* 保证渲染的时候,minimap能完全展示。
|
||||
* 获取将画布所有元素平移到0,0开始时,所有节点数据
|
||||
*/
|
||||
MiniMap.prototype.__resetData = function (data) {
|
||||
var nodes = data.nodes, edges = data.edges;
|
||||
var left = 0;
|
||||
var top = 0;
|
||||
if (nodes && nodes.length > 0) {
|
||||
// 因为获取的节点不知道真实的宽高,这里需要补充一点数值
|
||||
nodes.forEach(function (_a) {
|
||||
var x = _a.x, y = _a.y, _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c;
|
||||
var nodeLeft = x - width / 2;
|
||||
var nodeTop = y - height / 2;
|
||||
left = nodeLeft < left ? nodeLeft : left;
|
||||
top = nodeTop < top ? nodeTop : top;
|
||||
});
|
||||
if (left < 0 || top < 0) {
|
||||
this.__resetDataX = left;
|
||||
this.__resetDataY = top;
|
||||
nodes.forEach(function (node) {
|
||||
node.x = node.x - left;
|
||||
node.y = node.y - top;
|
||||
if (node.text) {
|
||||
node.text.x = node.text.x - left;
|
||||
node.text.y = node.text.y - top;
|
||||
}
|
||||
});
|
||||
edges.forEach(function (edge) {
|
||||
if (edge.startPoint) {
|
||||
edge.startPoint.x = edge.startPoint.x - left;
|
||||
edge.startPoint.y = edge.startPoint.y - top;
|
||||
}
|
||||
if (edge.endPoint) {
|
||||
edge.endPoint.x = edge.endPoint.x - left;
|
||||
edge.endPoint.y = edge.endPoint.y - top;
|
||||
}
|
||||
if (edge.text) {
|
||||
edge.text.x = edge.text.x - left;
|
||||
edge.text.y = edge.text.y - top;
|
||||
}
|
||||
if (edge.pointsList) {
|
||||
edge.pointsList.forEach(function (point) {
|
||||
point.x = point.x - left;
|
||||
point.y = point.y - top;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return data;
|
||||
};
|
||||
/**
|
||||
* 显示导航
|
||||
* 显示视口范围
|
||||
* 1. 基于画布的范围比例,设置视口范围比例。宽度默认为导航宽度。
|
||||
*/
|
||||
MiniMap.prototype.__setView = function () {
|
||||
var e_1, _a;
|
||||
// 1. 获取到图中所有的节点中的位置,将其偏移到原点开始(避免节点位置为负的时候无法展示问题)。
|
||||
var data = this.__resetData(this.__lf.getGraphRawData());
|
||||
// 由于随时都会有新节点注册进来,需要同步将注册的
|
||||
var viewMap = this.__lf.viewMap;
|
||||
var modelMap = this.__lf.graphModel.modelMap;
|
||||
var minimapViewMap = this.__lfMap.viewMap;
|
||||
try {
|
||||
// todo: no-restricted-syntax
|
||||
for (var _b = __values(viewMap.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||
var key = _c.value;
|
||||
if (!minimapViewMap.has(key)) {
|
||||
this.__lfMap.setView(key, viewMap.get(key));
|
||||
this.__lfMap.graphModel.modelMap.set(key, modelMap.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
this.__lfMap.render(data);
|
||||
// 2. 将偏移后的数据渲染到minimap画布上
|
||||
// 3. 计算出所有节点在一起的边界。
|
||||
var _d = this.__getBounds(data), left = _d.left, top = _d.top, right = _d.right, bottom = _d.bottom;
|
||||
// 4. 计算所有节点的边界与minimap看板的边界的比例.
|
||||
var realWidthScale = this.__width / (right - left);
|
||||
var realHeightScale = this.__height / (bottom - top);
|
||||
// 5. 取比例最小的值,将渲染的画布缩小对应比例。
|
||||
var innerStyle = this.__miniMapWrap.firstChild.style;
|
||||
var scale = Math.min(realWidthScale, realHeightScale);
|
||||
innerStyle.transform = "matrix(" + scale + ", 0, 0, " + scale + ", 0, 0)";
|
||||
innerStyle.transformOrigin = 'left top';
|
||||
innerStyle.height = bottom - Math.min(top, 0) + "px";
|
||||
innerStyle.width = right - Math.min(left, 0) + "px";
|
||||
this.__viewPortScale = scale;
|
||||
this.__setViewPort(scale, {
|
||||
left: left,
|
||||
top: top,
|
||||
right: right,
|
||||
bottom: bottom,
|
||||
});
|
||||
};
|
||||
// 设置视口
|
||||
MiniMap.prototype.__setViewPort = function (scale, _a) {
|
||||
var left = _a.left, right = _a.right, top = _a.top, bottom = _a.bottom;
|
||||
var viewStyle = this.__viewport.style;
|
||||
viewStyle.width = this.__width - 4 + "px";
|
||||
viewStyle.height = (this.__width - 4) / (this.__lf.graphModel.width / this.__lf.graphModel.height) + "px";
|
||||
// top
|
||||
var _b = this.__lf.getTransform(), TRANSLATE_X = _b.TRANSLATE_X, TRANSLATE_Y = _b.TRANSLATE_Y;
|
||||
var realWidth = right - left;
|
||||
// 视口实际宽 = 视口默认宽 / (所有元素一起占据的真实宽 / 绘布宽)
|
||||
var realViewPortWidth = (this.__width - 4) / (realWidth / this.__lf.graphModel.width);
|
||||
// 视口实际高 = 视口实际宽 / (绘布宽 / 绘布高)
|
||||
var graphRatio = (this.__lf.graphModel.width / this.__lf.graphModel.height);
|
||||
var realViewPortHeight = realViewPortWidth / graphRatio;
|
||||
this.__viewPortTop = TRANSLATE_Y > 0 ? 0 : -TRANSLATE_Y * scale;
|
||||
this.__viewPortLeft = -TRANSLATE_X * scale;
|
||||
this.__viewPortWidth = realViewPortWidth;
|
||||
this.__viewPortHeight = realViewPortHeight;
|
||||
viewStyle.top = this.__viewPortTop + "px";
|
||||
viewStyle.left = this.__viewPortLeft + "px";
|
||||
viewStyle.width = realViewPortWidth + "px";
|
||||
viewStyle.height = realViewPortHeight + "px";
|
||||
};
|
||||
// 预览视窗
|
||||
MiniMap.prototype.__createViewPort = function () {
|
||||
var div = document.createElement('div');
|
||||
div.className = 'lf-minimap-viewport';
|
||||
div.addEventListener('mousedown', this.__startDrag);
|
||||
this.__viewport = div;
|
||||
};
|
||||
MiniMap.pluginName = 'miniMap';
|
||||
return MiniMap;
|
||||
}());
|
||||
exports.MiniMap = MiniMap;
|
||||
exports.default = MiniMap;
|
||||
@@ -0,0 +1,130 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SelectionSelect = void 0;
|
||||
var SelectionSelect = /** @class */ (function () {
|
||||
function SelectionSelect(_a) {
|
||||
var _this = this;
|
||||
var lf = _a.lf;
|
||||
this.__disabled = false;
|
||||
this.isDefalutStopMoveGraph = false;
|
||||
this.isWholeNode = true;
|
||||
this.isWholeEdge = true;
|
||||
this.__draw = function (ev) {
|
||||
var _a = _this.lf.getPointByClient(ev.clientX, ev.clientY).domOverlayPosition, x1 = _a.x, y1 = _a.y;
|
||||
_this.endPoint = { x: x1, y: y1 };
|
||||
var _b = _this.startPoint, x = _b.x, y = _b.y;
|
||||
var style = _this.wrapper.style;
|
||||
var left = x;
|
||||
var top = y;
|
||||
var width = x1 - x;
|
||||
var height = y1 - y;
|
||||
if (x1 < x) {
|
||||
left = x1;
|
||||
width = x - x1;
|
||||
}
|
||||
if (y1 < y) {
|
||||
top = y1;
|
||||
height = y - y1;
|
||||
}
|
||||
style.left = left + "px";
|
||||
style.top = top + "px";
|
||||
style.width = width + "px";
|
||||
style.height = height + "px";
|
||||
};
|
||||
this.__drawOff = function () {
|
||||
document.removeEventListener('mousemove', _this.__draw);
|
||||
document.removeEventListener('mouseup', _this.__drawOff);
|
||||
_this.__domContainer.removeChild(_this.wrapper);
|
||||
var _a = _this.startPoint, x = _a.x, y = _a.y;
|
||||
var _b = _this.endPoint, x1 = _b.x, y1 = _b.y;
|
||||
// 选区太小的情况就忽略
|
||||
if (Math.abs(x1 - x) < 10 && Math.abs(y1 - y) < 10) {
|
||||
return;
|
||||
}
|
||||
var lt = [Math.min(x, x1), Math.min(y, y1)];
|
||||
var rt = [Math.max(x, x1), Math.max(y, y1)];
|
||||
var elements = _this.lf.getAreaElement(lt, rt, _this.isWholeEdge, _this.isWholeNode);
|
||||
elements.forEach(function (element) {
|
||||
_this.lf.selectElementById(element.id, true);
|
||||
});
|
||||
_this.lf.emit('selection:selected', elements);
|
||||
};
|
||||
this.lf = lf;
|
||||
// 初始化isDefalutStopMoveGraph取值
|
||||
var stopMoveGraph = lf.getEditConfig().stopMoveGraph;
|
||||
this.isDefalutStopMoveGraph = stopMoveGraph;
|
||||
lf.openSelectionSelect = function () {
|
||||
_this.openSelectionSelect();
|
||||
};
|
||||
lf.closeSelectionSelect = function () {
|
||||
_this.closeSelectionSelect();
|
||||
};
|
||||
}
|
||||
SelectionSelect.prototype.render = function (lf, domContainer) {
|
||||
var _this = this;
|
||||
this.__domContainer = domContainer;
|
||||
lf.on('blank:mousedown', function (_a) {
|
||||
var e = _a.e;
|
||||
var config = lf.getEditConfig();
|
||||
// 鼠标控制滚动移动画布的时候,不能选区。
|
||||
if (!config.stopMoveGraph || _this.__disabled) {
|
||||
return;
|
||||
}
|
||||
var _b = lf.getPointByClient(e.clientX, e.clientY).domOverlayPosition, x = _b.x, y = _b.y;
|
||||
_this.startPoint = { x: x, y: y };
|
||||
_this.endPoint = { x: x, y: y };
|
||||
var wrapper = document.createElement('div');
|
||||
wrapper.className = 'lf-selection-select';
|
||||
wrapper.style.top = _this.startPoint.y + "px";
|
||||
wrapper.style.left = _this.startPoint.x + "px";
|
||||
domContainer.appendChild(wrapper);
|
||||
_this.wrapper = wrapper;
|
||||
document.addEventListener('mousemove', _this.__draw);
|
||||
document.addEventListener('mouseup', _this.__drawOff);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 设置选中的灵敏度
|
||||
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
|
||||
* @param isWholeNode 是否要节点的全部点都在选区范围才算选中。默认true
|
||||
*/
|
||||
SelectionSelect.prototype.setSelectionSense = function (isWholeEdge, isWholeNode) {
|
||||
if (isWholeEdge === void 0) { isWholeEdge = true; }
|
||||
if (isWholeNode === void 0) { isWholeNode = true; }
|
||||
this.isWholeEdge = isWholeEdge;
|
||||
this.isWholeNode = isWholeNode;
|
||||
};
|
||||
/**
|
||||
* 开启选区
|
||||
*/
|
||||
SelectionSelect.prototype.openSelectionSelect = function () {
|
||||
var stopMoveGraph = this.lf.getEditConfig().stopMoveGraph;
|
||||
if (!stopMoveGraph) {
|
||||
this.isDefalutStopMoveGraph = false;
|
||||
this.lf.updateEditConfig({
|
||||
stopMoveGraph: true,
|
||||
});
|
||||
}
|
||||
this.open();
|
||||
};
|
||||
/**
|
||||
* 关闭选区
|
||||
*/
|
||||
SelectionSelect.prototype.closeSelectionSelect = function () {
|
||||
if (!this.isDefalutStopMoveGraph) {
|
||||
this.lf.updateEditConfig({
|
||||
stopMoveGraph: false,
|
||||
});
|
||||
}
|
||||
this.close();
|
||||
};
|
||||
SelectionSelect.prototype.open = function () {
|
||||
this.__disabled = false;
|
||||
};
|
||||
SelectionSelect.prototype.close = function () {
|
||||
this.__disabled = true;
|
||||
};
|
||||
SelectionSelect.pluginName = 'selectionSelect';
|
||||
return SelectionSelect;
|
||||
}());
|
||||
exports.SelectionSelect = SelectionSelect;
|
||||
Reference in new issue
Block a user