@logicflow/core 2.0.12 → 2.0.14
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 +7 -7
- package/CHANGELOG.md +12 -0
- package/__tests__/algorithm/index.test.ts +22 -17
- package/__tests__/algorithm/outline.test.ts +9 -9
- package/__tests__/event/event.test.ts +18 -18
- package/__tests__/history/history.test.ts +23 -23
- package/__tests__/logicflow.test.ts +236 -228
- package/__tests__/model/graphmodel.test.ts +51 -31
- package/__tests__/util/compatible.test.ts +5 -5
- package/__tests__/util/geometry.test.ts +10 -10
- package/__tests__/util/graph.test.ts +12 -12
- package/__tests__/util/matrix.test.ts +26 -26
- package/__tests__/util/node.test.ts +22 -22
- package/__tests__/util/sampling.test.ts +6 -10
- package/__tests__/util/vector.test.ts +36 -36
- package/__tests__/util/zIndex.test.ts +6 -6
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.d.ts +29 -4
- package/es/LogicFlow.js +35 -6
- package/es/model/GraphModel.d.ts +35 -1
- package/es/model/GraphModel.js +45 -5
- package/es/model/node/RectNodeModel.js +3 -0
- package/es/options.d.ts +1 -0
- package/es/util/theme.d.ts +67 -2
- package/es/util/theme.js +189 -2
- package/es/view/Graph.d.ts +0 -3
- package/es/view/Graph.js +3 -7
- package/es/view/edge/BaseEdge.d.ts +4 -0
- package/es/view/edge/BaseEdge.js +45 -3
- package/es/view/overlay/Grid.js +3 -2
- package/es/view/overlay/ToolOverlay.d.ts +1 -3
- package/es/view/overlay/ToolOverlay.js +2 -39
- package/es/view/shape/Polygon.d.ts +8 -0
- package/es/view/shape/Polygon.js +50 -3
- package/lib/LogicFlow.d.ts +29 -4
- package/lib/LogicFlow.js +34 -5
- package/lib/model/GraphModel.d.ts +35 -1
- package/lib/model/GraphModel.js +43 -3
- package/lib/model/node/RectNodeModel.js +3 -0
- package/lib/options.d.ts +1 -0
- package/lib/util/theme.d.ts +67 -2
- package/lib/util/theme.js +192 -2
- package/lib/view/Graph.d.ts +0 -3
- package/lib/view/Graph.js +2 -6
- package/lib/view/edge/BaseEdge.d.ts +4 -0
- package/lib/view/edge/BaseEdge.js +45 -3
- package/lib/view/overlay/Grid.js +3 -2
- package/lib/view/overlay/ToolOverlay.d.ts +1 -3
- package/lib/view/overlay/ToolOverlay.js +2 -39
- package/lib/view/shape/Polygon.d.ts +8 -0
- package/lib/view/shape/Polygon.js +52 -4
- package/package.json +1 -1
- package/src/LogicFlow.tsx +57 -7
- package/src/model/GraphModel.ts +56 -3
- package/src/model/edge/index.ts +4 -4
- package/src/model/index.ts +7 -7
- package/src/model/node/RectNodeModel.ts +2 -1
- package/src/model/node/index.ts +8 -8
- package/src/options.ts +1 -0
- package/src/util/theme.ts +198 -3
- package/src/view/Graph.tsx +3 -15
- package/src/view/edge/BaseEdge.tsx +96 -12
- package/src/view/overlay/Grid.tsx +2 -1
- package/src/view/overlay/ToolOverlay.tsx +2 -17
- package/src/view/shape/Polygon.tsx +56 -4
- package/stats.html +1 -1
package/es/view/Graph.js
CHANGED
|
@@ -45,7 +45,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
45
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
46
|
};
|
|
47
47
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
48
|
-
import { Component
|
|
48
|
+
import { Component } from 'preact/compat';
|
|
49
49
|
import { map, throttle } from 'lodash-es';
|
|
50
50
|
import { CanvasOverlay, ToolOverlay, BackgroundOverlay, Grid, SnaplineOverlay, OutlineOverlay, BezierAdjustOverlay, ModificationOverlay, } from './overlay';
|
|
51
51
|
import { observer } from '..';
|
|
@@ -54,10 +54,6 @@ var Graph = /** @class */ (function (_super) {
|
|
|
54
54
|
__extends(Graph, _super);
|
|
55
55
|
function Graph() {
|
|
56
56
|
var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
|
|
57
|
-
_this.canvasOverlayRef = createRef();
|
|
58
|
-
_this.getCanvasOverlay = function () {
|
|
59
|
-
return _this.canvasOverlayRef.current;
|
|
60
|
-
};
|
|
61
57
|
_this.handleResize = function () {
|
|
62
58
|
var _a = _this.props, graphModel = _a.graphModel, options = _a.options;
|
|
63
59
|
var width = graphModel.width, height = graphModel.height, isContainerWidth = graphModel.isContainerWidth, isContainerHeight = graphModel.isContainerHeight;
|
|
@@ -114,9 +110,9 @@ var Graph = /** @class */ (function (_super) {
|
|
|
114
110
|
}
|
|
115
111
|
var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel, background = graphModel.background;
|
|
116
112
|
var adjustEdge = editConfigModel.adjustEdge;
|
|
117
|
-
return (_jsxs("div", { className: "lf-graph", "flow-id": graphModel.flowId, style: style, children: [_jsxs(CanvasOverlay, {
|
|
113
|
+
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) {
|
|
118
114
|
return _this.getComponent(nodeModel, graphModel);
|
|
119
|
-
}) }), 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
|
|
115
|
+
}) }), 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 })] }));
|
|
120
116
|
};
|
|
121
117
|
Graph = __decorate([
|
|
122
118
|
observer
|
|
@@ -44,6 +44,10 @@ export declare abstract class BaseEdge<P extends IProps> extends Component<P, IE
|
|
|
44
44
|
* 定义边的箭头,不支持重写。请使用getStartArrow和getEndArrow
|
|
45
45
|
*/
|
|
46
46
|
private getArrow;
|
|
47
|
+
/**
|
|
48
|
+
* Private helper method to generate arrow path based on type and parameters
|
|
49
|
+
*/
|
|
50
|
+
private getArrowPath;
|
|
47
51
|
/**
|
|
48
52
|
* @overridable 可重写,自定义边起点箭头形状。
|
|
49
53
|
* @example
|
package/es/view/edge/BaseEdge.js
CHANGED
|
@@ -291,6 +291,31 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
291
291
|
}
|
|
292
292
|
return (_jsx("g", { children: _jsxs("defs", { children: [_jsx("marker", { id: "marker-start-".concat(id), refX: -refX, refY: refY, overflow: "visible", orient: "auto", markerUnits: "userSpaceOnUse", children: this.getStartArrow() }), _jsx("marker", { id: "marker-end-".concat(id), refX: refX, refY: refY, overflow: "visible", orient: theta, markerUnits: "userSpaceOnUse", children: this.getEndArrow() })] }) }));
|
|
293
293
|
};
|
|
294
|
+
/**
|
|
295
|
+
* Private helper method to generate arrow path based on type and parameters
|
|
296
|
+
*/
|
|
297
|
+
BaseEdge.prototype.getArrowPath = function (arrowType, props) {
|
|
298
|
+
var stroke = props.stroke, _a = props.fill, fill = _a === void 0 ? stroke : _a, strokeWidth = props.strokeWidth, _b = props.offset, offset = _b === void 0 ? 10 : _b, verticalLength = props.verticalLength, strokeLinecap = props.strokeLinecap, strokeLinejoin = props.strokeLinejoin, transform = props.transform;
|
|
299
|
+
var arrowPath = '';
|
|
300
|
+
switch (arrowType) {
|
|
301
|
+
case 'solid':
|
|
302
|
+
arrowPath = "M".concat(-offset / 4, ",0 L").concat((3 * offset) / 4, ",").concat(verticalLength, " L").concat((3 * offset) / 4, ",-").concat(verticalLength, " Z");
|
|
303
|
+
break;
|
|
304
|
+
case 'hollow':
|
|
305
|
+
arrowPath = "M".concat(-offset / 4, ",0 L").concat((3 * offset) / 4, ",").concat(verticalLength, " L").concat(-offset / 4, ",0 L").concat((3 * offset) / 4, ",-").concat(verticalLength, " L").concat(-offset / 4, ",0 Z");
|
|
306
|
+
break;
|
|
307
|
+
case 'diamond':
|
|
308
|
+
arrowPath = "M".concat(-offset / 2, ",0 L0,").concat(verticalLength, " L").concat(offset / 2, ",0 L0,-").concat(verticalLength, " L").concat(-offset / 2, ",0 Z");
|
|
309
|
+
break;
|
|
310
|
+
case 'circle':
|
|
311
|
+
arrowPath = "M".concat(-offset / 2, ",0 A").concat(offset / 4, ",").concat(offset / 4, " 0 1,0 ").concat(offset / 2, ",0 A").concat(offset / 4, ",").concat(offset / 4, " 0 1,0 ").concat(-offset / 2, ",0 Z");
|
|
312
|
+
break;
|
|
313
|
+
default:
|
|
314
|
+
arrowPath = '';
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
return (_jsx("path", { d: arrowPath, stroke: stroke, fill: fill, strokeWidth: strokeWidth, strokeLinecap: strokeLinecap, strokeLinejoin: strokeLinejoin, transform: transform }));
|
|
318
|
+
};
|
|
294
319
|
/**
|
|
295
320
|
* @overridable 可重写,自定义边起点箭头形状。
|
|
296
321
|
* @example
|
|
@@ -305,7 +330,16 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
305
330
|
* }
|
|
306
331
|
*/
|
|
307
332
|
BaseEdge.prototype.getStartArrow = function () {
|
|
308
|
-
|
|
333
|
+
var model = this.props.model;
|
|
334
|
+
var _a = model.getArrowStyle(), stroke = _a.stroke, strokeWidth = _a.strokeWidth, offset = _a.offset, verticalLength = _a.verticalLength, _b = _a.startArrowType, startArrowType = _b === void 0 ? 'solid' : _b, strokeLinecap = _a.strokeLinecap, strokeLinejoin = _a.strokeLinejoin;
|
|
335
|
+
return this.getArrowPath(startArrowType, {
|
|
336
|
+
stroke: stroke,
|
|
337
|
+
strokeWidth: strokeWidth,
|
|
338
|
+
offset: offset,
|
|
339
|
+
verticalLength: verticalLength,
|
|
340
|
+
strokeLinecap: strokeLinecap,
|
|
341
|
+
strokeLinejoin: strokeLinejoin,
|
|
342
|
+
});
|
|
309
343
|
};
|
|
310
344
|
/**
|
|
311
345
|
* @overridable 可重写,自定义边终点箭头形状。
|
|
@@ -322,8 +356,16 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
322
356
|
*/
|
|
323
357
|
BaseEdge.prototype.getEndArrow = function () {
|
|
324
358
|
var model = this.props.model;
|
|
325
|
-
var _a = model.getArrowStyle(), stroke = _a.stroke, strokeWidth = _a.strokeWidth, offset = _a.offset, verticalLength = _a.verticalLength;
|
|
326
|
-
return (
|
|
359
|
+
var _a = model.getArrowStyle(), stroke = _a.stroke, strokeWidth = _a.strokeWidth, offset = _a.offset, verticalLength = _a.verticalLength, _b = _a.endArrowType, endArrowType = _b === void 0 ? 'solid' : _b, strokeLinecap = _a.strokeLinecap, strokeLinejoin = _a.strokeLinejoin;
|
|
360
|
+
return this.getArrowPath(endArrowType, {
|
|
361
|
+
stroke: stroke,
|
|
362
|
+
strokeWidth: strokeWidth,
|
|
363
|
+
offset: offset,
|
|
364
|
+
verticalLength: verticalLength,
|
|
365
|
+
strokeLinecap: strokeLinecap,
|
|
366
|
+
strokeLinejoin: strokeLinejoin,
|
|
367
|
+
transform: 'rotate(180)',
|
|
368
|
+
});
|
|
327
369
|
};
|
|
328
370
|
/**
|
|
329
371
|
* @overridable 可重写,自定义调整边连接节点形状。在开启了adjustEdgeStartAndEnd的时候,会显示调整点。
|
package/es/view/overlay/Grid.js
CHANGED
|
@@ -54,8 +54,9 @@ var Grid = /** @class */ (function (_super) {
|
|
|
54
54
|
return (_jsx("path", { d: d, stroke: color, strokeWidth: strokeWidth / 2, opacity: opacity, fill: "transparent" }));
|
|
55
55
|
};
|
|
56
56
|
Grid.prototype.render = function () {
|
|
57
|
-
var
|
|
58
|
-
|
|
57
|
+
var _a = this.props.graphModel, transformModel = _a.transformModel, grid = _a.grid;
|
|
58
|
+
this.gridOptions = grid;
|
|
59
|
+
var _b = this.gridOptions, type = _b.type, _c = _b.size, size = _c === void 0 ? 1 : _c;
|
|
59
60
|
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;
|
|
60
61
|
var matrixString = [
|
|
61
62
|
SCALE_X,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createElement as h, Component } from 'preact/compat';
|
|
2
|
-
import {
|
|
2
|
+
import { OutlineOverlay } from '.';
|
|
3
3
|
import { GraphModel } from '../../model';
|
|
4
4
|
import { Tool } from '../../tool';
|
|
5
5
|
type IProps = {
|
|
6
6
|
graphModel: GraphModel;
|
|
7
7
|
tool: Tool;
|
|
8
|
-
getCanvasOverlay: () => CanvasOverlay | null;
|
|
9
8
|
};
|
|
10
9
|
export declare class ToolOverlay extends Component<IProps> {
|
|
11
10
|
componentDidMount(): void;
|
|
@@ -15,7 +14,6 @@ export declare class ToolOverlay extends Component<IProps> {
|
|
|
15
14
|
*/
|
|
16
15
|
getTools(): import("preact").VNode<import("../..").IToolProps>[];
|
|
17
16
|
triggerToolRender(): void;
|
|
18
|
-
zoomHandler: (e: WheelEvent) => void;
|
|
19
17
|
render(): h.JSX.Element;
|
|
20
18
|
}
|
|
21
19
|
export default OutlineOverlay;
|
|
@@ -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 } from "preact/jsx-runtime";
|
|
48
23
|
import { createElement as h, Component } from 'preact/compat';
|
|
49
24
|
import { OutlineOverlay } from '.';
|
|
@@ -51,13 +26,7 @@ import { observer } from '../..';
|
|
|
51
26
|
var ToolOverlay = /** @class */ (function (_super) {
|
|
52
27
|
__extends(ToolOverlay, _super);
|
|
53
28
|
function ToolOverlay() {
|
|
54
|
-
|
|
55
|
-
_this.zoomHandler = function (e) {
|
|
56
|
-
var _a;
|
|
57
|
-
// TODO 是否应该使用 dispatchEvent 来触发事件
|
|
58
|
-
(_a = _this.props.getCanvasOverlay()) === null || _a === void 0 ? void 0 : _a.zoomHandler(e);
|
|
59
|
-
};
|
|
60
|
-
return _this;
|
|
29
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
61
30
|
}
|
|
62
31
|
// 在react严格模式下,useEffect会执行两次,但是在LogicFlow内部,则只会触发一次componentDidMount和componentDidUpdate。
|
|
63
32
|
// 其中第一次componentDidMount对应的graphModel为被丢弃的graphModel, 所以不应该生效。
|
|
@@ -95,13 +64,7 @@ var ToolOverlay = /** @class */ (function (_super) {
|
|
|
95
64
|
};
|
|
96
65
|
ToolOverlay.prototype.render = function () {
|
|
97
66
|
var graphModel = this.props.graphModel;
|
|
98
|
-
return (_jsx("div", { className: "lf-tool-overlay", id: "ToolOverlay_".concat(graphModel.flowId),
|
|
99
|
-
/*
|
|
100
|
-
* 默认情况下该容器设置了 pointer-events: none,不会触发这些事件
|
|
101
|
-
* 只会在容器取消 pointer-events: none 后触发,用于缩放、滚动画布等操作
|
|
102
|
-
* 目前只在 selection-select 插件中使用。为了能在元素内部进行框选,在开启选区后会关闭事件透传。需要手动触发事件
|
|
103
|
-
*/
|
|
104
|
-
onWheel: this.zoomHandler, children: this.getTools() }));
|
|
67
|
+
return (_jsx("div", { className: "lf-tool-overlay", id: "ToolOverlay_".concat(graphModel.flowId), children: this.getTools() }));
|
|
105
68
|
};
|
|
106
69
|
ToolOverlay = __decorate([
|
|
107
70
|
observer
|
|
@@ -5,6 +5,14 @@ export type IPolygonProps = {
|
|
|
5
5
|
x?: number;
|
|
6
6
|
y?: number;
|
|
7
7
|
className?: string;
|
|
8
|
+
radius?: number;
|
|
8
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* 生成带圆角的多边形路径
|
|
12
|
+
* @param points 多边形顶点坐标数组
|
|
13
|
+
* @param radius 圆角半径
|
|
14
|
+
* @returns SVG 路径字符串
|
|
15
|
+
*/
|
|
16
|
+
export declare function createRoundedPolygonPath(points: any, radius: any): string;
|
|
9
17
|
export declare function Polygon(props: IPolygonProps): h.JSX.Element;
|
|
10
18
|
export default Polygon;
|
package/es/view/shape/Polygon.js
CHANGED
|
@@ -27,8 +27,48 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
27
27
|
};
|
|
28
28
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
29
29
|
import { forEach, toPairs } from 'lodash-es';
|
|
30
|
+
/**
|
|
31
|
+
* 生成带圆角的多边形路径
|
|
32
|
+
* @param points 多边形顶点坐标数组
|
|
33
|
+
* @param radius 圆角半径
|
|
34
|
+
* @returns SVG 路径字符串
|
|
35
|
+
*/
|
|
36
|
+
export function createRoundedPolygonPath(points, radius) {
|
|
37
|
+
var pointList = points.map(function (point) { return ({ x: point[0], y: point[1] }); });
|
|
38
|
+
var len = pointList.length;
|
|
39
|
+
if (len < 3)
|
|
40
|
+
return '';
|
|
41
|
+
var r = Math.abs(radius);
|
|
42
|
+
var path = '';
|
|
43
|
+
for (var i = 0; i < len; i++) {
|
|
44
|
+
var prev = pointList[(i - 1 + len) % len];
|
|
45
|
+
var curr = pointList[i];
|
|
46
|
+
var next = pointList[(i + 1) % len];
|
|
47
|
+
// 向量
|
|
48
|
+
var v1 = { x: curr.x - prev.x, y: curr.y - prev.y };
|
|
49
|
+
var v2 = { x: next.x - curr.x, y: next.y - curr.y };
|
|
50
|
+
// 单位向量
|
|
51
|
+
var len1 = Math.hypot(v1.x, v1.y);
|
|
52
|
+
var len2 = Math.hypot(v2.x, v2.y);
|
|
53
|
+
var u1 = { x: v1.x / len1, y: v1.y / len1 };
|
|
54
|
+
var u2 = { x: v2.x / len2, y: v2.y / len2 };
|
|
55
|
+
// 起点 = curr - u1 * r,终点 = curr + u2 * r
|
|
56
|
+
var start = { x: curr.x - u1.x * r, y: curr.y - u1.y * r };
|
|
57
|
+
var end = { x: curr.x + u2.x * r, y: curr.y + u2.y * r };
|
|
58
|
+
if (i === 0) {
|
|
59
|
+
path += "M ".concat(start.x, " ").concat(start.y, " ");
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
path += "L ".concat(start.x, " ").concat(start.y, " ");
|
|
63
|
+
}
|
|
64
|
+
// Q 控制点是当前拐角点
|
|
65
|
+
path += "Q ".concat(curr.x, " ").concat(curr.y, " ").concat(end.x, " ").concat(end.y, " ");
|
|
66
|
+
}
|
|
67
|
+
path += 'Z';
|
|
68
|
+
return path;
|
|
69
|
+
}
|
|
30
70
|
export function Polygon(props) {
|
|
31
|
-
var _a = props.points, points = _a === void 0 ? [] : _a, className = props.className;
|
|
71
|
+
var _a = props.points, points = _a === void 0 ? [] : _a, className = props.className, radius = props.radius;
|
|
32
72
|
var attrs = {
|
|
33
73
|
fill: 'transparent',
|
|
34
74
|
fillOpacity: 1,
|
|
@@ -49,7 +89,14 @@ export function Polygon(props) {
|
|
|
49
89
|
else {
|
|
50
90
|
attrs.className = 'lf-basic-shape';
|
|
51
91
|
}
|
|
52
|
-
|
|
53
|
-
|
|
92
|
+
if (radius) {
|
|
93
|
+
var path = createRoundedPolygonPath(points, radius);
|
|
94
|
+
attrs.d = path;
|
|
95
|
+
return _jsx("path", __assign({}, attrs));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
attrs.points = points.map(function (point) { return point.join(','); }).join(' ');
|
|
99
|
+
return _jsx("polygon", __assign({}, attrs));
|
|
100
|
+
}
|
|
54
101
|
}
|
|
55
102
|
export default Polygon;
|
package/lib/LogicFlow.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import History from './history';
|
|
|
8
8
|
import Keyboard from './keyboard';
|
|
9
9
|
import { EventCallback, CallbackArgs, EventArgs } from './event/eventEmitter';
|
|
10
10
|
import { EventType, SegmentDirection } from './constant';
|
|
11
|
+
import { Grid } from './view/overlay';
|
|
11
12
|
import Extension = LogicFlow.Extension;
|
|
12
13
|
import ExtensionConfig = LogicFlow.ExtensionConfig;
|
|
13
14
|
import ExtensionConstructor = LogicFlow.ExtensionConstructor;
|
|
@@ -263,6 +264,11 @@ export declare class LogicFlow {
|
|
|
263
264
|
* @param toFront 是否将选中的元素置顶,默认为true
|
|
264
265
|
*/
|
|
265
266
|
selectElementById(id: string, multiple?: boolean, toFront?: boolean): void;
|
|
267
|
+
/**
|
|
268
|
+
* 移除选中的元素
|
|
269
|
+
* @param id 元素ID
|
|
270
|
+
*/
|
|
271
|
+
deselectElementById(id: string): void;
|
|
266
272
|
/**
|
|
267
273
|
* 获取选中的元素数据
|
|
268
274
|
* @param isIgnoreCheck 是否包括sourceNode和targetNode没有被选中的边,默认包括。
|
|
@@ -309,7 +315,7 @@ export declare class LogicFlow {
|
|
|
309
315
|
getAreaElement(leftTopPoint: PointTuple, rightBottomPoint: PointTuple, wholeEdge?: boolean, wholeNode?: boolean, ignoreHideElement?: boolean): (EdgeData | NodeData)[];
|
|
310
316
|
/**
|
|
311
317
|
* 设置元素的自定义属性
|
|
312
|
-
* @see
|
|
318
|
+
* @see http://logicflow.cn/api/detail#setproperties
|
|
313
319
|
* @param id 元素的id
|
|
314
320
|
* @param properties 自定义属性
|
|
315
321
|
*/
|
|
@@ -351,12 +357,12 @@ export declare class LogicFlow {
|
|
|
351
357
|
/**
|
|
352
358
|
* 更新流程图编辑相关设置
|
|
353
359
|
* @param {object} config 编辑配置
|
|
354
|
-
* @see
|
|
360
|
+
* @see http://logicflow.cn/api/detail#updateeditconfig
|
|
355
361
|
*/
|
|
356
362
|
updateEditConfig(config: Partial<IEditConfigType>): void;
|
|
357
363
|
/**
|
|
358
364
|
* 获取流程图当前编辑相关设置
|
|
359
|
-
* @see
|
|
365
|
+
* @see http://logicflow.cn/api/detail#geteditconfig
|
|
360
366
|
*/
|
|
361
367
|
getEditConfig(): _Model.IEditConfigType;
|
|
362
368
|
/*********************************************************
|
|
@@ -367,7 +373,12 @@ export declare class LogicFlow {
|
|
|
367
373
|
* @param { object } style 自定义主题样式
|
|
368
374
|
* todo docs link
|
|
369
375
|
*/
|
|
370
|
-
setTheme(style: Partial<LogicFlow.Theme
|
|
376
|
+
setTheme(style: Partial<LogicFlow.Theme>, themeMode?: 'radius' | 'dark' | 'colorful' | 'default' | string): void;
|
|
377
|
+
/**
|
|
378
|
+
* 获取当前主题样式
|
|
379
|
+
* @see todo docs link
|
|
380
|
+
*/
|
|
381
|
+
getTheme(): LogicFlow.Theme;
|
|
371
382
|
private focusByElement;
|
|
372
383
|
private focusByCoordinate;
|
|
373
384
|
/**
|
|
@@ -563,6 +574,14 @@ export declare class LogicFlow {
|
|
|
563
574
|
* @param props
|
|
564
575
|
*/
|
|
565
576
|
static use(extension: ExtensionConstructor | ExtensionDefinition, props?: Record<string, unknown>): void;
|
|
577
|
+
/**
|
|
578
|
+
* 添加主题模式
|
|
579
|
+
* @param themeMode 主题模式
|
|
580
|
+
* @param style 主题样式
|
|
581
|
+
*/
|
|
582
|
+
static addThemeMode(themeMode: string, style: Partial<LogicFlow.Theme>): void;
|
|
583
|
+
static removeThemeMode(themeMode: string): void;
|
|
584
|
+
static clearThemeMode(): void;
|
|
566
585
|
private installPlugins;
|
|
567
586
|
/**
|
|
568
587
|
* 加载插件-内部方法
|
|
@@ -893,6 +912,10 @@ export declare namespace LogicFlow {
|
|
|
893
912
|
refX?: number;
|
|
894
913
|
refY?: number;
|
|
895
914
|
verticalLength: number;
|
|
915
|
+
endArrowType?: 'solid' | 'hollow' | 'diamond' | 'circle' | 'none';
|
|
916
|
+
startArrowType?: 'solid' | 'hollow' | 'diamond' | 'circle' | 'none';
|
|
917
|
+
strokeLinecap?: 'butt' | 'round' | 'square';
|
|
918
|
+
strokeLinejoin?: 'miter' | 'round' | 'bevel';
|
|
896
919
|
} & CommonTheme;
|
|
897
920
|
type ArrowAttributesType = {
|
|
898
921
|
d: string;
|
|
@@ -940,6 +963,8 @@ export declare namespace LogicFlow {
|
|
|
940
963
|
edgeAdjust: CircleTheme;
|
|
941
964
|
outline: OutlineTheme;
|
|
942
965
|
edgeAnimation: EdgeAnimation;
|
|
966
|
+
background?: boolean | Partial<LFOptions.BackgroundConfig>;
|
|
967
|
+
grid?: boolean | Partial<Grid.GridOptions>;
|
|
943
968
|
}
|
|
944
969
|
}
|
|
945
970
|
export declare namespace LogicFlow {
|
package/lib/LogicFlow.js
CHANGED
|
@@ -669,6 +669,13 @@ var LogicFlow = /** @class */ (function () {
|
|
|
669
669
|
this.graphModel.toFront(id);
|
|
670
670
|
}
|
|
671
671
|
};
|
|
672
|
+
/**
|
|
673
|
+
* 移除选中的元素
|
|
674
|
+
* @param id 元素ID
|
|
675
|
+
*/
|
|
676
|
+
LogicFlow.prototype.deselectElementById = function (id) {
|
|
677
|
+
this.graphModel.deselectElementById(id);
|
|
678
|
+
};
|
|
672
679
|
/**
|
|
673
680
|
* 获取选中的元素数据
|
|
674
681
|
* @param isIgnoreCheck 是否包括sourceNode和targetNode没有被选中的边,默认包括。
|
|
@@ -745,7 +752,7 @@ var LogicFlow = /** @class */ (function () {
|
|
|
745
752
|
};
|
|
746
753
|
/**
|
|
747
754
|
* 设置元素的自定义属性
|
|
748
|
-
* @see
|
|
755
|
+
* @see http://logicflow.cn/api/detail#setproperties
|
|
749
756
|
* @param id 元素的id
|
|
750
757
|
* @param properties 自定义属性
|
|
751
758
|
*/
|
|
@@ -802,7 +809,7 @@ var LogicFlow = /** @class */ (function () {
|
|
|
802
809
|
/**
|
|
803
810
|
* 更新流程图编辑相关设置
|
|
804
811
|
* @param {object} config 编辑配置
|
|
805
|
-
* @see
|
|
812
|
+
* @see http://logicflow.cn/api/detail#updateeditconfig
|
|
806
813
|
*/
|
|
807
814
|
LogicFlow.prototype.updateEditConfig = function (config) {
|
|
808
815
|
var _a = this.graphModel, editConfigModel = _a.editConfigModel, transformModel = _a.transformModel;
|
|
@@ -821,7 +828,7 @@ var LogicFlow = /** @class */ (function () {
|
|
|
821
828
|
};
|
|
822
829
|
/**
|
|
823
830
|
* 获取流程图当前编辑相关设置
|
|
824
|
-
* @see
|
|
831
|
+
* @see http://logicflow.cn/api/detail#geteditconfig
|
|
825
832
|
*/
|
|
826
833
|
LogicFlow.prototype.getEditConfig = function () {
|
|
827
834
|
return this.graphModel.editConfigModel.getConfig();
|
|
@@ -834,8 +841,15 @@ var LogicFlow = /** @class */ (function () {
|
|
|
834
841
|
* @param { object } style 自定义主题样式
|
|
835
842
|
* todo docs link
|
|
836
843
|
*/
|
|
837
|
-
LogicFlow.prototype.setTheme = function (style) {
|
|
838
|
-
this.graphModel.setTheme(style);
|
|
844
|
+
LogicFlow.prototype.setTheme = function (style, themeMode) {
|
|
845
|
+
this.graphModel.setTheme(style, themeMode);
|
|
846
|
+
};
|
|
847
|
+
/**
|
|
848
|
+
* 获取当前主题样式
|
|
849
|
+
* @see todo docs link
|
|
850
|
+
*/
|
|
851
|
+
LogicFlow.prototype.getTheme = function () {
|
|
852
|
+
return this.graphModel.getTheme();
|
|
839
853
|
};
|
|
840
854
|
LogicFlow.prototype.focusByElement = function (id) {
|
|
841
855
|
var coordinate = undefined;
|
|
@@ -1150,6 +1164,20 @@ var LogicFlow = /** @class */ (function () {
|
|
|
1150
1164
|
_a.props = props,
|
|
1151
1165
|
_a));
|
|
1152
1166
|
};
|
|
1167
|
+
/**
|
|
1168
|
+
* 添加主题模式
|
|
1169
|
+
* @param themeMode 主题模式
|
|
1170
|
+
* @param style 主题样式
|
|
1171
|
+
*/
|
|
1172
|
+
LogicFlow.addThemeMode = function (themeMode, style) {
|
|
1173
|
+
(0, util_1.addThemeMode)(themeMode, style);
|
|
1174
|
+
};
|
|
1175
|
+
LogicFlow.removeThemeMode = function (themeMode) {
|
|
1176
|
+
(0, util_1.removeThemeMode)(themeMode);
|
|
1177
|
+
};
|
|
1178
|
+
LogicFlow.clearThemeMode = function () {
|
|
1179
|
+
(0, util_1.clearThemeMode)();
|
|
1180
|
+
};
|
|
1153
1181
|
LogicFlow.prototype.installPlugins = function (disabledPlugins) {
|
|
1154
1182
|
var _this = this;
|
|
1155
1183
|
if (disabledPlugins === void 0) { disabledPlugins = []; }
|
|
@@ -1212,6 +1240,7 @@ var LogicFlow = /** @class */ (function () {
|
|
|
1212
1240
|
this.graphModel.destroy();
|
|
1213
1241
|
this.tool.destroy();
|
|
1214
1242
|
this.history.destroy();
|
|
1243
|
+
this.clearThemeMode();
|
|
1215
1244
|
for (var extensionName in this.extension) {
|
|
1216
1245
|
var extensionInstance = this.extension[extensionName];
|
|
1217
1246
|
if ('destroy' in extensionInstance) {
|
|
@@ -17,6 +17,7 @@ export declare class GraphModel {
|
|
|
17
17
|
width: number;
|
|
18
18
|
height: number;
|
|
19
19
|
theme: LogicFlow.Theme;
|
|
20
|
+
customStyles: object;
|
|
20
21
|
grid: Grid.GridOptions;
|
|
21
22
|
readonly eventCenter: EventEmitter;
|
|
22
23
|
readonly modelMap: Map<string, LogicFlow.GraphElementCtor>;
|
|
@@ -322,6 +323,7 @@ export declare class GraphModel {
|
|
|
322
323
|
* @param multiple 是否允许多选,如果为true,不会将上一个选中的元素重置
|
|
323
324
|
*/
|
|
324
325
|
selectElementById(id: string, multiple?: boolean): void;
|
|
326
|
+
deselectElementById(id: string): void;
|
|
325
327
|
/**
|
|
326
328
|
* 将所有选中的元素设置为非选中
|
|
327
329
|
*/
|
|
@@ -393,7 +395,39 @@ export declare class GraphModel {
|
|
|
393
395
|
* 设置主题
|
|
394
396
|
* todo docs link
|
|
395
397
|
*/
|
|
396
|
-
setTheme(style: Partial<LogicFlow.Theme
|
|
398
|
+
setTheme(style: Partial<LogicFlow.Theme>, themeMode?: 'radius' | 'dark' | 'colorful' | 'default' | string): void;
|
|
399
|
+
/**
|
|
400
|
+
* 设置主题
|
|
401
|
+
* todo docs link
|
|
402
|
+
*/
|
|
403
|
+
getTheme(): {
|
|
404
|
+
background: boolean | LFOptions.BackgroundConfig | undefined;
|
|
405
|
+
grid: Grid.GridOptions;
|
|
406
|
+
baseNode: LogicFlow.CommonTheme;
|
|
407
|
+
baseEdge: LogicFlow.CommonTheme;
|
|
408
|
+
rect: LogicFlow.CommonTheme;
|
|
409
|
+
circle: LogicFlow.CommonTheme;
|
|
410
|
+
diamond: LogicFlow.CommonTheme;
|
|
411
|
+
ellipse: LogicFlow.CommonTheme;
|
|
412
|
+
polygon: LogicFlow.CommonTheme;
|
|
413
|
+
line: LogicFlow.CommonTheme;
|
|
414
|
+
polyline: LogicFlow.CommonTheme;
|
|
415
|
+
bezier: LogicFlow.EdgeBezierTheme;
|
|
416
|
+
anchorLine: LogicFlow.AnchorLineTheme;
|
|
417
|
+
text: LogicFlow.TextNodeTheme;
|
|
418
|
+
nodeText: LogicFlow.NodeTextTheme;
|
|
419
|
+
edgeText: LogicFlow.EdgeTextTheme;
|
|
420
|
+
inputText?: LogicFlow.CommonTheme | undefined;
|
|
421
|
+
anchor: LogicFlow.AnchorTheme;
|
|
422
|
+
arrow: LogicFlow.ArrowTheme;
|
|
423
|
+
snapline: LogicFlow.CommonTheme;
|
|
424
|
+
rotateControl: LogicFlow.CommonTheme;
|
|
425
|
+
resizeControl: LogicFlow.CommonTheme;
|
|
426
|
+
resizeOutline: LogicFlow.CommonTheme;
|
|
427
|
+
edgeAdjust: LogicFlow.CommonTheme;
|
|
428
|
+
outline: LogicFlow.OutlineTheme;
|
|
429
|
+
edgeAnimation: LogicFlow.EdgeAnimation;
|
|
430
|
+
};
|
|
397
431
|
/**
|
|
398
432
|
* 更新网格配置
|
|
399
433
|
*/
|
package/lib/model/GraphModel.js
CHANGED
|
@@ -110,8 +110,11 @@ var GraphModel = /** @class */ (function () {
|
|
|
110
110
|
// TODO:需要让用户设置成 0 吗?后面可以讨论一下
|
|
111
111
|
this.gridSize = grid.size || 1; // 默认 gridSize 设置为 1
|
|
112
112
|
}
|
|
113
|
-
this.
|
|
113
|
+
this.customStyles = options.style || {};
|
|
114
114
|
this.grid = overlay_1.Grid.getGridOptions(grid !== null && grid !== void 0 ? grid : false);
|
|
115
|
+
this.theme = (0, util_1.setupTheme)(options.style, options.themeMode);
|
|
116
|
+
this.theme.grid = (0, lodash_es_1.cloneDeep)(this.grid);
|
|
117
|
+
this.theme.background = (0, lodash_es_1.cloneDeep)(this.background);
|
|
115
118
|
this.edgeType = options.edgeType || 'polyline';
|
|
116
119
|
this.animation = (0, util_1.setupAnimation)(animation);
|
|
117
120
|
this.overlapMode = options.overlapMode || constant_1.OverlapMode.DEFAULT;
|
|
@@ -1060,6 +1063,12 @@ var GraphModel = /** @class */ (function () {
|
|
|
1060
1063
|
var selectElement = this.getElement(id);
|
|
1061
1064
|
selectElement === null || selectElement === void 0 ? void 0 : selectElement.setSelected(true);
|
|
1062
1065
|
};
|
|
1066
|
+
GraphModel.prototype.deselectElementById = function (id) {
|
|
1067
|
+
var element = this.getElement(id);
|
|
1068
|
+
if (element) {
|
|
1069
|
+
element.setSelected(false);
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1063
1072
|
/**
|
|
1064
1073
|
* 将所有选中的元素设置为非选中
|
|
1065
1074
|
*/
|
|
@@ -1298,8 +1307,33 @@ var GraphModel = /** @class */ (function () {
|
|
|
1298
1307
|
* 设置主题
|
|
1299
1308
|
* todo docs link
|
|
1300
1309
|
*/
|
|
1301
|
-
GraphModel.prototype.setTheme = function (style) {
|
|
1302
|
-
|
|
1310
|
+
GraphModel.prototype.setTheme = function (style, themeMode) {
|
|
1311
|
+
var _a;
|
|
1312
|
+
if (themeMode) {
|
|
1313
|
+
// 修改背景颜色
|
|
1314
|
+
util_1.backgroundModeMap[themeMode] &&
|
|
1315
|
+
this.updateBackgroundOptions(__assign(__assign({}, (typeof this.background === 'object' ? this.background : {})), util_1.backgroundModeMap[themeMode]));
|
|
1316
|
+
util_1.gridModeMap[themeMode] &&
|
|
1317
|
+
this.updateGridOptions(overlay_1.Grid.getGridOptions(__assign(__assign({}, this.grid), util_1.gridModeMap[themeMode])));
|
|
1318
|
+
}
|
|
1319
|
+
if (style.background) {
|
|
1320
|
+
this.updateBackgroundOptions(style.background);
|
|
1321
|
+
}
|
|
1322
|
+
if (style.grid) {
|
|
1323
|
+
var formattedGrid = overlay_1.Grid.getGridOptions((_a = style.grid) !== null && _a !== void 0 ? _a : false);
|
|
1324
|
+
this.updateGridOptions(formattedGrid);
|
|
1325
|
+
}
|
|
1326
|
+
this.theme = (0, util_1.updateTheme)(__assign(__assign({}, this.customStyles), style), themeMode);
|
|
1327
|
+
this.customStyles = __assign(__assign({}, this.customStyles), style);
|
|
1328
|
+
};
|
|
1329
|
+
/**
|
|
1330
|
+
* 设置主题
|
|
1331
|
+
* todo docs link
|
|
1332
|
+
*/
|
|
1333
|
+
GraphModel.prototype.getTheme = function () {
|
|
1334
|
+
var _a = this, background = _a.background, grid = _a.grid;
|
|
1335
|
+
var theme = __assign(__assign({}, (0, lodash_es_1.cloneDeep)(this.theme)), { background: background, grid: grid });
|
|
1336
|
+
return theme;
|
|
1303
1337
|
};
|
|
1304
1338
|
/**
|
|
1305
1339
|
* 更新网格配置
|
|
@@ -1596,6 +1630,9 @@ var GraphModel = /** @class */ (function () {
|
|
|
1596
1630
|
__decorate([
|
|
1597
1631
|
mobx_1.action
|
|
1598
1632
|
], GraphModel.prototype, "selectElementById", null);
|
|
1633
|
+
__decorate([
|
|
1634
|
+
mobx_1.action
|
|
1635
|
+
], GraphModel.prototype, "deselectElementById", null);
|
|
1599
1636
|
__decorate([
|
|
1600
1637
|
mobx_1.action
|
|
1601
1638
|
], GraphModel.prototype, "clearSelectElements", null);
|
|
@@ -1632,6 +1669,9 @@ var GraphModel = /** @class */ (function () {
|
|
|
1632
1669
|
__decorate([
|
|
1633
1670
|
mobx_1.action
|
|
1634
1671
|
], GraphModel.prototype, "setTheme", null);
|
|
1672
|
+
__decorate([
|
|
1673
|
+
mobx_1.action
|
|
1674
|
+
], GraphModel.prototype, "getTheme", null);
|
|
1635
1675
|
__decorate([
|
|
1636
1676
|
mobx_1.action
|
|
1637
1677
|
], GraphModel.prototype, "resize", null);
|
|
@@ -57,6 +57,7 @@ var RectNodeModel = /** @class */ (function (_super) {
|
|
|
57
57
|
RectNodeModel.prototype.setAttributes = function () {
|
|
58
58
|
_super.prototype.setAttributes.call(this);
|
|
59
59
|
var _a = this.properties, width = _a.width, height = _a.height, radius = _a.radius;
|
|
60
|
+
var styleRadius = this.getNodeStyle().radius;
|
|
60
61
|
if (!(0, lodash_es_1.isNil)(width))
|
|
61
62
|
this.width = width;
|
|
62
63
|
if (!(0, lodash_es_1.isNil)(height))
|
|
@@ -64,6 +65,8 @@ var RectNodeModel = /** @class */ (function (_super) {
|
|
|
64
65
|
// 矩形特有
|
|
65
66
|
if (!(0, lodash_es_1.isNil)(radius))
|
|
66
67
|
this.radius = radius;
|
|
68
|
+
if (!(0, lodash_es_1.isNil)(styleRadius))
|
|
69
|
+
this.radius = styleRadius;
|
|
67
70
|
};
|
|
68
71
|
RectNodeModel.prototype.getDefaultAnchor = function () {
|
|
69
72
|
var _a = this, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
package/lib/options.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ export declare namespace Options {
|
|
|
66
66
|
idGenerator?: (type?: string) => string;
|
|
67
67
|
edgeGenerator?: EdgeGeneratorType;
|
|
68
68
|
customTrajectory?: (props: CustomAnchorLineProps) => h.JSX.Element;
|
|
69
|
+
themeMode?: 'radius' | 'dark' | 'colorful';
|
|
69
70
|
[key: string]: unknown;
|
|
70
71
|
}
|
|
71
72
|
interface ManualBooleans {
|