@logicflow/core 2.0.0-beta.0 → 2.0.0-beta.2
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 +14 -20
- package/dist/index.min.js +26 -0
- package/dist/index.min.js.map +1 -0
- package/es/LogicFlow.d.ts +30 -18
- package/es/LogicFlow.js +22 -20
- package/es/LogicFlow.js.map +1 -1
- package/es/model/edge/BaseEdgeModel.js.map +1 -1
- package/es/options.d.ts +7 -13
- package/es/options.js +1 -31
- package/es/options.js.map +1 -1
- package/es/view/Graph.js +2 -2
- package/es/view/Graph.js.map +1 -1
- package/es/view/overlay/Grid.d.ts +35 -20
- package/es/view/overlay/Grid.js +35 -26
- package/es/view/overlay/Grid.js.map +1 -1
- package/lib/LogicFlow.d.ts +30 -18
- package/lib/LogicFlow.js +21 -19
- package/lib/LogicFlow.js.map +1 -1
- package/lib/model/edge/BaseEdgeModel.js.map +1 -1
- package/lib/options.d.ts +7 -13
- package/lib/options.js +1 -31
- package/lib/options.js.map +1 -1
- package/lib/view/Graph.js +2 -2
- package/lib/view/Graph.js.map +1 -1
- package/lib/view/overlay/Grid.d.ts +35 -20
- package/lib/view/overlay/Grid.js +35 -26
- package/lib/view/overlay/Grid.js.map +1 -1
- package/package.json +4 -4
- package/src/LogicFlow.tsx +79 -49
- package/src/model/edge/BaseEdgeModel.ts +32 -0
- package/src/options.ts +10 -41
- package/src/view/Graph.tsx +2 -2
- package/src/view/overlay/Grid.tsx +75 -53
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
import { Component } from 'preact/compat';
|
|
2
2
|
import { GraphModel } from '../../model';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* 网格格子间距
|
|
6
|
-
*/
|
|
7
|
-
size?: number;
|
|
8
|
-
/**
|
|
9
|
-
* 网格是否可见
|
|
10
|
-
*/
|
|
11
|
-
visible?: boolean;
|
|
3
|
+
import GridOptions = Grid.GridOptions;
|
|
4
|
+
type IProps = GridOptions & {
|
|
12
5
|
graphModel: GraphModel;
|
|
13
|
-
/**
|
|
14
|
-
* 网格类型
|
|
15
|
-
* 'dot' || 'mesh'
|
|
16
|
-
*/
|
|
17
|
-
type?: string;
|
|
18
|
-
config?: {
|
|
19
|
-
color: string;
|
|
20
|
-
thickness?: number;
|
|
21
|
-
};
|
|
22
6
|
};
|
|
23
|
-
type IProps = GridOptions;
|
|
24
7
|
export declare class Grid extends Component<IProps> {
|
|
25
8
|
readonly id: string;
|
|
26
9
|
renderDot(): import("preact/compat").JSX.Element;
|
|
27
10
|
renderMesh(): import("preact/compat").JSX.Element;
|
|
28
11
|
render(): import("preact/compat").JSX.Element;
|
|
29
12
|
}
|
|
30
|
-
export
|
|
13
|
+
export declare namespace Grid {
|
|
14
|
+
type GridOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* 网格格子间距
|
|
17
|
+
*/
|
|
18
|
+
size?: number;
|
|
19
|
+
/**
|
|
20
|
+
* 网格是否可见
|
|
21
|
+
*/
|
|
22
|
+
visible?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 网格类型
|
|
25
|
+
* - `dot` 点状网格
|
|
26
|
+
* - `mesh` 交叉线网格
|
|
27
|
+
*/
|
|
28
|
+
type?: 'dot' | 'mesh';
|
|
29
|
+
config?: {
|
|
30
|
+
/**
|
|
31
|
+
* 网格的颜色
|
|
32
|
+
*/
|
|
33
|
+
color: string;
|
|
34
|
+
/**
|
|
35
|
+
* 网格的宽度
|
|
36
|
+
* - 对于 `dot` 点状网格,表示点的大小
|
|
37
|
+
* - 对于 `mesh` 交叉线网格,表示线的宽度
|
|
38
|
+
*/
|
|
39
|
+
thickness?: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const defaultProps: GridOptions;
|
|
43
|
+
function getGridOptions(options: number | boolean | GridOptions): GridOptions;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
package/lib/view/overlay/Grid.js
CHANGED
|
@@ -49,6 +49,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
49
49
|
exports.Grid = void 0;
|
|
50
50
|
var jsx_runtime_1 = require("preact/jsx-runtime");
|
|
51
51
|
var compat_1 = require("preact/compat");
|
|
52
|
+
var lodash_es_1 = require("lodash-es");
|
|
52
53
|
var __1 = require("../..");
|
|
53
54
|
var util_1 = require("../../util");
|
|
54
55
|
var constant_1 = require("../../constant");
|
|
@@ -63,30 +64,24 @@ var Grid = /** @class */ (function (_super) {
|
|
|
63
64
|
Grid.prototype.renderDot = function () {
|
|
64
65
|
var _a = this.props, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
|
|
65
66
|
var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 2 : _d;
|
|
66
|
-
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
/* eslint-disable-next-line */
|
|
72
|
-
return ((0, jsx_runtime_1.jsx)("rect", { width: length, height: length, rx: length / 2, ry: length / 2, fill: color, opacity: opacity }));
|
|
67
|
+
// 对于点状网格,点的半径不能大于网格大小的四分之一
|
|
68
|
+
var radius = Math.min(Math.max(2, thickness), size / 4);
|
|
69
|
+
var opacity = visible ? 1 : 0;
|
|
70
|
+
return ((0, jsx_runtime_1.jsxs)("g", { fill: color, opacity: opacity, children: [(0, jsx_runtime_1.jsx)("circle", { cx: 0, cy: 0, r: radius / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: 0, cy: size, r: radius / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: size, cy: 0, r: radius / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: size, cy: size, r: radius / 2 })] }));
|
|
73
71
|
};
|
|
74
72
|
// 网格类型为交叉线
|
|
75
73
|
// todo: 采用背景缩放的方式,实现更好的体验
|
|
76
74
|
Grid.prototype.renderMesh = function () {
|
|
77
75
|
var _a = this.props, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
|
|
78
76
|
var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 1 : _d;
|
|
79
|
-
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
return ((0, jsx_runtime_1.jsx)("path", { d: d, stroke: color, strokeWidth: strokeWidth, opacity: opacity }));
|
|
77
|
+
// 对于交叉线网格,线的宽度不能大于网格大小的一半
|
|
78
|
+
var strokeWidth = Math.min(Math.max(1, thickness), size / 2);
|
|
79
|
+
var d = "M 0 0 H ".concat(size, " V ").concat(size, " H 0 Z");
|
|
80
|
+
var opacity = visible ? 1 : 0;
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)("path", { d: d, stroke: color, strokeWidth: strokeWidth, opacity: opacity, fill: "transparent" }));
|
|
86
82
|
};
|
|
87
83
|
Grid.prototype.render = function () {
|
|
88
|
-
|
|
89
|
-
var _a = this.props, type = _a.type, size = _a.size, transformModel = _a.graphModel.transformModel;
|
|
84
|
+
var _a = this.props, type = _a.type, _b = _a.size, size = _b === void 0 ? 1 : _b, transformModel = _a.graphModel.transformModel;
|
|
90
85
|
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;
|
|
91
86
|
var matrixString = [
|
|
92
87
|
SCALE_X,
|
|
@@ -108,14 +103,28 @@ var Grid = /** @class */ (function (_super) {
|
|
|
108
103
|
return Grid;
|
|
109
104
|
}(compat_1.Component));
|
|
110
105
|
exports.Grid = Grid;
|
|
111
|
-
Grid
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
106
|
+
(function (Grid) {
|
|
107
|
+
Grid.defaultProps = {
|
|
108
|
+
size: constant_1.DEFAULT_GRID_SIZE,
|
|
109
|
+
visible: true,
|
|
110
|
+
type: 'dot',
|
|
111
|
+
config: {
|
|
112
|
+
color: '#ababab',
|
|
113
|
+
thickness: 1,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
function getGridOptions(options) {
|
|
117
|
+
var defaultOptions = (0, lodash_es_1.cloneDeep)(Grid.defaultProps);
|
|
118
|
+
if (typeof options === 'number') {
|
|
119
|
+
return (0, lodash_es_1.assign)(defaultOptions, { size: options });
|
|
120
|
+
}
|
|
121
|
+
else if (typeof options === 'boolean') {
|
|
122
|
+
return (0, lodash_es_1.assign)(defaultOptions, { visible: options });
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return (0, lodash_es_1.assign)(defaultOptions, options);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
Grid.getGridOptions = getGridOptions;
|
|
129
|
+
})(Grid || (exports.Grid = Grid = {}));
|
|
121
130
|
//# sourceMappingURL=Grid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.js","sourceRoot":"","sources":["../../../src/view/overlay/Grid.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAyC;AACzC,2BAAgC;AAChC,mCAAuC;AAEvC,2CAAkD;
|
|
1
|
+
{"version":3,"file":"Grid.js","sourceRoot":"","sources":["../../../src/view/overlay/Grid.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAyC;AACzC,uCAA6C;AAC7C,2BAAgC;AAChC,mCAAuC;AAEvC,2CAAkD;AASlD;IAA0B,wBAAiB;IAA3C;;QACW,QAAE,GAAG,IAAA,iBAAU,GAAE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M,EAAC,cAAc,EAAE,OAAO,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IATe,mBAAc,iBAS7B,CAAA;AACH,CAAC,EAlDgB,IAAI,oBAAJ,IAAI,QAkDpB"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logicflow/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "LogicFlow, help you quickly create flowcharts",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
|
-
"unpkg": "dist/index.js",
|
|
9
|
-
"jsdelivr": "dist/index.js",
|
|
8
|
+
"unpkg": "dist/index.min.js",
|
|
9
|
+
"jsdelivr": "dist/index.min.js",
|
|
10
10
|
"homepage": "https://site.logic-flow.cn",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
package/src/LogicFlow.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentType, createElement as h, render } from 'preact/compat'
|
|
2
|
-
import { cloneDeep, forEach } from 'lodash-es'
|
|
2
|
+
import { cloneDeep, forEach, indexOf } from 'lodash-es'
|
|
3
3
|
import { observer } from '.'
|
|
4
4
|
import { Options as LFOptions } from './options'
|
|
5
5
|
import * as _Model from './model'
|
|
@@ -24,8 +24,9 @@ import History from './history'
|
|
|
24
24
|
import { EventCallback, CallbackArgs, EventArgs } from './event/eventEmitter'
|
|
25
25
|
import { ElementType, EventType, SegmentDirection } from './constant'
|
|
26
26
|
import { initDefaultShortcut } from './keyboard/shortcut'
|
|
27
|
+
|
|
27
28
|
import Extension = LogicFlow.Extension
|
|
28
|
-
import
|
|
29
|
+
import ExtensionConfig = LogicFlow.ExtensionConfig
|
|
29
30
|
import ExtensionConstructor = LogicFlow.ExtensionConstructor
|
|
30
31
|
import GraphConfigData = LogicFlow.GraphConfigData
|
|
31
32
|
import NodeConfig = LogicFlow.NodeConfig
|
|
@@ -38,11 +39,13 @@ import RegisterParam = LogicFlow.RegisterParam
|
|
|
38
39
|
import GraphElements = LogicFlow.GraphElements
|
|
39
40
|
import Position = LogicFlow.Position
|
|
40
41
|
import PointTuple = LogicFlow.PointTuple
|
|
41
|
-
import
|
|
42
|
+
import ExtensionRenderFunc = LogicFlow.ExtensionRenderFunc
|
|
42
43
|
import RegisterElementFunc = LogicFlow.RegisterElementFunc
|
|
43
44
|
import PropertiesType = LogicFlow.PropertiesType
|
|
44
45
|
import BaseNodeModelCtor = LogicFlow.BaseNodeModelCtor
|
|
45
46
|
import ClientPosition = LogicFlow.ClientPosition
|
|
47
|
+
import ExtensionDefinition = LogicFlow.ExtensionDefinition
|
|
48
|
+
import ExtensionType = LogicFlow.ExtensionType
|
|
46
49
|
|
|
47
50
|
const pluginFlag = Symbol('plugin registered by Logicflow.use')
|
|
48
51
|
|
|
@@ -61,13 +64,13 @@ export class LogicFlow {
|
|
|
61
64
|
tool: Tool
|
|
62
65
|
snaplineModel?: SnaplineModel
|
|
63
66
|
|
|
64
|
-
components:
|
|
67
|
+
components: ExtensionRenderFunc[] = []
|
|
65
68
|
// 个性配置的插件,覆盖全局配置的插件
|
|
66
|
-
readonly plugins:
|
|
69
|
+
readonly plugins: ExtensionType[]
|
|
67
70
|
// 全局配置的插件,所有的LogicFlow示例都会使用
|
|
68
|
-
static extensions: Map<string,
|
|
71
|
+
static extensions: Map<string, ExtensionConfig> = new Map()
|
|
69
72
|
// 插件扩展方法
|
|
70
|
-
extension: Record<string, Extension> = {}
|
|
73
|
+
extension: Record<string, Extension | ExtensionDefinition> = {}
|
|
71
74
|
|
|
72
75
|
readonly width?: number // 只读:画布宽度
|
|
73
76
|
readonly height?: number // 只读:画布高度
|
|
@@ -1292,19 +1295,14 @@ export class LogicFlow {
|
|
|
1292
1295
|
* @param props
|
|
1293
1296
|
*/
|
|
1294
1297
|
static use(
|
|
1295
|
-
extension: ExtensionConstructor,
|
|
1298
|
+
extension: ExtensionConstructor | ExtensionDefinition,
|
|
1296
1299
|
props?: Record<string, unknown>,
|
|
1297
1300
|
): void {
|
|
1298
|
-
|
|
1301
|
+
const { pluginName } = extension
|
|
1299
1302
|
if (!pluginName) {
|
|
1300
|
-
|
|
1301
|
-
`请给插件${
|
|
1302
|
-
extension.name || extension.constructor.name
|
|
1303
|
-
}指定pluginName!`,
|
|
1304
|
-
)
|
|
1305
|
-
pluginName = extension.name // 兼容以前name的情况,1.0版本去掉。
|
|
1303
|
+
throw new Error(`请给插件指定 pluginName!`)
|
|
1306
1304
|
}
|
|
1307
|
-
// TODO:
|
|
1305
|
+
// TODO: 应该在何时进行插件的销毁???
|
|
1308
1306
|
// const preExtension = this.extensions.get(pluginName)?.extension
|
|
1309
1307
|
// preExtension?.destroy?.() // 该代码应该有问题,因为 preExtension 直接用的是 Constructor,没有实例化。无法访问实例方法 destroy
|
|
1310
1308
|
|
|
@@ -1316,19 +1314,26 @@ export class LogicFlow {
|
|
|
1316
1314
|
}
|
|
1317
1315
|
|
|
1318
1316
|
private installPlugins(disabledPlugins: string[] = []) {
|
|
1317
|
+
const extensionsAddByUse = Array.from(
|
|
1318
|
+
LogicFlow.extensions,
|
|
1319
|
+
([, extension]) => extension,
|
|
1320
|
+
)
|
|
1319
1321
|
// 安装插件,优先使用个性插件
|
|
1320
|
-
const extensions = this.plugins
|
|
1321
|
-
|
|
1322
|
-
let extension:
|
|
1323
|
-
let props
|
|
1324
|
-
|
|
1322
|
+
const extensions = [...extensionsAddByUse, ...this.plugins]
|
|
1323
|
+
forEach(extensions, (ext) => {
|
|
1324
|
+
let extension: ExtensionConstructor | ExtensionDefinition
|
|
1325
|
+
let props: Record<string, any> | undefined
|
|
1326
|
+
|
|
1327
|
+
if (pluginFlag in ext) {
|
|
1325
1328
|
extension = ext.extension
|
|
1326
1329
|
props = ext.props
|
|
1327
1330
|
} else {
|
|
1328
1331
|
extension = ext
|
|
1329
1332
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1333
|
+
|
|
1334
|
+
const pluginName = extension?.pluginName
|
|
1335
|
+
|
|
1336
|
+
if (indexOf(disabledPlugins, pluginName) === -1) {
|
|
1332
1337
|
this.installPlugin(extension, props)
|
|
1333
1338
|
}
|
|
1334
1339
|
})
|
|
@@ -1337,31 +1342,38 @@ export class LogicFlow {
|
|
|
1337
1342
|
/**
|
|
1338
1343
|
* 加载插件-内部方法
|
|
1339
1344
|
*/
|
|
1340
|
-
private installPlugin(
|
|
1341
|
-
|
|
1342
|
-
|
|
1345
|
+
private installPlugin(
|
|
1346
|
+
extension: ExtensionConstructor | ExtensionDefinition,
|
|
1347
|
+
props?: Record<string, any>,
|
|
1348
|
+
) {
|
|
1349
|
+
if ('pluginName' in extension && 'install' in extension) {
|
|
1350
|
+
const { pluginName, install, render } = extension
|
|
1343
1351
|
if (pluginName) {
|
|
1344
1352
|
install && install.call(extension, this, LogicFlow)
|
|
1345
|
-
|
|
1353
|
+
render && this.components.push(render.bind(extension))
|
|
1346
1354
|
this.extension[pluginName] = extension
|
|
1347
1355
|
}
|
|
1348
1356
|
return
|
|
1349
1357
|
}
|
|
1350
|
-
|
|
1351
|
-
const
|
|
1358
|
+
|
|
1359
|
+
const ExtensionCtor = extension as ExtensionConstructor
|
|
1360
|
+
const extensionIns = new ExtensionCtor({
|
|
1352
1361
|
lf: this,
|
|
1353
1362
|
LogicFlow,
|
|
1354
|
-
options: this.options.pluginsOptions ?? {},
|
|
1355
1363
|
props,
|
|
1364
|
+
options: this.options.pluginsOptions ?? {},
|
|
1356
1365
|
})
|
|
1357
|
-
|
|
1358
|
-
this.components.push(
|
|
1359
|
-
this.extension[
|
|
1366
|
+
extensionIns.render &&
|
|
1367
|
+
this.components.push(extensionIns.render.bind(extensionIns))
|
|
1368
|
+
this.extension[ExtensionCtor.pluginName] = extensionIns
|
|
1360
1369
|
}
|
|
1361
1370
|
}
|
|
1362
1371
|
|
|
1363
1372
|
// Option
|
|
1364
1373
|
export namespace LogicFlow {
|
|
1374
|
+
/**
|
|
1375
|
+
* LogicFlow init Options
|
|
1376
|
+
*/
|
|
1365
1377
|
export interface Options extends LFOptions.Common {}
|
|
1366
1378
|
|
|
1367
1379
|
export type DomAttributes = {
|
|
@@ -1376,6 +1388,7 @@ export namespace LogicFlow {
|
|
|
1376
1388
|
ry?: number
|
|
1377
1389
|
} & Record<string, any>
|
|
1378
1390
|
export type AttributesType = Record<string, any>
|
|
1391
|
+
|
|
1379
1392
|
export type VectorData = {
|
|
1380
1393
|
deltaX: number
|
|
1381
1394
|
deltaY: number
|
|
@@ -1390,7 +1403,7 @@ export namespace LogicFlow {
|
|
|
1390
1403
|
}
|
|
1391
1404
|
export type Point = {
|
|
1392
1405
|
id?: string
|
|
1393
|
-
[key: string]: any
|
|
1406
|
+
[key: string]: any // TODO: 确认这个属性是干什么的呢?是有可以移除
|
|
1394
1407
|
} & Position
|
|
1395
1408
|
export type PointTuple = [number, number]
|
|
1396
1409
|
export type ClientPosition = {
|
|
@@ -1422,7 +1435,7 @@ export namespace LogicFlow {
|
|
|
1422
1435
|
value: string
|
|
1423
1436
|
editable?: boolean
|
|
1424
1437
|
draggable?: boolean
|
|
1425
|
-
} &
|
|
1438
|
+
} & Position
|
|
1426
1439
|
|
|
1427
1440
|
export type AppendConfig = {
|
|
1428
1441
|
startIndex: number
|
|
@@ -1755,8 +1768,14 @@ export namespace LogicFlow {
|
|
|
1755
1768
|
|
|
1756
1769
|
// Render or Functions
|
|
1757
1770
|
export namespace LogicFlow {
|
|
1758
|
-
type FocusOnById = {
|
|
1759
|
-
|
|
1771
|
+
type FocusOnById = {
|
|
1772
|
+
id: string
|
|
1773
|
+
coordinate?: never
|
|
1774
|
+
}
|
|
1775
|
+
type FocusOnByCoordinate = {
|
|
1776
|
+
id?: string
|
|
1777
|
+
coordinate: Position
|
|
1778
|
+
}
|
|
1760
1779
|
export type FocusOnArgsType = FocusOnById | FocusOnByCoordinate
|
|
1761
1780
|
|
|
1762
1781
|
export type BaseNodeModelCtor = typeof BaseNodeModel
|
|
@@ -1794,32 +1813,43 @@ export namespace LogicFlow {
|
|
|
1794
1813
|
new (options: LFOptions.Definition): LogicFlow
|
|
1795
1814
|
}
|
|
1796
1815
|
|
|
1797
|
-
|
|
1816
|
+
/**
|
|
1817
|
+
* Extension 插件类型
|
|
1818
|
+
*/
|
|
1819
|
+
export type ExtensionType = ExtensionConstructor | ExtensionDefinition
|
|
1820
|
+
export type ExtensionConfig = {
|
|
1798
1821
|
[pluginFlag]: symbol
|
|
1799
|
-
extension:
|
|
1800
|
-
props?: Record<string,
|
|
1822
|
+
extension: ExtensionType
|
|
1823
|
+
props?: Record<string, any> // TODO: 看这类型是否可以更精确
|
|
1801
1824
|
}
|
|
1802
1825
|
|
|
1803
|
-
export type
|
|
1826
|
+
export type IExtensionProps = {
|
|
1804
1827
|
lf: LogicFlow
|
|
1805
1828
|
LogicFlow: LogicFlowConstructor
|
|
1806
|
-
options: Record<string, unknown>
|
|
1807
1829
|
props?: Record<string, unknown>
|
|
1830
|
+
options: Record<string, unknown>
|
|
1808
1831
|
}
|
|
1809
1832
|
|
|
1810
1833
|
export interface ExtensionConstructor {
|
|
1811
1834
|
pluginName: string
|
|
1812
|
-
|
|
1813
|
-
new (props: ExtensionProps): Extension
|
|
1835
|
+
new (props: IExtensionProps): Extension
|
|
1814
1836
|
}
|
|
1815
1837
|
|
|
1816
|
-
export type
|
|
1838
|
+
export type ExtensionRenderFunc = (
|
|
1839
|
+
lf: LogicFlow,
|
|
1840
|
+
container: HTMLElement,
|
|
1841
|
+
) => void
|
|
1842
|
+
|
|
1843
|
+
// 对象形式定义的插件
|
|
1844
|
+
export type ExtensionDefinition = {
|
|
1845
|
+
pluginName: string
|
|
1846
|
+
install?: (lf: LogicFlow, LFCtor: LogicFlowConstructor) => void
|
|
1847
|
+
render?: ExtensionRenderFunc
|
|
1848
|
+
}
|
|
1817
1849
|
|
|
1818
1850
|
export interface Extension {
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
render?: ExtensionRender
|
|
1822
|
-
destroy?: () => void
|
|
1851
|
+
render: ExtensionRenderFunc
|
|
1852
|
+
destroy?: () => void // TODO: 确认插件销毁函数参数类型
|
|
1823
1853
|
}
|
|
1824
1854
|
}
|
|
1825
1855
|
|
|
@@ -107,6 +107,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
107
107
|
this.initEdgeData(data)
|
|
108
108
|
this.setAttributes()
|
|
109
109
|
}
|
|
110
|
+
|
|
110
111
|
/**
|
|
111
112
|
* 初始化边数据
|
|
112
113
|
* @overridable 支持重写
|
|
@@ -145,15 +146,18 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
145
146
|
// 文本位置依赖于边上的所有拐点
|
|
146
147
|
this.formatText(data)
|
|
147
148
|
}
|
|
149
|
+
|
|
148
150
|
/**
|
|
149
151
|
* 设置model属性
|
|
150
152
|
* @overridable 支持重写
|
|
151
153
|
* 每次properties发生变化会触发
|
|
152
154
|
*/
|
|
153
155
|
setAttributes() {}
|
|
156
|
+
|
|
154
157
|
createId(): string | null {
|
|
155
158
|
return null
|
|
156
159
|
}
|
|
160
|
+
|
|
157
161
|
/**
|
|
158
162
|
* 自定义边样式
|
|
159
163
|
*
|
|
@@ -166,6 +170,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
166
170
|
...this.style,
|
|
167
171
|
}
|
|
168
172
|
}
|
|
173
|
+
|
|
169
174
|
/**
|
|
170
175
|
* 自定义边调整点样式
|
|
171
176
|
*
|
|
@@ -177,6 +182,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
177
182
|
...this.graphModel.theme.edgeAdjust,
|
|
178
183
|
}
|
|
179
184
|
}
|
|
185
|
+
|
|
180
186
|
/**
|
|
181
187
|
* 自定义边文本样式
|
|
182
188
|
*
|
|
@@ -187,6 +193,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
187
193
|
const { edgeText } = this.graphModel.theme
|
|
188
194
|
return cloneDeep(edgeText)
|
|
189
195
|
}
|
|
196
|
+
|
|
190
197
|
/**
|
|
191
198
|
* 自定义边动画样式
|
|
192
199
|
*
|
|
@@ -204,6 +211,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
204
211
|
const { edgeAnimation } = this.graphModel.theme
|
|
205
212
|
return cloneDeep(edgeAnimation)
|
|
206
213
|
}
|
|
214
|
+
|
|
207
215
|
/**
|
|
208
216
|
* 自定义边箭头样式
|
|
209
217
|
*
|
|
@@ -229,6 +237,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
229
237
|
...arrow,
|
|
230
238
|
}
|
|
231
239
|
}
|
|
240
|
+
|
|
232
241
|
/**
|
|
233
242
|
* 自定义边被选中时展示其范围的矩形框样式
|
|
234
243
|
*
|
|
@@ -247,6 +256,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
247
256
|
const { outline } = graphModel.theme
|
|
248
257
|
return cloneDeep(outline)
|
|
249
258
|
}
|
|
259
|
+
|
|
250
260
|
/**
|
|
251
261
|
* 重新自定义文本位置
|
|
252
262
|
*
|
|
@@ -258,18 +268,21 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
258
268
|
y: 0,
|
|
259
269
|
}
|
|
260
270
|
}
|
|
271
|
+
|
|
261
272
|
/**
|
|
262
273
|
* 边的前一个节点
|
|
263
274
|
*/
|
|
264
275
|
@computed get sourceNode() {
|
|
265
276
|
return this.graphModel?.nodesMap[this.sourceNodeId]?.model
|
|
266
277
|
}
|
|
278
|
+
|
|
267
279
|
/**
|
|
268
280
|
* 边的后一个节点
|
|
269
281
|
*/
|
|
270
282
|
@computed get targetNode() {
|
|
271
283
|
return this.graphModel?.nodesMap[this.targetNodeId]?.model
|
|
272
284
|
}
|
|
285
|
+
|
|
273
286
|
@computed get textPosition(): Point {
|
|
274
287
|
return this.getTextPosition()
|
|
275
288
|
}
|
|
@@ -346,12 +359,14 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
346
359
|
})
|
|
347
360
|
return position
|
|
348
361
|
}
|
|
362
|
+
|
|
349
363
|
/**
|
|
350
364
|
* 获取当前边的properties
|
|
351
365
|
*/
|
|
352
366
|
getProperties() {
|
|
353
367
|
return toJS(this.properties)
|
|
354
368
|
}
|
|
369
|
+
|
|
355
370
|
/**
|
|
356
371
|
* 获取被保存时返回的数据
|
|
357
372
|
*
|
|
@@ -380,6 +395,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
380
395
|
}
|
|
381
396
|
return data
|
|
382
397
|
}
|
|
398
|
+
|
|
383
399
|
/**
|
|
384
400
|
* 获取边的数据
|
|
385
401
|
*
|
|
@@ -391,6 +407,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
391
407
|
getHistoryData(): EdgeData {
|
|
392
408
|
return this.getData()
|
|
393
409
|
}
|
|
410
|
+
|
|
394
411
|
/**
|
|
395
412
|
* 设置边的属性,会触发重新渲染
|
|
396
413
|
* @param key 属性名
|
|
@@ -401,6 +418,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
401
418
|
this.properties[key] = formatData(val)
|
|
402
419
|
this.setAttributes()
|
|
403
420
|
}
|
|
421
|
+
|
|
404
422
|
/**
|
|
405
423
|
* 删除边的属性,会触发重新渲染
|
|
406
424
|
* @param key 属性名
|
|
@@ -410,6 +428,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
410
428
|
delete this.properties[key]
|
|
411
429
|
this.setAttributes()
|
|
412
430
|
}
|
|
431
|
+
|
|
413
432
|
/**
|
|
414
433
|
* 设置边的属性,会触发重新渲染
|
|
415
434
|
* @param key 属性名
|
|
@@ -423,6 +442,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
423
442
|
}
|
|
424
443
|
this.setAttributes()
|
|
425
444
|
}
|
|
445
|
+
|
|
426
446
|
/**
|
|
427
447
|
* 修改边的id
|
|
428
448
|
*/
|
|
@@ -437,6 +457,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
437
457
|
}
|
|
438
458
|
this.id = id
|
|
439
459
|
}
|
|
460
|
+
|
|
440
461
|
/**
|
|
441
462
|
* 设置边样式,用于插件开发时跳过自定义边的渲染。大多数情况下,不需要使用此方法。
|
|
442
463
|
* 如果需要设置边的样式,请使用 getEdgeStyle 方法自定义边样式。
|
|
@@ -448,6 +469,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
448
469
|
[key]: formatData(val),
|
|
449
470
|
}
|
|
450
471
|
}
|
|
472
|
+
|
|
451
473
|
/**
|
|
452
474
|
* 设置边样式,用于插件开发时跳过自定义边的渲染。大多数情况下,不需要使用此方法。
|
|
453
475
|
* 如果需要设置边的样式,请使用 getEdgeStyle 方法自定义边样式。
|
|
@@ -459,6 +481,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
459
481
|
...formatData(styles),
|
|
460
482
|
}
|
|
461
483
|
}
|
|
484
|
+
|
|
462
485
|
/**
|
|
463
486
|
* 设置边样式,用于插件开发时跳过自定义边的渲染。大多数情况下,不需要使用此方法。
|
|
464
487
|
* 如果需要设置边的样式,请使用 getEdgeStyle 方法自定义边样式。
|
|
@@ -497,6 +520,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
497
520
|
}
|
|
498
521
|
}
|
|
499
522
|
}
|
|
523
|
+
|
|
500
524
|
/**
|
|
501
525
|
* 重置文本位置
|
|
502
526
|
*/
|
|
@@ -505,6 +529,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
505
529
|
this.text.x = x
|
|
506
530
|
this.text.y = y
|
|
507
531
|
}
|
|
532
|
+
|
|
508
533
|
/**
|
|
509
534
|
* 移动边上的文本
|
|
510
535
|
*/
|
|
@@ -520,6 +545,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
520
545
|
}
|
|
521
546
|
}
|
|
522
547
|
}
|
|
548
|
+
|
|
523
549
|
/**
|
|
524
550
|
* 设置文本位置和值
|
|
525
551
|
*/
|
|
@@ -528,6 +554,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
528
554
|
assign(this.text, textConfig)
|
|
529
555
|
}
|
|
530
556
|
}
|
|
557
|
+
|
|
531
558
|
/**
|
|
532
559
|
* 更新文本的值
|
|
533
560
|
*/
|
|
@@ -537,6 +564,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
537
564
|
value,
|
|
538
565
|
}
|
|
539
566
|
}
|
|
567
|
+
|
|
540
568
|
/**
|
|
541
569
|
* 内部方法,计算边的起点和终点和其对于的锚点Id
|
|
542
570
|
*/
|
|
@@ -602,6 +630,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
602
630
|
setHitable(flag = true): void {
|
|
603
631
|
this.isHitable = flag
|
|
604
632
|
}
|
|
633
|
+
|
|
605
634
|
@action
|
|
606
635
|
setHittable(flag = true): void {
|
|
607
636
|
this.isHittable = flag
|
|
@@ -664,16 +693,19 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
664
693
|
updateAttributes(attributes) {
|
|
665
694
|
assign(this, attributes)
|
|
666
695
|
}
|
|
696
|
+
|
|
667
697
|
// 获取边调整的起点
|
|
668
698
|
@action
|
|
669
699
|
getAdjustStart() {
|
|
670
700
|
return this.startPoint
|
|
671
701
|
}
|
|
702
|
+
|
|
672
703
|
// 获取边调整的终点
|
|
673
704
|
@action
|
|
674
705
|
getAdjustEnd() {
|
|
675
706
|
return this.endPoint
|
|
676
707
|
}
|
|
708
|
+
|
|
677
709
|
// 起终点拖拽调整过程中,进行直线路径更新
|
|
678
710
|
@action
|
|
679
711
|
updateAfterAdjustStartAndEnd({
|