@logicflow/core 2.0.9 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$dev.log +2 -2
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +16 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.js +14 -1
- package/es/event/eventEmitter.d.ts +1 -0
- package/es/event/eventEmitter.js +3 -0
- package/es/history/index.d.ts +1 -0
- package/es/history/index.js +6 -0
- package/es/keyboard/index.d.ts +1 -0
- package/es/keyboard/index.js +3 -0
- package/es/model/EditConfigModel.d.ts +3 -1
- package/es/model/EditConfigModel.js +5 -0
- package/es/model/GraphModel.d.ts +13 -1
- package/es/model/GraphModel.js +41 -41
- package/es/model/edge/BaseEdgeModel.js +6 -3
- package/es/model/edge/PolylineEdgeModel.d.ts +1 -0
- package/es/model/edge/PolylineEdgeModel.js +7 -0
- package/es/model/node/BaseNodeModel.js +3 -2
- package/es/tool/index.d.ts +1 -0
- package/es/tool/index.js +4 -0
- package/es/util/geometry.d.ts +1 -1
- package/es/util/geometry.js +4 -1
- package/es/view/Graph.js +19 -2
- package/es/view/behavior/dnd.js +3 -2
- package/es/view/edge/BaseEdge.js +9 -2
- package/es/view/node/BaseNode.js +19 -6
- package/es/view/node/HtmlNode.js +1 -0
- package/es/view/overlay/CanvasOverlay.js +6 -4
- package/es/view/text/BaseText.js +1 -0
- package/lib/LogicFlow.js +13 -0
- package/lib/event/eventEmitter.d.ts +1 -0
- package/lib/event/eventEmitter.js +3 -0
- package/lib/history/index.d.ts +1 -0
- package/lib/history/index.js +6 -0
- package/lib/keyboard/index.d.ts +1 -0
- package/lib/keyboard/index.js +3 -0
- package/lib/model/EditConfigModel.d.ts +3 -1
- package/lib/model/EditConfigModel.js +5 -0
- package/lib/model/GraphModel.d.ts +13 -1
- package/lib/model/GraphModel.js +40 -40
- package/lib/model/edge/BaseEdgeModel.js +6 -3
- package/lib/model/edge/PolylineEdgeModel.d.ts +1 -0
- package/lib/model/edge/PolylineEdgeModel.js +7 -0
- package/lib/model/node/BaseNodeModel.js +3 -2
- package/lib/tool/index.d.ts +1 -0
- package/lib/tool/index.js +4 -0
- package/lib/util/geometry.d.ts +1 -1
- package/lib/util/geometry.js +4 -1
- package/lib/view/Graph.js +19 -2
- package/lib/view/behavior/dnd.js +3 -2
- package/lib/view/edge/BaseEdge.js +9 -2
- package/lib/view/node/BaseNode.js +19 -6
- package/lib/view/node/HtmlNode.js +1 -0
- package/lib/view/overlay/CanvasOverlay.js +6 -4
- package/lib/view/text/BaseText.js +1 -0
- package/package.json +1 -1
- package/src/LogicFlow.tsx +19 -1
- package/src/event/eventEmitter.ts +4 -0
- package/src/history/index.ts +7 -0
- package/src/keyboard/index.ts +4 -0
- package/src/model/EditConfigModel.ts +4 -0
- package/src/model/GraphModel.ts +62 -70
- package/src/model/edge/BaseEdgeModel.ts +7 -2
- package/src/model/edge/PolylineEdgeModel.ts +8 -0
- package/src/model/node/BaseNodeModel.ts +5 -2
- package/src/tool/index.ts +5 -0
- package/src/util/geometry.ts +3 -1
- package/src/view/Graph.tsx +19 -2
- package/src/view/behavior/dnd.ts +5 -2
- package/src/view/edge/BaseEdge.tsx +9 -2
- package/src/view/node/BaseNode.tsx +20 -6
- package/src/view/node/HtmlNode.tsx +1 -0
- package/src/view/overlay/CanvasOverlay.tsx +6 -5
- package/src/view/text/BaseText.tsx +1 -0
- package/stats.html +1 -1
package/es/LogicFlow.js
CHANGED
|
@@ -36,7 +36,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
36
36
|
};
|
|
37
37
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
38
38
|
import { createElement as h, render } from 'preact/compat';
|
|
39
|
-
import { cloneDeep, forEach, indexOf } from 'lodash-es';
|
|
39
|
+
import { cloneDeep, forEach, indexOf, isNil } from 'lodash-es';
|
|
40
40
|
import { observer } from '.';
|
|
41
41
|
import { Options as LFOptions } from './options';
|
|
42
42
|
import * as _Model from './model';
|
|
@@ -777,12 +777,18 @@ var LogicFlow = /** @class */ (function () {
|
|
|
777
777
|
*/
|
|
778
778
|
LogicFlow.prototype.updateEditConfig = function (config) {
|
|
779
779
|
var _a = this.graphModel, editConfigModel = _a.editConfigModel, transformModel = _a.transformModel;
|
|
780
|
+
var currentSnapGrid = editConfigModel.snapGrid;
|
|
780
781
|
editConfigModel.updateEditConfig(config);
|
|
781
782
|
if ((config === null || config === void 0 ? void 0 : config.stopMoveGraph) !== undefined) {
|
|
782
783
|
transformModel.updateTranslateLimits(config.stopMoveGraph);
|
|
783
784
|
}
|
|
784
785
|
// 静默模式切换时,修改快捷键的启用状态
|
|
785
786
|
(config === null || config === void 0 ? void 0 : config.isSilentMode) ? this.keyboard.disable() : this.keyboard.enable(true);
|
|
787
|
+
// 切换网格对齐状态时,修改网格尺寸
|
|
788
|
+
if (!isNil(config === null || config === void 0 ? void 0 : config.snapGrid) && config.snapGrid !== currentSnapGrid) {
|
|
789
|
+
var _b = this.graphModel.grid.size, size = _b === void 0 ? 1 : _b;
|
|
790
|
+
this.graphModel.updateGridSize(config.snapGrid ? size : 1);
|
|
791
|
+
}
|
|
786
792
|
};
|
|
787
793
|
/**
|
|
788
794
|
* 获取流程图当前编辑相关设置
|
|
@@ -907,6 +913,8 @@ var LogicFlow = /** @class */ (function () {
|
|
|
907
913
|
*/
|
|
908
914
|
LogicFlow.prototype.clearData = function () {
|
|
909
915
|
this.graphModel.clearData();
|
|
916
|
+
// 强制刷新数据, 让 preact 清除对已删除节点的引用
|
|
917
|
+
this.render({});
|
|
910
918
|
};
|
|
911
919
|
/*********************************************************
|
|
912
920
|
* LogicFlow Render方法
|
|
@@ -1168,7 +1176,12 @@ var LogicFlow = /** @class */ (function () {
|
|
|
1168
1176
|
};
|
|
1169
1177
|
/** 销毁当前实例 */
|
|
1170
1178
|
LogicFlow.prototype.destroy = function () {
|
|
1179
|
+
this.clearData();
|
|
1180
|
+
render(null, this.container);
|
|
1181
|
+
this.keyboard.destroy();
|
|
1171
1182
|
this.graphModel.destroy();
|
|
1183
|
+
this.tool.destroy();
|
|
1184
|
+
this.history.destroy();
|
|
1172
1185
|
};
|
|
1173
1186
|
// 全局配置的插件,所有的LogicFlow示例都会使用
|
|
1174
1187
|
LogicFlow.extensions = new Map();
|
|
@@ -44,5 +44,6 @@ export default class EventEmitter {
|
|
|
44
44
|
off<T extends keyof EventArgs>(evts: T, callback?: (args: EventArgs[T]) => void): void;
|
|
45
45
|
off<T extends string>(evts: T, callback?: EventCallback<T>): void;
|
|
46
46
|
getEvents(): EventsType<string>;
|
|
47
|
+
destroy(): void;
|
|
47
48
|
}
|
|
48
49
|
export { EventEmitter, EventArgs };
|
package/es/event/eventEmitter.js
CHANGED
|
@@ -84,6 +84,9 @@ var EventEmitter = /** @class */ (function () {
|
|
|
84
84
|
EventEmitter.prototype.getEvents = function () {
|
|
85
85
|
return this._events;
|
|
86
86
|
};
|
|
87
|
+
EventEmitter.prototype.destroy = function () {
|
|
88
|
+
this._events = {};
|
|
89
|
+
};
|
|
87
90
|
return EventEmitter;
|
|
88
91
|
}());
|
|
89
92
|
export default EventEmitter;
|
package/es/history/index.d.ts
CHANGED
package/es/history/index.js
CHANGED
|
@@ -104,6 +104,12 @@ var History = /** @class */ (function () {
|
|
|
104
104
|
}
|
|
105
105
|
}, this.waitTime));
|
|
106
106
|
};
|
|
107
|
+
History.prototype.destroy = function () {
|
|
108
|
+
this.undos = [];
|
|
109
|
+
this.redos = [];
|
|
110
|
+
this.curData = null;
|
|
111
|
+
this.stopWatch && this.stopWatch();
|
|
112
|
+
};
|
|
107
113
|
return History;
|
|
108
114
|
}());
|
|
109
115
|
export { History };
|
package/es/keyboard/index.d.ts
CHANGED
package/es/keyboard/index.js
CHANGED
|
@@ -68,6 +68,9 @@ var Keyboard = /** @class */ (function () {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
+
Keyboard.prototype.destroy = function () {
|
|
72
|
+
this.mousetrap.reset();
|
|
73
|
+
};
|
|
71
74
|
Keyboard.prototype.getKeys = function (keys) {
|
|
72
75
|
var _this = this;
|
|
73
76
|
return (Array.isArray(keys) ? keys : [keys]).map(function (key) {
|
|
@@ -113,6 +113,7 @@ export interface IEditConfigType {
|
|
|
113
113
|
textMode: TextMode;
|
|
114
114
|
nodeTextMode: TextMode;
|
|
115
115
|
edgeTextMode: TextMode;
|
|
116
|
+
snapGrid: boolean;
|
|
116
117
|
}
|
|
117
118
|
export type IConfigKeys = keyof IEditConfigType;
|
|
118
119
|
/**
|
|
@@ -127,6 +128,7 @@ export declare class EditConfigModel {
|
|
|
127
128
|
stopZoomGraph: boolean;
|
|
128
129
|
stopMoveGraph: boolean;
|
|
129
130
|
stopScrollGraph: boolean;
|
|
131
|
+
snapGrid: boolean;
|
|
130
132
|
/*********************************************************
|
|
131
133
|
* 文本相关配置(全局)
|
|
132
134
|
********************************************************/
|
|
@@ -168,7 +170,7 @@ export declare class EditConfigModel {
|
|
|
168
170
|
multipleSelectKey: string;
|
|
169
171
|
constructor(config: Partial<IEditConfigType>);
|
|
170
172
|
updateEditConfig(config: Partial<IEditConfigType>): void;
|
|
171
|
-
computeConfig(config: Partial<IEditConfigType>): Partial<IEditConfigType> & Pick<Partial<IEditConfigType>, "textMode" | "adjustEdgeStartAndEnd" | "
|
|
173
|
+
computeConfig(config: Partial<IEditConfigType>): Partial<IEditConfigType> & Pick<Partial<IEditConfigType>, "textMode" | "adjustEdgeStartAndEnd" | "edgeTextDraggable" | "edgeTextEdit" | "nodeTextDraggable" | "nodeTextEdit" | "isSilentMode" | "stopZoomGraph" | "stopScrollGraph" | "stopMoveGraph" | "snapGrid" | "adjustEdge" | "adjustEdgeMiddle" | "adjustEdgeStart" | "adjustEdgeEnd" | "adjustNodePosition" | "hideAnchors" | "allowRotate" | "allowResize" | "autoExpand" | "hoverOutline" | "nodeSelectedOutline" | "edgeSelectedOutline" | "textEdit" | "textDraggable" | "multipleSelectKey" | "nodeTextMode" | "edgeTextMode" | "nodeTextMultiple" | "edgeTextMultiple" | "nodeTextVertical" | "edgeTextVertical">;
|
|
172
174
|
updateTextMode(textMode: TextMode): void;
|
|
173
175
|
getConfig(): IEditConfigType;
|
|
174
176
|
}
|
|
@@ -33,6 +33,7 @@ var allKeys = [
|
|
|
33
33
|
'stopZoomGraph', // 禁止缩放画布
|
|
34
34
|
'stopScrollGraph', // 禁止鼠标滚动移动画布
|
|
35
35
|
'stopMoveGraph', // 禁止拖动画布
|
|
36
|
+
'snapGrid', // 是否开启网格对齐
|
|
36
37
|
'adjustEdge', // 允许调整边
|
|
37
38
|
'adjustEdgeMiddle', // 允许调整边中点
|
|
38
39
|
'adjustEdgeStartAndEnd', // 允许调整边起点和终点
|
|
@@ -74,6 +75,7 @@ var EditConfigModel = /** @class */ (function () {
|
|
|
74
75
|
this.stopZoomGraph = false;
|
|
75
76
|
this.stopMoveGraph = false;
|
|
76
77
|
this.stopScrollGraph = false;
|
|
78
|
+
this.snapGrid = false;
|
|
77
79
|
/*********************************************************
|
|
78
80
|
* 文本相关配置(全局)
|
|
79
81
|
********************************************************/
|
|
@@ -188,6 +190,9 @@ var EditConfigModel = /** @class */ (function () {
|
|
|
188
190
|
__decorate([
|
|
189
191
|
observable
|
|
190
192
|
], EditConfigModel.prototype, "stopScrollGraph", void 0);
|
|
193
|
+
__decorate([
|
|
194
|
+
observable
|
|
195
|
+
], EditConfigModel.prototype, "snapGrid", void 0);
|
|
191
196
|
__decorate([
|
|
192
197
|
observable
|
|
193
198
|
], EditConfigModel.prototype, "textMode", void 0);
|
package/es/model/GraphModel.d.ts
CHANGED
|
@@ -46,6 +46,14 @@ export declare class GraphModel {
|
|
|
46
46
|
* 获取自定义连线轨迹
|
|
47
47
|
*/
|
|
48
48
|
customTrajectory: LFOptions.Definition['customTrajectory'];
|
|
49
|
+
/**
|
|
50
|
+
* 判断是否使用的是容器的宽度
|
|
51
|
+
*/
|
|
52
|
+
isContainerWidth: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 判断是否使用的是容器的高度
|
|
55
|
+
*/
|
|
56
|
+
isContainerHeight: boolean;
|
|
49
57
|
edgeType: string;
|
|
50
58
|
nodes: BaseNodeModel[];
|
|
51
59
|
edges: BaseEdgeModel[];
|
|
@@ -391,7 +399,11 @@ export declare class GraphModel {
|
|
|
391
399
|
*/
|
|
392
400
|
updateGridOptions(options: Partial<Grid.GridOptions>): void;
|
|
393
401
|
/**
|
|
394
|
-
*
|
|
402
|
+
* 更新网格尺寸
|
|
403
|
+
*/
|
|
404
|
+
updateGridSize(size: number): void;
|
|
405
|
+
/**
|
|
406
|
+
* 更新背景配置
|
|
395
407
|
*/
|
|
396
408
|
updateBackgroundOptions(options: boolean | Partial<LFOptions.BackgroundConfig>): void;
|
|
397
409
|
/**
|
package/es/model/GraphModel.js
CHANGED
|
@@ -51,7 +51,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
51
51
|
}
|
|
52
52
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
53
53
|
};
|
|
54
|
-
import { find, forEach, map, merge, isBoolean, debounce,
|
|
54
|
+
import { find, forEach, map, merge, isBoolean, debounce, isNil, } from 'lodash-es';
|
|
55
55
|
import { action, computed, observable } from 'mobx';
|
|
56
56
|
import { EditConfigModel, TransformModel, } from '.';
|
|
57
57
|
import { DEFAULT_VISIBLE_SPACE, ELEMENT_MAX_Z_INDEX, ElementState, ElementType, EventType, ModelType, OverlapMode, TextMode, } from '../constant';
|
|
@@ -61,6 +61,7 @@ import { Grid } from '../view/overlay';
|
|
|
61
61
|
var GraphModel = /** @class */ (function () {
|
|
62
62
|
function GraphModel(options) {
|
|
63
63
|
var _this = this;
|
|
64
|
+
var _a, _b;
|
|
64
65
|
// 维护所有节点和边类型对应的 model
|
|
65
66
|
this.modelMap = new Map();
|
|
66
67
|
// Remind:用于记录当前画布上所有节点和边的 model 的 Map
|
|
@@ -94,11 +95,13 @@ var GraphModel = /** @class */ (function () {
|
|
|
94
95
|
// 控制是否开启局部渲染
|
|
95
96
|
this.partial = false;
|
|
96
97
|
this.waitCleanEffects = [];
|
|
97
|
-
var container = options.container, partial = options.partial,
|
|
98
|
+
var container = options.container, partial = options.partial, _c = options.background, background = _c === void 0 ? {} : _c, grid = options.grid, idGenerator = options.idGenerator, edgeGenerator = options.edgeGenerator, animation = options.animation, customTrajectory = options.customTrajectory;
|
|
98
99
|
this.rootEl = container;
|
|
99
100
|
this.partial = !!partial;
|
|
100
101
|
this.background = background;
|
|
101
|
-
if (typeof grid === 'object') {
|
|
102
|
+
if (typeof grid === 'object' && options.snapGrid) {
|
|
103
|
+
// 开启网格对齐时才根据网格尺寸设置步长
|
|
104
|
+
// TODO:需要让用户设置成 0 吗?后面可以讨论一下
|
|
102
105
|
this.gridSize = grid.size || 1; // 默认 gridSize 设置为 1
|
|
103
106
|
}
|
|
104
107
|
this.theme = setupTheme(options.style);
|
|
@@ -106,8 +109,10 @@ var GraphModel = /** @class */ (function () {
|
|
|
106
109
|
this.edgeType = options.edgeType || 'polyline';
|
|
107
110
|
this.animation = setupAnimation(animation);
|
|
108
111
|
this.overlapMode = options.overlapMode || OverlapMode.DEFAULT;
|
|
109
|
-
this.width = options.width
|
|
110
|
-
this.
|
|
112
|
+
this.width = (_a = options.width) !== null && _a !== void 0 ? _a : this.rootEl.getBoundingClientRect().width;
|
|
113
|
+
this.isContainerWidth = isNil(options.width);
|
|
114
|
+
this.height = (_b = options.height) !== null && _b !== void 0 ? _b : this.rootEl.getBoundingClientRect().height;
|
|
115
|
+
this.isContainerHeight = isNil(options.height);
|
|
111
116
|
var resizeObserver = new ResizeObserver(debounce((function (entries) {
|
|
112
117
|
var e_1, _a;
|
|
113
118
|
try {
|
|
@@ -389,17 +394,23 @@ var GraphModel = /** @class */ (function () {
|
|
|
389
394
|
*/
|
|
390
395
|
GraphModel.prototype.graphDataToModel = function (graphData) {
|
|
391
396
|
var _this = this;
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
397
|
+
// 宽度必然存在,取消重新计算
|
|
398
|
+
// if (!this.width || !this.height) {
|
|
399
|
+
// this.resize()
|
|
400
|
+
// }
|
|
395
401
|
if (!graphData) {
|
|
396
|
-
this.
|
|
397
|
-
this.edges = [];
|
|
402
|
+
this.clearData();
|
|
398
403
|
return;
|
|
399
404
|
}
|
|
405
|
+
this.elementsModelMap.clear();
|
|
406
|
+
this.nodeModelMap.clear();
|
|
407
|
+
this.edgeModelMap.clear();
|
|
400
408
|
if (graphData.nodes) {
|
|
401
409
|
this.nodes = map(graphData.nodes, function (node) {
|
|
402
|
-
|
|
410
|
+
var nodeModel = _this.getModelAfterSnapToGrid(node);
|
|
411
|
+
_this.elementsModelMap.set(nodeModel.id, nodeModel);
|
|
412
|
+
_this.nodeModelMap.set(nodeModel.id, nodeModel);
|
|
413
|
+
return nodeModel;
|
|
403
414
|
});
|
|
404
415
|
}
|
|
405
416
|
else {
|
|
@@ -414,31 +425,6 @@ var GraphModel = /** @class */ (function () {
|
|
|
414
425
|
throw new Error("\u627E\u4E0D\u5230".concat(edge.type, "\u5BF9\u5E94\u7684\u8FB9\u3002"));
|
|
415
426
|
}
|
|
416
427
|
var edgeModel = new Model(edge, _this);
|
|
417
|
-
// 根据edgeModel中存储的数据找到当前画布上的起终锚点坐标
|
|
418
|
-
// 判断当前起终锚点数据和Model中存储的起终点数据是否一致,不一致更新起终点信息
|
|
419
|
-
var sourceNodeId = edgeModel.sourceNodeId, targetNodeId = edgeModel.targetNodeId, _b = edgeModel.sourceAnchorId, sourceAnchorId = _b === void 0 ? '' : _b, _c = edgeModel.targetAnchorId, targetAnchorId = _c === void 0 ? '' : _c, startPoint = edgeModel.startPoint, endPoint = edgeModel.endPoint, text = edgeModel.text, textPosition = edgeModel.textPosition;
|
|
420
|
-
var updateAnchorPoint = function (node, anchorId, point, updatePoint) {
|
|
421
|
-
var anchor = node === null || node === void 0 ? void 0 : node.anchors.find(function (anchor) { return anchor.id === anchorId; });
|
|
422
|
-
if (anchor && !isEqual(anchor, point)) {
|
|
423
|
-
updatePoint(anchor);
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
var sourceNode = _this.getNodeModelById(sourceNodeId);
|
|
427
|
-
var targetNode = _this.getNodeModelById(targetNodeId);
|
|
428
|
-
updateAnchorPoint(sourceNode, sourceAnchorId, startPoint, edgeModel.updateStartPoint.bind(edgeModel));
|
|
429
|
-
updateAnchorPoint(targetNode, targetAnchorId, endPoint, edgeModel.updateEndPoint.bind(edgeModel));
|
|
430
|
-
// 而文本需要先算一下文本与默认文本位置之间的相对位置差
|
|
431
|
-
// 再计算新路径的文本默认位置,加上相对位置差,得到调整后边的文本的位置
|
|
432
|
-
if (text) {
|
|
433
|
-
var x = text.x, y = text.y;
|
|
434
|
-
var defaultX = textPosition.x, defaultY = textPosition.y;
|
|
435
|
-
if (x && y && defaultX && defaultY) {
|
|
436
|
-
var deltaX = x - defaultX;
|
|
437
|
-
var deltaY = y - defaultY;
|
|
438
|
-
edgeModel.resetTextPosition();
|
|
439
|
-
edgeModel.moveText(deltaX, deltaY);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
428
|
_this.edgeModelMap.set(edgeModel.id, edgeModel);
|
|
443
429
|
_this.elementsModelMap.set(edgeModel.id, edgeModel);
|
|
444
430
|
return edgeModel;
|
|
@@ -772,14 +758,15 @@ var GraphModel = /** @class */ (function () {
|
|
|
772
758
|
*/
|
|
773
759
|
GraphModel.prototype.getModelAfterSnapToGrid = function (node) {
|
|
774
760
|
var Model = this.getModel(node.type);
|
|
761
|
+
var snapGrid = this.editConfigModel.snapGrid;
|
|
775
762
|
if (!Model) {
|
|
776
763
|
throw new Error("\u627E\u4E0D\u5230".concat(node.type, "\u5BF9\u5E94\u7684\u8282\u70B9\uFF0C\u8BF7\u786E\u8BA4\u662F\u5426\u5DF2\u6CE8\u518C\u6B64\u7C7B\u578B\u8282\u70B9\u3002"));
|
|
777
764
|
}
|
|
778
765
|
var nodeX = node.x, nodeY = node.y;
|
|
779
766
|
// 根据 grid 修正节点的 x, y
|
|
780
767
|
if (nodeX && nodeY) {
|
|
781
|
-
node.x = snapToGrid(nodeX, this.gridSize);
|
|
782
|
-
node.y = snapToGrid(nodeY, this.gridSize);
|
|
768
|
+
node.x = snapToGrid(nodeX, this.gridSize, snapGrid);
|
|
769
|
+
node.y = snapToGrid(nodeY, this.gridSize, snapGrid);
|
|
783
770
|
if (typeof node.text === 'object' && node.text !== null) {
|
|
784
771
|
// 原来的处理是:node.text.x -= getGridOffset(nodeX, this.gridSize)
|
|
785
772
|
// 由于snapToGrid()使用了Math.round()四舍五入的做法,因此无法判断需要执行
|
|
@@ -1315,7 +1302,13 @@ var GraphModel = /** @class */ (function () {
|
|
|
1315
1302
|
merge(this.grid, options);
|
|
1316
1303
|
};
|
|
1317
1304
|
/**
|
|
1318
|
-
*
|
|
1305
|
+
* 更新网格尺寸
|
|
1306
|
+
*/
|
|
1307
|
+
GraphModel.prototype.updateGridSize = function (size) {
|
|
1308
|
+
this.gridSize = size;
|
|
1309
|
+
};
|
|
1310
|
+
/**
|
|
1311
|
+
* 更新背景配置
|
|
1319
1312
|
*/
|
|
1320
1313
|
GraphModel.prototype.updateBackgroundOptions = function (options) {
|
|
1321
1314
|
if (isBoolean(options) || isBoolean(this.background)) {
|
|
@@ -1329,8 +1322,10 @@ var GraphModel = /** @class */ (function () {
|
|
|
1329
1322
|
* 重新设置画布的宽高
|
|
1330
1323
|
*/
|
|
1331
1324
|
GraphModel.prototype.resize = function (width, height) {
|
|
1332
|
-
this.width = width
|
|
1333
|
-
this.
|
|
1325
|
+
this.width = width !== null && width !== void 0 ? width : this.rootEl.getBoundingClientRect().width;
|
|
1326
|
+
this.isContainerWidth = isNil(width);
|
|
1327
|
+
this.height = height !== null && height !== void 0 ? height : this.rootEl.getBoundingClientRect().height;
|
|
1328
|
+
this.isContainerHeight = isNil(height);
|
|
1334
1329
|
if (!this.width || !this.height) {
|
|
1335
1330
|
console.warn('渲染画布的时候无法获取画布宽高,请确认在container已挂载到DOM。@see https://github.com/didi/LogicFlow/issues/675');
|
|
1336
1331
|
}
|
|
@@ -1341,6 +1336,10 @@ var GraphModel = /** @class */ (function () {
|
|
|
1341
1336
|
GraphModel.prototype.clearData = function () {
|
|
1342
1337
|
this.nodes = [];
|
|
1343
1338
|
this.edges = [];
|
|
1339
|
+
// 清除对已清除节点的引用
|
|
1340
|
+
this.edgeModelMap.clear();
|
|
1341
|
+
this.nodeModelMap.clear();
|
|
1342
|
+
this.elementsModelMap.clear();
|
|
1344
1343
|
};
|
|
1345
1344
|
/**
|
|
1346
1345
|
* 获取图形区域虚拟矩型的尺寸和中心坐标
|
|
@@ -1457,6 +1456,7 @@ var GraphModel = /** @class */ (function () {
|
|
|
1457
1456
|
console.warn('error on destroy GraphModel', err);
|
|
1458
1457
|
}
|
|
1459
1458
|
this.waitCleanEffects.length = 0;
|
|
1459
|
+
this.eventCenter.destroy();
|
|
1460
1460
|
};
|
|
1461
1461
|
__decorate([
|
|
1462
1462
|
observable
|
|
@@ -317,6 +317,8 @@ var BaseEdgeModel = /** @class */ (function () {
|
|
|
317
317
|
properties: properties,
|
|
318
318
|
sourceNodeId: this.sourceNodeId,
|
|
319
319
|
targetNodeId: this.targetNodeId,
|
|
320
|
+
sourceAnchorId: this.sourceAnchorId,
|
|
321
|
+
targetAnchorId: this.targetAnchorId,
|
|
320
322
|
startPoint: assign({}, this.startPoint),
|
|
321
323
|
endPoint: assign({}, this.endPoint),
|
|
322
324
|
};
|
|
@@ -416,14 +418,15 @@ var BaseEdgeModel = /** @class */ (function () {
|
|
|
416
418
|
*/
|
|
417
419
|
BaseEdgeModel.prototype.formatText = function (data) {
|
|
418
420
|
var _a, _b, _c;
|
|
419
|
-
var _d = this.
|
|
421
|
+
var _d = this.graphModel.editConfigModel, edgeTextDraggable = _d.edgeTextDraggable, edgeTextEdit = _d.edgeTextEdit;
|
|
422
|
+
var _e = this.textPosition, x = _e.x, y = _e.y;
|
|
420
423
|
var text = data.text;
|
|
421
424
|
var textConfig = {
|
|
422
425
|
value: '',
|
|
423
426
|
x: x,
|
|
424
427
|
y: y,
|
|
425
|
-
draggable:
|
|
426
|
-
editable:
|
|
428
|
+
draggable: edgeTextDraggable,
|
|
429
|
+
editable: edgeTextEdit,
|
|
427
430
|
};
|
|
428
431
|
if (text) {
|
|
429
432
|
if (typeof text === 'string') {
|
|
@@ -33,6 +33,7 @@ export declare class PolylineEdgeModel extends BaseEdgeModel {
|
|
|
33
33
|
removeCrossPoints(startIndex: number, endIndex: number, pointList: Point[]): LogicFlow.Point[];
|
|
34
34
|
getDraggingPoints(direction: SegmentDirection, positionType: string, position: Position, anchorList: AnchorConfig[], draggingPointList: Point[]): LogicFlow.Point[];
|
|
35
35
|
updateCrossPoints(pointList: Point[]): LogicFlow.Point[];
|
|
36
|
+
updatePath(pointList: Point[]): void;
|
|
36
37
|
getData(): LogicFlow.EdgeData & {
|
|
37
38
|
pointsList: {
|
|
38
39
|
x: number;
|
|
@@ -70,6 +70,9 @@ var PolylineEdgeModel = /** @class */ (function (_super) {
|
|
|
70
70
|
}
|
|
71
71
|
PolylineEdgeModel.prototype.initEdgeData = function (data) {
|
|
72
72
|
this.offset = 30;
|
|
73
|
+
if (data.pointsList) {
|
|
74
|
+
this.pointsList = data.pointsList;
|
|
75
|
+
}
|
|
73
76
|
_super.prototype.initEdgeData.call(this, data);
|
|
74
77
|
};
|
|
75
78
|
PolylineEdgeModel.prototype.getEdgeStyle = function () {
|
|
@@ -282,6 +285,10 @@ var PolylineEdgeModel = /** @class */ (function (_super) {
|
|
|
282
285
|
}
|
|
283
286
|
return list;
|
|
284
287
|
};
|
|
288
|
+
PolylineEdgeModel.prototype.updatePath = function (pointList) {
|
|
289
|
+
this.pointsList = pointList;
|
|
290
|
+
this.points = this.getPath(this.pointsList);
|
|
291
|
+
};
|
|
285
292
|
PolylineEdgeModel.prototype.getData = function () {
|
|
286
293
|
var data = _super.prototype.getData.call(this);
|
|
287
294
|
var pointsList = this.pointsList.map(function (_a) {
|
|
@@ -223,13 +223,14 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
223
223
|
*/
|
|
224
224
|
BaseNodeModel.prototype.formatText = function (data) {
|
|
225
225
|
var _a, _b, _c;
|
|
226
|
+
var _d = this.graphModel.editConfigModel, nodeTextDraggable = _d.nodeTextDraggable, nodeTextEdit = _d.nodeTextEdit;
|
|
226
227
|
var x = data.x, y = data.y, text = data.text;
|
|
227
228
|
var textConfig = {
|
|
228
229
|
value: '',
|
|
229
230
|
x: x,
|
|
230
231
|
y: y,
|
|
231
|
-
draggable:
|
|
232
|
-
editable:
|
|
232
|
+
draggable: nodeTextDraggable,
|
|
233
|
+
editable: nodeTextEdit,
|
|
233
234
|
};
|
|
234
235
|
if (text) {
|
|
235
236
|
if (typeof text === 'string') {
|
package/es/tool/index.d.ts
CHANGED
package/es/tool/index.js
CHANGED
|
@@ -67,6 +67,10 @@ var Tool = /** @class */ (function () {
|
|
|
67
67
|
Tool.prototype.getInstance = function () {
|
|
68
68
|
return this.instance;
|
|
69
69
|
};
|
|
70
|
+
Tool.prototype.destroy = function () {
|
|
71
|
+
this.toolMap.clear();
|
|
72
|
+
this.disabledToolMap.clear();
|
|
73
|
+
};
|
|
70
74
|
__decorate([
|
|
71
75
|
observable
|
|
72
76
|
], Tool.prototype, "toolMap", void 0);
|
package/es/util/geometry.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import LogicFlow from '../LogicFlow';
|
|
2
2
|
import PointTuple = LogicFlow.PointTuple;
|
|
3
|
-
export declare function snapToGrid(point: number, gridSize: number): number;
|
|
3
|
+
export declare function snapToGrid(point: number, gridSize: number, snapGrid: boolean): number;
|
|
4
4
|
export declare function getGridOffset(distance: number, gridSize: number): number;
|
|
5
5
|
/**
|
|
6
6
|
* 多边形设置 points 后,坐标平移至原点 并 根据 width、height 缩放
|
package/es/util/geometry.js
CHANGED
|
@@ -23,7 +23,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
23
23
|
}
|
|
24
24
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
25
|
};
|
|
26
|
-
export function snapToGrid(point, gridSize) {
|
|
26
|
+
export function snapToGrid(point, gridSize, snapGrid) {
|
|
27
|
+
// 开启节网格对齐时才根据网格尺寸校准坐标
|
|
28
|
+
if (!snapGrid)
|
|
29
|
+
return point;
|
|
27
30
|
// 保证 x, y 的值为 gridSize 的整数倍
|
|
28
31
|
return gridSize * Math.round(point / gridSize) || point;
|
|
29
32
|
}
|
package/es/view/Graph.js
CHANGED
|
@@ -55,9 +55,26 @@ var Graph = /** @class */ (function (_super) {
|
|
|
55
55
|
function Graph() {
|
|
56
56
|
var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
|
|
57
57
|
_this.handleResize = function () {
|
|
58
|
-
_this.props.graphModel.
|
|
58
|
+
var _a = _this.props, graphModel = _a.graphModel, options = _a.options;
|
|
59
|
+
var width = graphModel.width, height = graphModel.height, isContainerWidth = graphModel.isContainerWidth, isContainerHeight = graphModel.isContainerHeight;
|
|
60
|
+
var resizeWidth = width;
|
|
61
|
+
var resizeHeight = height;
|
|
62
|
+
var needUpdate = false;
|
|
63
|
+
if (isContainerWidth) {
|
|
64
|
+
resizeWidth = undefined;
|
|
65
|
+
needUpdate = true;
|
|
66
|
+
}
|
|
67
|
+
if (isContainerHeight) {
|
|
68
|
+
resizeHeight = undefined;
|
|
69
|
+
needUpdate = true;
|
|
70
|
+
}
|
|
71
|
+
if (needUpdate) {
|
|
72
|
+
graphModel.resize(resizeWidth, resizeHeight);
|
|
73
|
+
}
|
|
74
|
+
options.width = width;
|
|
75
|
+
options.height = height;
|
|
59
76
|
};
|
|
60
|
-
_this.throttleResize =
|
|
77
|
+
_this.throttleResize = throttle(_this.handleResize, 200);
|
|
61
78
|
return _this;
|
|
62
79
|
}
|
|
63
80
|
Graph.prototype.componentDidMount = function () {
|
package/es/view/behavior/dnd.js
CHANGED
|
@@ -81,10 +81,11 @@ var Dnd = /** @class */ (function () {
|
|
|
81
81
|
});
|
|
82
82
|
// 处理缩放和偏移
|
|
83
83
|
var _b = position.canvasOverlayPosition, x1 = _b.x, y1 = _b.y;
|
|
84
|
+
var snapGrid = this.lf.graphModel.editConfigModel.snapGrid;
|
|
84
85
|
// x, y 对齐到网格的 size
|
|
85
86
|
return {
|
|
86
|
-
x: snapToGrid(x1, gridSize),
|
|
87
|
-
y: snapToGrid(y1, gridSize),
|
|
87
|
+
x: snapToGrid(x1, gridSize, snapGrid),
|
|
88
|
+
y: snapToGrid(y1, gridSize, snapGrid),
|
|
88
89
|
};
|
|
89
90
|
};
|
|
90
91
|
Dnd.prototype.startDrag = function (nodeConfig) {
|
package/es/view/edge/BaseEdge.js
CHANGED
|
@@ -99,12 +99,16 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
99
99
|
clearTimeout(_this.clickTimer);
|
|
100
100
|
}
|
|
101
101
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
102
|
+
var editConfigModel = graphModel.editConfigModel;
|
|
102
103
|
var position = graphModel.getPointByClient({
|
|
103
104
|
x: ev.clientX,
|
|
104
105
|
y: ev.clientY,
|
|
105
106
|
});
|
|
106
107
|
graphModel.setElementStateById(model.id, ElementState.SHOW_MENU, position.domOverlayPosition);
|
|
107
|
-
|
|
108
|
+
// 静默模式下点击节点不变更节点层级
|
|
109
|
+
if (!editConfigModel.isSilentMode) {
|
|
110
|
+
_this.toFront();
|
|
111
|
+
}
|
|
108
112
|
if (!model.isSelected) {
|
|
109
113
|
graphModel.selectEdgeById(model.id);
|
|
110
114
|
}
|
|
@@ -192,7 +196,10 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
192
196
|
}
|
|
193
197
|
var editConfigModel = graphModel.editConfigModel;
|
|
194
198
|
graphModel.selectEdgeById(model.id, isMultipleSelect(e, editConfigModel));
|
|
195
|
-
|
|
199
|
+
// 静默模式下点击节点不变更节点层级
|
|
200
|
+
if (!editConfigModel.isSilentMode) {
|
|
201
|
+
_this.toFront();
|
|
202
|
+
}
|
|
196
203
|
};
|
|
197
204
|
_this.handleFocus = function () {
|
|
198
205
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
package/es/view/node/BaseNode.js
CHANGED
|
@@ -85,7 +85,7 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
85
85
|
var _b, _c, _d, _e;
|
|
86
86
|
var event = _a.event;
|
|
87
87
|
var _f = _this.props, model = _f.model, graphModel = _f.graphModel;
|
|
88
|
-
var _g = graphModel.editConfigModel, stopMoveGraph = _g.stopMoveGraph, autoExpand = _g.autoExpand, transformModel = graphModel.transformModel, selectNodes = graphModel.selectNodes, width = graphModel.width, height = graphModel.height, gridSize = graphModel.gridSize;
|
|
88
|
+
var _g = graphModel.editConfigModel, stopMoveGraph = _g.stopMoveGraph, autoExpand = _g.autoExpand, snapGrid = _g.snapGrid, transformModel = graphModel.transformModel, selectNodes = graphModel.selectNodes, width = graphModel.width, height = graphModel.height, gridSize = graphModel.gridSize;
|
|
89
89
|
model.isDragging = true;
|
|
90
90
|
var _h = event, clientX = _h.clientX, clientY = _h.clientY;
|
|
91
91
|
var _j = graphModel.getPointByClient({
|
|
@@ -97,9 +97,9 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
97
97
|
// 2. 考虑鼠标位置不再节点中心
|
|
98
98
|
x = x + ((_c = (_b = _this.moveOffset) === null || _b === void 0 ? void 0 : _b.dx) !== null && _c !== void 0 ? _c : 0);
|
|
99
99
|
y = y + ((_e = (_d = _this.moveOffset) === null || _d === void 0 ? void 0 : _d.dy) !== null && _e !== void 0 ? _e : 0);
|
|
100
|
-
//
|
|
101
|
-
x = snapToGrid(x, gridSize);
|
|
102
|
-
y = snapToGrid(y, gridSize);
|
|
100
|
+
// 校准坐标
|
|
101
|
+
x = snapToGrid(x, gridSize, snapGrid);
|
|
102
|
+
y = snapToGrid(y, gridSize, snapGrid);
|
|
103
103
|
if (!width || !height) {
|
|
104
104
|
graphModel.moveNode2Coordinate(model.id, x, y);
|
|
105
105
|
return;
|
|
@@ -213,7 +213,10 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
213
213
|
else {
|
|
214
214
|
graphModel.selectNodeById(model.id, isMultiple);
|
|
215
215
|
eventOptions.isSelected = true;
|
|
216
|
-
|
|
216
|
+
// 静默模式下点击节点不变更节点层级
|
|
217
|
+
if (!editConfigModel.isSilentMode) {
|
|
218
|
+
_this.toFront();
|
|
219
|
+
}
|
|
217
220
|
}
|
|
218
221
|
// 不是双击的,默认都是单击
|
|
219
222
|
if (isDoubleClick) {
|
|
@@ -233,6 +236,7 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
233
236
|
_this.handleContextMenu = function (ev) {
|
|
234
237
|
ev.preventDefault();
|
|
235
238
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
239
|
+
var editConfigModel = graphModel.editConfigModel;
|
|
236
240
|
// 节点数据,多为事件对象数据抛出
|
|
237
241
|
var nodeData = model.getData();
|
|
238
242
|
var position = graphModel.getPointByClient({
|
|
@@ -248,7 +252,10 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
248
252
|
e: ev,
|
|
249
253
|
position: position,
|
|
250
254
|
});
|
|
251
|
-
|
|
255
|
+
// 静默模式下点击节点不变更节点层级
|
|
256
|
+
if (!editConfigModel.isSilentMode) {
|
|
257
|
+
_this.toFront();
|
|
258
|
+
}
|
|
252
259
|
};
|
|
253
260
|
_this.handleMouseDown = function (ev) {
|
|
254
261
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
@@ -322,6 +329,12 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
322
329
|
if (this.modelDisposer) {
|
|
323
330
|
this.modelDisposer();
|
|
324
331
|
}
|
|
332
|
+
// 以下是 mobx-preact 中 componentWillUnmount 的回调逻辑,但是不知道出于什么考虑,mobx-preact 没有混入这一段逻辑
|
|
333
|
+
// @ts-ignore
|
|
334
|
+
if (this.render.$mobx) {
|
|
335
|
+
// @ts-ignore
|
|
336
|
+
this.render.$mobx.dispose();
|
|
337
|
+
}
|
|
325
338
|
};
|
|
326
339
|
BaseNode.prototype.componentDidMount = function () { };
|
|
327
340
|
BaseNode.prototype.componentDidUpdate = function () { };
|
package/es/view/node/HtmlNode.js
CHANGED
|
@@ -113,6 +113,7 @@ var HtmlNode = /** @class */ (function (_super) {
|
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
115
|
HtmlNode.prototype.componentWillUnmount = function () {
|
|
116
|
+
_super.prototype.componentWillUnmount.call(this);
|
|
116
117
|
this.rootEl.innerHTML = '';
|
|
117
118
|
};
|
|
118
119
|
HtmlNode.prototype.getShape = function () {
|