@logicflow/core 2.0.6 → 2.0.7
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 +10 -10
- package/.turbo/turbo-build.log +33 -33
- package/CHANGELOG.md +21 -0
- package/__tests__/algorithm/egde.test.ts +36 -23
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/event/eventArgs.d.ts +23 -29
- package/es/model/GraphModel.d.ts +10 -0
- package/es/model/GraphModel.js +26 -1
- package/es/model/edge/BaseEdgeModel.d.ts +1 -0
- package/es/model/node/BaseNodeModel.js +1 -1
- package/es/util/drag.d.ts +1 -0
- package/es/util/drag.js +11 -0
- package/es/view/Anchor.js +6 -8
- package/es/view/Control.js +1 -1
- package/es/view/Graph.js +3 -15
- package/es/view/behavior/dnd.js +1 -0
- package/es/view/edge/BaseEdge.d.ts +3 -1
- package/es/view/edge/BaseEdge.js +8 -5
- package/es/view/overlay/BackgroundOverlay.d.ts +4 -14
- package/es/view/overlay/BackgroundOverlay.js +11 -1
- package/es/view/overlay/Grid.d.ts +4 -3
- package/es/view/overlay/Grid.js +8 -31
- package/es/view/text/BaseText.js +1 -1
- package/lib/event/eventArgs.d.ts +23 -29
- package/lib/model/GraphModel.d.ts +10 -0
- package/lib/model/GraphModel.js +25 -0
- package/lib/model/edge/BaseEdgeModel.d.ts +1 -0
- package/lib/model/node/BaseNodeModel.js +1 -1
- package/lib/util/drag.d.ts +1 -0
- package/lib/util/drag.js +11 -0
- package/lib/view/Anchor.js +6 -8
- package/lib/view/Control.js +1 -1
- package/lib/view/Graph.js +3 -15
- package/lib/view/behavior/dnd.js +1 -0
- package/lib/view/edge/BaseEdge.d.ts +3 -1
- package/lib/view/edge/BaseEdge.js +8 -5
- package/lib/view/overlay/BackgroundOverlay.d.ts +4 -14
- package/lib/view/overlay/BackgroundOverlay.js +11 -1
- package/lib/view/overlay/Grid.d.ts +4 -3
- package/lib/view/overlay/Grid.js +8 -31
- package/lib/view/text/BaseText.js +1 -1
- package/package.json +1 -1
- package/src/algorithm/edge.ts +2 -4
- package/src/event/eventArgs.ts +23 -29
- package/src/model/GraphModel.ts +12 -1
- package/src/model/edge/BaseEdgeModel.ts +1 -0
- package/src/model/node/BaseNodeModel.ts +1 -1
- package/src/model/node/HtmlNodeModel.ts +1 -1
- package/src/util/drag.ts +12 -0
- package/src/view/Anchor.tsx +7 -8
- package/src/view/Control.tsx +1 -1
- package/src/view/Graph.tsx +2 -3
- package/src/view/behavior/dnd.ts +1 -0
- package/src/view/edge/BaseEdge.tsx +8 -3
- package/src/view/overlay/Grid.tsx +13 -9
- package/src/view/text/BaseText.tsx +1 -1
- package/stats.html +1 -1
package/es/event/eventArgs.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ interface NodeEventArgs {
|
|
|
105
105
|
/**
|
|
106
106
|
* 拖拽外部拖入节点
|
|
107
107
|
*/
|
|
108
|
-
'node:dnd-drag': NodeEventArgsPick<'data'>;
|
|
108
|
+
'node:dnd-drag': NodeEventArgsPick<'data' | 'e'>;
|
|
109
109
|
/**
|
|
110
110
|
* 开始拖拽节点
|
|
111
111
|
*/
|
|
@@ -130,6 +130,27 @@ interface NodeEventArgs {
|
|
|
130
130
|
* 节点缩放
|
|
131
131
|
*/
|
|
132
132
|
'node:resize': NodeEventArgsPick<'preData' | 'data' | 'model' | 'deltaX' | 'deltaY' | 'index'>;
|
|
133
|
+
/**
|
|
134
|
+
* 元素的 properties 发生改变
|
|
135
|
+
*/
|
|
136
|
+
'node:properties-change': {
|
|
137
|
+
/**
|
|
138
|
+
* 元素的 id
|
|
139
|
+
*/
|
|
140
|
+
id: string;
|
|
141
|
+
/**
|
|
142
|
+
* 改变的 properties 的 key
|
|
143
|
+
*/
|
|
144
|
+
keys: string[];
|
|
145
|
+
/**
|
|
146
|
+
* 改变前的 properties
|
|
147
|
+
*/
|
|
148
|
+
preProperties: Record<string, any>;
|
|
149
|
+
/**
|
|
150
|
+
* 改变后的 properties
|
|
151
|
+
*/
|
|
152
|
+
properties: Record<string, any>;
|
|
153
|
+
};
|
|
133
154
|
}
|
|
134
155
|
type EdgeEventArgsPick<T extends 'data' | 'e' | 'position'> = Pick<{
|
|
135
156
|
/**
|
|
@@ -275,33 +296,6 @@ interface CommonEventArgs {
|
|
|
275
296
|
*/
|
|
276
297
|
position: ClientPosition;
|
|
277
298
|
};
|
|
278
|
-
/**
|
|
279
|
-
* 元素的 properties 发生改变
|
|
280
|
-
*/
|
|
281
|
-
'properties:change': {
|
|
282
|
-
data: {
|
|
283
|
-
/**
|
|
284
|
-
* 元素的 id
|
|
285
|
-
*/
|
|
286
|
-
id: string;
|
|
287
|
-
/**
|
|
288
|
-
* 元素的类型
|
|
289
|
-
*/
|
|
290
|
-
type: string;
|
|
291
|
-
/**
|
|
292
|
-
* 改变的 properties 的 key
|
|
293
|
-
*/
|
|
294
|
-
keys: string[];
|
|
295
|
-
/**
|
|
296
|
-
* 改变前的 properties
|
|
297
|
-
*/
|
|
298
|
-
preProperties: Record<string, any>;
|
|
299
|
-
/**
|
|
300
|
-
* 改变后的 properties
|
|
301
|
-
*/
|
|
302
|
-
properties: Record<string, any>;
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
299
|
/**
|
|
306
300
|
* 进行画布平移或缩放等变化操作时触发
|
|
307
301
|
*/
|
|
@@ -356,7 +350,7 @@ type AnchorEventArgsPick<T extends 'data' | 'e' | 'nodeModel' | 'edgeModel'> = P
|
|
|
356
350
|
/**
|
|
357
351
|
* 通过拖动锚点连线添加的边的数据
|
|
358
352
|
*/
|
|
359
|
-
edgeModel
|
|
353
|
+
edgeModel?: BaseEdgeModel;
|
|
360
354
|
}, T>;
|
|
361
355
|
/**
|
|
362
356
|
* 锚点事件
|
package/es/model/GraphModel.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ElementState, EventType, OverlapMode, TextMode } from '../constant';
|
|
|
3
3
|
import LogicFlow from '../LogicFlow';
|
|
4
4
|
import { Options as LFOptions } from '../options';
|
|
5
5
|
import EventEmitter from '../event/eventEmitter';
|
|
6
|
+
import { Grid } from '../view/overlay';
|
|
6
7
|
import PointTuple = LogicFlow.PointTuple;
|
|
7
8
|
import GraphData = LogicFlow.GraphData;
|
|
8
9
|
import NodeConfig = LogicFlow.NodeConfig;
|
|
@@ -16,6 +17,7 @@ export declare class GraphModel {
|
|
|
16
17
|
width: number;
|
|
17
18
|
height: number;
|
|
18
19
|
theme: LogicFlow.Theme;
|
|
20
|
+
grid: Grid.GridOptions;
|
|
19
21
|
readonly eventCenter: EventEmitter;
|
|
20
22
|
readonly modelMap: Map<string, LogicFlow.GraphElementCtor>;
|
|
21
23
|
/**
|
|
@@ -383,6 +385,14 @@ export declare class GraphModel {
|
|
|
383
385
|
* todo docs link
|
|
384
386
|
*/
|
|
385
387
|
setTheme(style: Partial<LogicFlow.Theme>): void;
|
|
388
|
+
/**
|
|
389
|
+
* 更新网格配置
|
|
390
|
+
*/
|
|
391
|
+
updateGridOptions(options: Partial<Grid.GridOptions>): void;
|
|
392
|
+
/**
|
|
393
|
+
* 更新网格配置
|
|
394
|
+
*/
|
|
395
|
+
updateBackgroundOptions(options: boolean | Partial<LFOptions.BackgroundConfig>): void;
|
|
386
396
|
/**
|
|
387
397
|
* 重新设置画布的宽高
|
|
388
398
|
*/
|
package/es/model/GraphModel.js
CHANGED
|
@@ -40,12 +40,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
40
40
|
}
|
|
41
41
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
42
42
|
};
|
|
43
|
-
import { find, forEach, map } from 'lodash-es';
|
|
43
|
+
import { find, forEach, map, merge } from 'lodash-es';
|
|
44
44
|
import { action, computed, observable } from 'mobx';
|
|
45
45
|
import { EditConfigModel, TransformModel, } from '.';
|
|
46
46
|
import { DEFAULT_VISIBLE_SPACE, ELEMENT_MAX_Z_INDEX, ElementState, ElementType, EventType, ModelType, OverlapMode, TextMode, } from '../constant';
|
|
47
47
|
import { createEdgeGenerator, createUuid, formatData, getClosestPointOfPolyline, getMinIndex, getNodeAnchorPosition, getNodeBBox, getZIndex, isPointInArea, setupAnimation, setupTheme, snapToGrid, updateTheme, } from '../util';
|
|
48
48
|
import EventEmitter from '../event/eventEmitter';
|
|
49
|
+
import { Grid } from '../view/overlay';
|
|
49
50
|
var GraphModel = /** @class */ (function () {
|
|
50
51
|
function GraphModel(options) {
|
|
51
52
|
// 维护所有节点和边类型对应的 model
|
|
@@ -88,6 +89,7 @@ var GraphModel = /** @class */ (function () {
|
|
|
88
89
|
this.gridSize = grid.size || 1; // 默认 gridSize 设置为 1
|
|
89
90
|
}
|
|
90
91
|
this.theme = setupTheme(options.style);
|
|
92
|
+
this.grid = Grid.getGridOptions(grid !== null && grid !== void 0 ? grid : false);
|
|
91
93
|
this.edgeType = options.edgeType || 'polyline';
|
|
92
94
|
this.animation = setupAnimation(animation);
|
|
93
95
|
this.overlapMode = options.overlapMode || OverlapMode.DEFAULT;
|
|
@@ -1238,6 +1240,26 @@ var GraphModel = /** @class */ (function () {
|
|
|
1238
1240
|
GraphModel.prototype.setTheme = function (style) {
|
|
1239
1241
|
this.theme = updateTheme(__assign(__assign({}, this.theme), style));
|
|
1240
1242
|
};
|
|
1243
|
+
/**
|
|
1244
|
+
* 更新网格配置
|
|
1245
|
+
*/
|
|
1246
|
+
GraphModel.prototype.updateGridOptions = function (options) {
|
|
1247
|
+
merge(this.grid, options);
|
|
1248
|
+
};
|
|
1249
|
+
/**
|
|
1250
|
+
* 更新网格配置
|
|
1251
|
+
*/
|
|
1252
|
+
GraphModel.prototype.updateBackgroundOptions = function (options) {
|
|
1253
|
+
if (typeof options === 'boolean') {
|
|
1254
|
+
this.background = options;
|
|
1255
|
+
}
|
|
1256
|
+
else if (typeof this.background === 'boolean') {
|
|
1257
|
+
this.background = options;
|
|
1258
|
+
}
|
|
1259
|
+
else {
|
|
1260
|
+
this.background = __assign(__assign({}, this.background), options);
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1241
1263
|
/**
|
|
1242
1264
|
* 重新设置画布的宽高
|
|
1243
1265
|
*/
|
|
@@ -1365,6 +1387,9 @@ var GraphModel = /** @class */ (function () {
|
|
|
1365
1387
|
__decorate([
|
|
1366
1388
|
observable
|
|
1367
1389
|
], GraphModel.prototype, "height", void 0);
|
|
1390
|
+
__decorate([
|
|
1391
|
+
observable
|
|
1392
|
+
], GraphModel.prototype, "grid", void 0);
|
|
1368
1393
|
__decorate([
|
|
1369
1394
|
observable
|
|
1370
1395
|
], GraphModel.prototype, "edgeType", void 0);
|
|
@@ -736,7 +736,7 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
736
736
|
var preProperties = toJS(this.properties);
|
|
737
737
|
this.properties = nextProperties;
|
|
738
738
|
this.setAttributes();
|
|
739
|
-
// 触发更新节点 properties
|
|
739
|
+
// 触发更新节点 node:properties-change 的事件
|
|
740
740
|
this.graphModel.eventCenter.emit(EventType.NODE_PROPERTIES_CHANGE, {
|
|
741
741
|
id: this.id,
|
|
742
742
|
keys: updateKeys,
|
package/es/util/drag.d.ts
CHANGED
package/es/util/drag.js
CHANGED
|
@@ -121,6 +121,17 @@ var StepDrag = /** @class */ (function () {
|
|
|
121
121
|
_this.onDragEnd({ event: undefined });
|
|
122
122
|
_this.isDragging = false;
|
|
123
123
|
};
|
|
124
|
+
this.destroy = function () {
|
|
125
|
+
if (_this.isStartDragging) {
|
|
126
|
+
// https://github.com/didi/LogicFlow/issues/1934
|
|
127
|
+
// https://github.com/didi/LogicFlow/issues/1926
|
|
128
|
+
// cancelDrag()->onDragEnd()->updateEdgePointByAnchors()触发线的重新计算
|
|
129
|
+
// 我们的本意是为了防止mousemove和mouseup没有及时被移除
|
|
130
|
+
// 因此这里增加if(this.isStartDragging)的判断,isStartDragging=true代表没有触发handleMouseUp(),此时监听还没被移除
|
|
131
|
+
// 在拖拽情况下(isStartDragging=true),此时注册了监听,在组件突然销毁时,强制触发cancelDrag进行监听事件的移除
|
|
132
|
+
_this.cancelDrag();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
124
135
|
this.onDragStart = onDragStart;
|
|
125
136
|
this.onDragging = onDragging;
|
|
126
137
|
this.onDragEnd = onDragEnd;
|
package/es/view/Anchor.js
CHANGED
|
@@ -139,14 +139,12 @@ var Anchor = /** @class */ (function (_super) {
|
|
|
139
139
|
_this.sourceRuleResults.clear();
|
|
140
140
|
_this.targetRuleResults.clear();
|
|
141
141
|
var _b = _this.props, graphModel = _b.graphModel, nodeModel = _b.nodeModel, anchorData = _b.anchorData;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
}
|
|
142
|
+
graphModel.eventCenter.emit(EventType.ANCHOR_DRAGEND, {
|
|
143
|
+
data: anchorData,
|
|
144
|
+
e: event,
|
|
145
|
+
nodeModel: nodeModel,
|
|
146
|
+
edgeModel: edgeModel !== null && edgeModel !== void 0 ? edgeModel : undefined,
|
|
147
|
+
});
|
|
150
148
|
};
|
|
151
149
|
_this.checkEnd = function (event) {
|
|
152
150
|
var _a;
|
package/es/view/Control.js
CHANGED
|
@@ -316,7 +316,7 @@ var ResizeControl = /** @class */ (function (_super) {
|
|
|
316
316
|
return _this;
|
|
317
317
|
}
|
|
318
318
|
ResizeControl.prototype.componentWillUnmount = function () {
|
|
319
|
-
this.dragHandler.
|
|
319
|
+
this.dragHandler.destroy();
|
|
320
320
|
};
|
|
321
321
|
ResizeControl.prototype.render = function () {
|
|
322
322
|
var _a = this.props, x = _a.x, y = _a.y, direction = _a.direction, model = _a.model;
|
package/es/view/Graph.js
CHANGED
|
@@ -13,17 +13,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
13
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
14
|
};
|
|
15
15
|
})();
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
16
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
28
17
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
18
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -102,12 +91,11 @@ var Graph = /** @class */ (function (_super) {
|
|
|
102
91
|
if (options.height) {
|
|
103
92
|
style.height = "".concat(graphModel.height, "px");
|
|
104
93
|
}
|
|
105
|
-
var
|
|
106
|
-
var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel;
|
|
94
|
+
var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel, background = graphModel.background;
|
|
107
95
|
var adjustEdge = editConfigModel.adjustEdge;
|
|
108
|
-
return (_jsxs("div", { className: "lf-graph", "flow-id": graphModel.flowId, children: [_jsxs(CanvasOverlay, { graphModel: graphModel, dnd: dnd, children: [_jsx("g", { className: "lf-base", children: map(graphModel.sortElements, function (nodeModel) {
|
|
96
|
+
return (_jsxs("div", { className: "lf-graph", "flow-id": graphModel.flowId, style: style, children: [_jsxs(CanvasOverlay, { graphModel: graphModel, dnd: dnd, children: [_jsx("g", { className: "lf-base", children: map(graphModel.sortElements, function (nodeModel) {
|
|
109
97
|
return _this.getComponent(nodeModel, graphModel);
|
|
110
|
-
}) }), fakeNode ? this.getComponent(fakeNode, graphModel) : ''] }), _jsxs(ModificationOverlay, { graphModel: graphModel, children: [_jsx(OutlineOverlay, { graphModel: graphModel }), adjustEdge ? _jsx(BezierAdjustOverlay, { graphModel: graphModel }) : '', options.snapline !== false ? (_jsx(SnaplineOverlay, { snaplineModel: snaplineModel })) : ('')] }), _jsx(ToolOverlay, { graphModel: graphModel, tool: tool }),
|
|
98
|
+
}) }), fakeNode ? this.getComponent(fakeNode, graphModel) : ''] }), _jsxs(ModificationOverlay, { graphModel: graphModel, children: [_jsx(OutlineOverlay, { graphModel: graphModel }), adjustEdge ? _jsx(BezierAdjustOverlay, { graphModel: graphModel }) : '', options.snapline !== false ? (_jsx(SnaplineOverlay, { snaplineModel: snaplineModel })) : ('')] }), _jsx(ToolOverlay, { graphModel: graphModel, tool: tool }), background && _jsx(BackgroundOverlay, { background: background }), _jsx(Grid, { graphModel: graphModel })] }));
|
|
111
99
|
};
|
|
112
100
|
Graph = __decorate([
|
|
113
101
|
observer
|
package/es/view/behavior/dnd.js
CHANGED
|
@@ -13,6 +13,7 @@ export type IEdgeState = {
|
|
|
13
13
|
export declare abstract class BaseEdge<P extends IProps> extends Component<P, IEdgeState> {
|
|
14
14
|
static isObserved: boolean;
|
|
15
15
|
static extendsKey?: string;
|
|
16
|
+
mouseUpDrag?: boolean;
|
|
16
17
|
startTime?: number;
|
|
17
18
|
contextMenuTime?: number;
|
|
18
19
|
clickTimer?: number;
|
|
@@ -127,10 +128,11 @@ export declare abstract class BaseEdge<P extends IProps> extends Component<P, IE
|
|
|
127
128
|
* 不支持重写
|
|
128
129
|
*/
|
|
129
130
|
handleMouseDown: (e: MouseEvent) => void;
|
|
131
|
+
handleMouseUp: () => void;
|
|
130
132
|
/**
|
|
131
133
|
* 不支持重写
|
|
132
134
|
*/
|
|
133
|
-
|
|
135
|
+
handleClick: (e: MouseEvent) => void;
|
|
134
136
|
/**
|
|
135
137
|
* @overridable 支持重写, 此方法为获取边的形状,如果需要自定义边的形状,请重写此方法。
|
|
136
138
|
* @example https://docs.logic-flow.cn/docs/#/zh/guide/basic/edge?id=%e5%9f%ba%e4%ba%8e-react-%e7%bb%84%e4%bb%b6%e8%87%aa%e5%ae%9a%e4%b9%89%e8%be%b9
|
package/es/view/edge/BaseEdge.js
CHANGED
|
@@ -123,15 +123,18 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
123
123
|
e.stopPropagation();
|
|
124
124
|
_this.startTime = new Date().getTime();
|
|
125
125
|
};
|
|
126
|
+
_this.handleMouseUp = function () {
|
|
127
|
+
var model = _this.props.model;
|
|
128
|
+
_this.mouseUpDrag = model.isDragging;
|
|
129
|
+
};
|
|
126
130
|
/**
|
|
127
131
|
* 不支持重写
|
|
128
132
|
*/
|
|
129
|
-
_this.
|
|
133
|
+
_this.handleClick = function (e) {
|
|
130
134
|
if (!_this.startTime)
|
|
131
135
|
return;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return; // 事件大于200ms,认为是拖拽。
|
|
136
|
+
if (_this.mouseUpDrag)
|
|
137
|
+
return; // 如果是拖拽,不触发click事件。
|
|
135
138
|
var isRightClick = e.button === 2;
|
|
136
139
|
if (isRightClick)
|
|
137
140
|
return;
|
|
@@ -379,7 +382,7 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
379
382
|
isSelected && 'lf-edge-selected',
|
|
380
383
|
]
|
|
381
384
|
.filter(Boolean)
|
|
382
|
-
.join(' '), onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, onContextMenu: this.handleContextMenu, onMouseOver: this.setHoverOn, onMouseEnter: this.setHoverOn, onMouseLeave: this.setHoverOff, children: [this.getShape(), this.getAppend(), this.getText(), this.getArrow()] }), isShowAdjustPoint && isSelected ? this.getAdjustPoints() : ''] }));
|
|
385
|
+
.join(' '), onMouseDown: this.handleMouseDown, onMouseUp: this.handleMouseUp, onClick: this.handleClick, onContextMenu: this.handleContextMenu, onMouseOver: this.setHoverOn, onMouseEnter: this.setHoverOn, onMouseLeave: this.setHoverOff, children: [this.getShape(), this.getAppend(), this.getText(), this.getArrow()] }), isShowAdjustPoint && isSelected ? this.getAdjustPoints() : ''] }));
|
|
383
386
|
};
|
|
384
387
|
BaseEdge.isObserved = false;
|
|
385
388
|
return BaseEdge;
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import { Component } from 'preact/compat';
|
|
2
|
+
import { Options as LFOptions } from '../../options';
|
|
2
3
|
/**
|
|
3
4
|
* 背景配置, 支持css属性配置
|
|
4
5
|
* https://developer.mozilla.org/zh-CN/docs/Web/CSS/background
|
|
5
6
|
* @example
|
|
6
7
|
* {
|
|
7
|
-
*
|
|
8
|
-
|
|
8
|
+
* backgroundImage: "url('./img/grid.svg')",
|
|
9
|
+
backgroundRepeat: 'repeat',
|
|
9
10
|
* }
|
|
10
11
|
*/
|
|
11
|
-
export type BackgroundConfig = {
|
|
12
|
-
/**
|
|
13
|
-
* 背景图片地址
|
|
14
|
-
*/
|
|
15
|
-
backgroundImage?: string;
|
|
16
|
-
/**
|
|
17
|
-
* 是否重复
|
|
18
|
-
*/
|
|
19
|
-
backgroundRepeat?: string;
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
};
|
|
22
12
|
type IProps = {
|
|
23
|
-
background: BackgroundConfig;
|
|
13
|
+
background: boolean | LFOptions.BackgroundConfig;
|
|
24
14
|
};
|
|
25
15
|
export declare class BackgroundOverlay extends Component<IProps> {
|
|
26
16
|
render(): import("preact/compat").JSX.Element;
|
|
@@ -13,8 +13,15 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
13
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
14
|
};
|
|
15
15
|
})();
|
|
16
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
17
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
18
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
19
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
20
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
+
};
|
|
16
22
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
17
23
|
import { Component } from 'preact/compat';
|
|
24
|
+
import { observer } from '../..';
|
|
18
25
|
var BackgroundOverlay = /** @class */ (function (_super) {
|
|
19
26
|
__extends(BackgroundOverlay, _super);
|
|
20
27
|
function BackgroundOverlay() {
|
|
@@ -22,8 +29,11 @@ var BackgroundOverlay = /** @class */ (function (_super) {
|
|
|
22
29
|
}
|
|
23
30
|
BackgroundOverlay.prototype.render = function () {
|
|
24
31
|
var background = this.props.background;
|
|
25
|
-
return (_jsx("div", { className: "lf-background", children: _jsx("div", { style: background, className: "lf-background-area" }) }));
|
|
32
|
+
return (_jsx("div", { className: "lf-background", children: _jsx("div", { style: typeof background === 'object' ? background : {}, className: "lf-background-area" }) }));
|
|
26
33
|
};
|
|
34
|
+
BackgroundOverlay = __decorate([
|
|
35
|
+
observer
|
|
36
|
+
], BackgroundOverlay);
|
|
27
37
|
return BackgroundOverlay;
|
|
28
38
|
}(Component));
|
|
29
39
|
export { BackgroundOverlay };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Component } from 'preact/compat';
|
|
2
2
|
import { GraphModel } from '../../model';
|
|
3
|
-
|
|
4
|
-
type IProps = GridOptions & {
|
|
3
|
+
type IProps = {
|
|
5
4
|
graphModel: GraphModel;
|
|
6
5
|
};
|
|
7
6
|
export declare class Grid extends Component<IProps> {
|
|
7
|
+
gridOptions: Grid.GridOptions;
|
|
8
8
|
readonly id: string;
|
|
9
|
+
constructor(props: IProps);
|
|
9
10
|
renderDot(): import("preact/compat").JSX.Element;
|
|
10
11
|
renderMesh(): import("preact/compat").JSX.Element;
|
|
11
12
|
render(): import("preact/compat").JSX.Element;
|
|
@@ -30,7 +31,7 @@ export declare namespace Grid {
|
|
|
30
31
|
/**
|
|
31
32
|
* 网格的颜色
|
|
32
33
|
*/
|
|
33
|
-
color
|
|
34
|
+
color?: string;
|
|
34
35
|
/**
|
|
35
36
|
* 网格的宽度
|
|
36
37
|
* - 对于 `dot` 点状网格,表示点的大小
|
package/es/view/overlay/Grid.js
CHANGED
|
@@ -19,31 +19,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
19
19
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
20
20
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
21
|
};
|
|
22
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
23
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
24
|
-
if (!m) return o;
|
|
25
|
-
var i = m.call(o), r, ar = [], e;
|
|
26
|
-
try {
|
|
27
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
28
|
-
}
|
|
29
|
-
catch (error) { e = { error: error }; }
|
|
30
|
-
finally {
|
|
31
|
-
try {
|
|
32
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
33
|
-
}
|
|
34
|
-
finally { if (e) throw e.error; }
|
|
35
|
-
}
|
|
36
|
-
return ar;
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
22
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
48
23
|
import { Component } from 'preact/compat';
|
|
49
24
|
import { cloneDeep, assign } from 'lodash-es';
|
|
@@ -52,14 +27,15 @@ import { createUuid } from '../../util';
|
|
|
52
27
|
import { DEFAULT_GRID_SIZE } from '../../constant';
|
|
53
28
|
var Grid = /** @class */ (function (_super) {
|
|
54
29
|
__extends(Grid, _super);
|
|
55
|
-
function Grid() {
|
|
56
|
-
var _this = _super.
|
|
30
|
+
function Grid(props) {
|
|
31
|
+
var _this = _super.call(this, props) || this;
|
|
57
32
|
_this.id = createUuid();
|
|
33
|
+
_this.gridOptions = _this.props.graphModel.grid;
|
|
58
34
|
return _this;
|
|
59
35
|
}
|
|
60
36
|
// 网格类型为点状
|
|
61
37
|
Grid.prototype.renderDot = function () {
|
|
62
|
-
var _a = this.
|
|
38
|
+
var _a = this.gridOptions, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
|
|
63
39
|
var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 2 : _d;
|
|
64
40
|
// 对于点状网格,点的半径不能大于网格大小的四分之一
|
|
65
41
|
var radius = Math.min(Math.max(2, thickness), size / 4);
|
|
@@ -69,16 +45,17 @@ var Grid = /** @class */ (function (_super) {
|
|
|
69
45
|
// 网格类型为交叉线
|
|
70
46
|
// todo: 采用背景缩放的方式,实现更好的体验
|
|
71
47
|
Grid.prototype.renderMesh = function () {
|
|
72
|
-
var _a = this.
|
|
48
|
+
var _a = this.gridOptions, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
|
|
73
49
|
var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 1 : _d;
|
|
74
50
|
// 对于交叉线网格,线的宽度不能大于网格大小的一半
|
|
75
51
|
var strokeWidth = Math.min(Math.max(1, thickness), size / 2);
|
|
76
52
|
var d = "M 0 0 H ".concat(size, " V ").concat(size, " H 0 Z");
|
|
77
53
|
var opacity = visible ? 1 : 0;
|
|
78
|
-
return (_jsx("path", { d: d, stroke: color, strokeWidth: strokeWidth, opacity: opacity, fill: "transparent" }));
|
|
54
|
+
return (_jsx("path", { d: d, stroke: color, strokeWidth: strokeWidth / 2, opacity: opacity, fill: "transparent" }));
|
|
79
55
|
};
|
|
80
56
|
Grid.prototype.render = function () {
|
|
81
|
-
var
|
|
57
|
+
var transformModel = this.props.graphModel.transformModel;
|
|
58
|
+
var _a = this.gridOptions, type = _a.type, _b = _a.size, size = _b === void 0 ? 1 : _b;
|
|
82
59
|
var SCALE_X = transformModel.SCALE_X, SKEW_Y = transformModel.SKEW_Y, SKEW_X = transformModel.SKEW_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
|
|
83
60
|
var matrixString = [
|
|
84
61
|
SCALE_X,
|
package/es/view/text/BaseText.js
CHANGED
|
@@ -61,7 +61,7 @@ var BaseText = /** @class */ (function (_super) {
|
|
|
61
61
|
_this.onDragging = function (_a) {
|
|
62
62
|
var deltaX = _a.deltaX, deltaY = _a.deltaY;
|
|
63
63
|
var _b = _this.props, model = _b.model, transformModel = _b.graphModel.transformModel;
|
|
64
|
-
if (deltaX
|
|
64
|
+
if (deltaX || deltaY) {
|
|
65
65
|
var _c = __read(transformModel.fixDeltaXY(deltaX, deltaY), 2), curDeltaX = _c[0], curDeltaY = _c[1];
|
|
66
66
|
model.moveText(curDeltaX, curDeltaY);
|
|
67
67
|
}
|
package/lib/event/eventArgs.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ interface NodeEventArgs {
|
|
|
105
105
|
/**
|
|
106
106
|
* 拖拽外部拖入节点
|
|
107
107
|
*/
|
|
108
|
-
'node:dnd-drag': NodeEventArgsPick<'data'>;
|
|
108
|
+
'node:dnd-drag': NodeEventArgsPick<'data' | 'e'>;
|
|
109
109
|
/**
|
|
110
110
|
* 开始拖拽节点
|
|
111
111
|
*/
|
|
@@ -130,6 +130,27 @@ interface NodeEventArgs {
|
|
|
130
130
|
* 节点缩放
|
|
131
131
|
*/
|
|
132
132
|
'node:resize': NodeEventArgsPick<'preData' | 'data' | 'model' | 'deltaX' | 'deltaY' | 'index'>;
|
|
133
|
+
/**
|
|
134
|
+
* 元素的 properties 发生改变
|
|
135
|
+
*/
|
|
136
|
+
'node:properties-change': {
|
|
137
|
+
/**
|
|
138
|
+
* 元素的 id
|
|
139
|
+
*/
|
|
140
|
+
id: string;
|
|
141
|
+
/**
|
|
142
|
+
* 改变的 properties 的 key
|
|
143
|
+
*/
|
|
144
|
+
keys: string[];
|
|
145
|
+
/**
|
|
146
|
+
* 改变前的 properties
|
|
147
|
+
*/
|
|
148
|
+
preProperties: Record<string, any>;
|
|
149
|
+
/**
|
|
150
|
+
* 改变后的 properties
|
|
151
|
+
*/
|
|
152
|
+
properties: Record<string, any>;
|
|
153
|
+
};
|
|
133
154
|
}
|
|
134
155
|
type EdgeEventArgsPick<T extends 'data' | 'e' | 'position'> = Pick<{
|
|
135
156
|
/**
|
|
@@ -275,33 +296,6 @@ interface CommonEventArgs {
|
|
|
275
296
|
*/
|
|
276
297
|
position: ClientPosition;
|
|
277
298
|
};
|
|
278
|
-
/**
|
|
279
|
-
* 元素的 properties 发生改变
|
|
280
|
-
*/
|
|
281
|
-
'properties:change': {
|
|
282
|
-
data: {
|
|
283
|
-
/**
|
|
284
|
-
* 元素的 id
|
|
285
|
-
*/
|
|
286
|
-
id: string;
|
|
287
|
-
/**
|
|
288
|
-
* 元素的类型
|
|
289
|
-
*/
|
|
290
|
-
type: string;
|
|
291
|
-
/**
|
|
292
|
-
* 改变的 properties 的 key
|
|
293
|
-
*/
|
|
294
|
-
keys: string[];
|
|
295
|
-
/**
|
|
296
|
-
* 改变前的 properties
|
|
297
|
-
*/
|
|
298
|
-
preProperties: Record<string, any>;
|
|
299
|
-
/**
|
|
300
|
-
* 改变后的 properties
|
|
301
|
-
*/
|
|
302
|
-
properties: Record<string, any>;
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
299
|
/**
|
|
306
300
|
* 进行画布平移或缩放等变化操作时触发
|
|
307
301
|
*/
|
|
@@ -356,7 +350,7 @@ type AnchorEventArgsPick<T extends 'data' | 'e' | 'nodeModel' | 'edgeModel'> = P
|
|
|
356
350
|
/**
|
|
357
351
|
* 通过拖动锚点连线添加的边的数据
|
|
358
352
|
*/
|
|
359
|
-
edgeModel
|
|
353
|
+
edgeModel?: BaseEdgeModel;
|
|
360
354
|
}, T>;
|
|
361
355
|
/**
|
|
362
356
|
* 锚点事件
|
|
@@ -3,6 +3,7 @@ import { ElementState, EventType, OverlapMode, TextMode } from '../constant';
|
|
|
3
3
|
import LogicFlow from '../LogicFlow';
|
|
4
4
|
import { Options as LFOptions } from '../options';
|
|
5
5
|
import EventEmitter from '../event/eventEmitter';
|
|
6
|
+
import { Grid } from '../view/overlay';
|
|
6
7
|
import PointTuple = LogicFlow.PointTuple;
|
|
7
8
|
import GraphData = LogicFlow.GraphData;
|
|
8
9
|
import NodeConfig = LogicFlow.NodeConfig;
|
|
@@ -16,6 +17,7 @@ export declare class GraphModel {
|
|
|
16
17
|
width: number;
|
|
17
18
|
height: number;
|
|
18
19
|
theme: LogicFlow.Theme;
|
|
20
|
+
grid: Grid.GridOptions;
|
|
19
21
|
readonly eventCenter: EventEmitter;
|
|
20
22
|
readonly modelMap: Map<string, LogicFlow.GraphElementCtor>;
|
|
21
23
|
/**
|
|
@@ -383,6 +385,14 @@ export declare class GraphModel {
|
|
|
383
385
|
* todo docs link
|
|
384
386
|
*/
|
|
385
387
|
setTheme(style: Partial<LogicFlow.Theme>): void;
|
|
388
|
+
/**
|
|
389
|
+
* 更新网格配置
|
|
390
|
+
*/
|
|
391
|
+
updateGridOptions(options: Partial<Grid.GridOptions>): void;
|
|
392
|
+
/**
|
|
393
|
+
* 更新网格配置
|
|
394
|
+
*/
|
|
395
|
+
updateBackgroundOptions(options: boolean | Partial<LFOptions.BackgroundConfig>): void;
|
|
386
396
|
/**
|
|
387
397
|
* 重新设置画布的宽高
|
|
388
398
|
*/
|