@logicflow/core 2.0.0-beta.2 → 2.0.0-beta.4
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 -8
- package/dist/index.min.js +9 -3
- package/es/LogicFlow.d.ts +8 -3
- package/es/LogicFlow.js +5 -4
- package/es/LogicFlow.js.map +1 -1
- package/es/common/drag.d.ts +51 -0
- package/es/common/drag.js +145 -0
- package/es/common/drag.js.map +1 -0
- package/es/common/history.d.ts +28 -0
- package/es/common/history.js +92 -0
- package/es/common/history.js.map +1 -0
- package/es/common/index.d.ts +5 -0
- package/es/common/index.js +6 -0
- package/es/common/index.js.map +1 -0
- package/es/common/keyboard.d.ts +34 -0
- package/es/common/keyboard.js +80 -0
- package/es/common/keyboard.js.map +1 -0
- package/es/common/matrix.d.ts +30 -0
- package/es/common/matrix.js +155 -0
- package/es/common/matrix.js.map +1 -0
- package/es/common/vector.d.ts +23 -0
- package/es/common/vector.js +97 -0
- package/es/common/vector.js.map +1 -0
- package/es/constant/index.d.ts +2 -1
- package/es/constant/index.js +1 -0
- package/es/constant/index.js.map +1 -1
- package/es/event/eventArgs.d.ts +6 -0
- package/es/event/eventEmitter.js +0 -1
- package/es/event/eventEmitter.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/model/GraphModel.d.ts +12 -1
- package/es/model/GraphModel.js +21 -2
- package/es/model/GraphModel.js.map +1 -1
- package/es/model/SnaplineModel.d.ts +2 -0
- package/es/model/edge/BaseEdgeModel.d.ts +5 -9
- package/es/model/edge/BaseEdgeModel.js +26 -23
- package/es/model/edge/BaseEdgeModel.js.map +1 -1
- package/es/model/edge/BezierEdgeModel.d.ts +2 -0
- package/es/model/edge/LineEdgeModel.d.ts +2 -0
- package/es/model/edge/PolylineEdgeModel.d.ts +2 -0
- package/es/model/node/BaseNodeModel.js +22 -21
- package/es/model/node/BaseNodeModel.js.map +1 -1
- package/es/model/node/CircleNodeModel.d.ts +2 -0
- package/es/model/node/CircleNodeModel.js +2 -2
- package/es/model/node/CircleNodeModel.js.map +1 -1
- package/es/model/node/DiamondNodeModel.d.ts +2 -0
- package/es/model/node/DiamondNodeModel.js +2 -1
- package/es/model/node/DiamondNodeModel.js.map +1 -1
- package/es/model/node/EllipseNodeModel.d.ts +2 -0
- package/es/model/node/EllipseNodeModel.js +2 -1
- package/es/model/node/EllipseNodeModel.js.map +1 -1
- package/es/model/node/HtmlNodeModel.d.ts +2 -2
- package/es/model/node/HtmlNodeModel.js.map +1 -1
- package/es/model/node/PolygonNodeModel.d.ts +2 -0
- package/es/model/node/PolygonNodeModel.js +2 -2
- package/es/model/node/PolygonNodeModel.js.map +1 -1
- package/es/model/node/RectNodeModel.d.ts +3 -0
- package/es/model/node/RectNodeModel.js +8 -2
- package/es/model/node/RectNodeModel.js.map +1 -1
- package/es/model/node/TextNodeModel.d.ts +4 -2
- package/es/options.js +2 -11
- package/es/options.js.map +1 -1
- package/es/tool/tool.js.map +1 -1
- package/es/util/edge.d.ts +6 -0
- package/es/util/edge.js +15 -1
- package/es/util/edge.js.map +1 -1
- package/es/util/node.d.ts +6 -2
- package/es/util/node.js +22 -7
- package/es/util/node.js.map +1 -1
- package/es/view/Anchor.d.ts +1 -1
- package/es/view/Anchor.js +3 -3
- package/es/view/Anchor.js.map +1 -1
- package/es/view/Control.js +14 -2
- package/es/view/Control.js.map +1 -1
- package/es/view/Graph.d.ts +4 -0
- package/es/view/Graph.js +42 -3
- package/es/view/Graph.js.map +1 -1
- package/es/view/edge/AdjustPoint.js +3 -3
- package/es/view/edge/AdjustPoint.js.map +1 -1
- package/es/view/edge/BaseEdge.d.ts +2 -2
- package/es/view/edge/BaseEdge.js +5 -5
- package/es/view/node/BaseNode.d.ts +2 -2
- package/es/view/node/BaseNode.js +5 -5
- package/es/view/node/TextNode.js +1 -1
- package/es/view/node/TextNode.js.map +1 -1
- package/es/view/shape/Circle.d.ts +9 -1
- package/es/view/shape/Circle.js +5 -5
- package/es/view/shape/Circle.js.map +1 -1
- package/es/view/shape/Ellipse.d.ts +10 -1
- package/es/view/shape/Ellipse.js +5 -5
- package/es/view/shape/Ellipse.js.map +1 -1
- package/es/view/shape/Line.d.ts +14 -1
- package/es/view/shape/Line.js +5 -7
- package/es/view/shape/Line.js.map +1 -1
- package/es/view/shape/Path.d.ts +3 -2
- package/es/view/shape/Path.js +3 -3
- package/es/view/shape/Path.js.map +1 -1
- package/es/view/shape/Polygon.d.ts +5 -3
- package/es/view/shape/Polygon.js +6 -6
- package/es/view/shape/Polygon.js.map +1 -1
- package/es/view/shape/Polyline.d.ts +7 -1
- package/es/view/shape/Polyline.js +8 -6
- package/es/view/shape/Polyline.js.map +1 -1
- package/es/view/shape/Rect.d.ts +11 -13
- package/es/view/shape/Rect.js +6 -9
- package/es/view/shape/Rect.js.map +1 -1
- package/es/view/shape/Text.d.ts +19 -1
- package/es/view/shape/Text.js +28 -21
- package/es/view/shape/Text.js.map +1 -1
- package/es/view/text/BaseText.d.ts +12 -15
- package/es/view/text/BaseText.js +37 -27
- package/es/view/text/BaseText.js.map +1 -1
- package/es/view/text/LineText.d.ts +19 -7
- package/es/view/text/LineText.js +62 -54
- package/es/view/text/LineText.js.map +1 -1
- package/lib/LogicFlow.d.ts +8 -3
- package/lib/LogicFlow.js +5 -4
- package/lib/LogicFlow.js.map +1 -1
- package/lib/common/drag.d.ts +51 -0
- package/lib/common/drag.js +148 -0
- package/lib/common/drag.js.map +1 -0
- package/lib/common/history.d.ts +28 -0
- package/lib/common/history.js +95 -0
- package/lib/common/history.js.map +1 -0
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +22 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/keyboard.d.ts +34 -0
- package/lib/common/keyboard.js +86 -0
- package/lib/common/keyboard.js.map +1 -0
- package/lib/common/matrix.d.ts +30 -0
- package/lib/common/matrix.js +158 -0
- package/lib/common/matrix.js.map +1 -0
- package/lib/common/vector.d.ts +23 -0
- package/lib/common/vector.js +101 -0
- package/lib/common/vector.js.map +1 -0
- package/lib/constant/index.d.ts +2 -1
- package/lib/constant/index.js +1 -0
- package/lib/constant/index.js.map +1 -1
- package/lib/event/eventArgs.d.ts +6 -0
- package/lib/event/eventEmitter.js +0 -1
- package/lib/event/eventEmitter.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/model/GraphModel.d.ts +12 -1
- package/lib/model/GraphModel.js +21 -2
- package/lib/model/GraphModel.js.map +1 -1
- package/lib/model/SnaplineModel.d.ts +2 -0
- package/lib/model/edge/BaseEdgeModel.d.ts +5 -9
- package/lib/model/edge/BaseEdgeModel.js +25 -22
- package/lib/model/edge/BaseEdgeModel.js.map +1 -1
- package/lib/model/edge/BezierEdgeModel.d.ts +2 -0
- package/lib/model/edge/LineEdgeModel.d.ts +2 -0
- package/lib/model/edge/PolylineEdgeModel.d.ts +2 -0
- package/lib/model/node/BaseNodeModel.js +21 -20
- package/lib/model/node/BaseNodeModel.js.map +1 -1
- package/lib/model/node/CircleNodeModel.d.ts +2 -0
- package/lib/model/node/CircleNodeModel.js +2 -2
- package/lib/model/node/CircleNodeModel.js.map +1 -1
- package/lib/model/node/DiamondNodeModel.d.ts +2 -0
- package/lib/model/node/DiamondNodeModel.js +2 -1
- package/lib/model/node/DiamondNodeModel.js.map +1 -1
- package/lib/model/node/EllipseNodeModel.d.ts +2 -0
- package/lib/model/node/EllipseNodeModel.js +2 -1
- package/lib/model/node/EllipseNodeModel.js.map +1 -1
- package/lib/model/node/HtmlNodeModel.d.ts +2 -2
- package/lib/model/node/HtmlNodeModel.js.map +1 -1
- package/lib/model/node/PolygonNodeModel.d.ts +2 -0
- package/lib/model/node/PolygonNodeModel.js +2 -2
- package/lib/model/node/PolygonNodeModel.js.map +1 -1
- package/lib/model/node/RectNodeModel.d.ts +3 -0
- package/lib/model/node/RectNodeModel.js +8 -2
- package/lib/model/node/RectNodeModel.js.map +1 -1
- package/lib/model/node/TextNodeModel.d.ts +4 -2
- package/lib/options.js +2 -11
- package/lib/options.js.map +1 -1
- package/lib/tool/tool.js.map +1 -1
- package/lib/util/edge.d.ts +6 -0
- package/lib/util/edge.js +16 -1
- package/lib/util/edge.js.map +1 -1
- package/lib/util/node.d.ts +6 -2
- package/lib/util/node.js +24 -9
- package/lib/util/node.js.map +1 -1
- package/lib/view/Anchor.d.ts +1 -1
- package/lib/view/Anchor.js +2 -2
- package/lib/view/Anchor.js.map +1 -1
- package/lib/view/Control.js +14 -2
- package/lib/view/Control.js.map +1 -1
- package/lib/view/Graph.d.ts +4 -0
- package/lib/view/Graph.js +41 -2
- package/lib/view/Graph.js.map +1 -1
- package/lib/view/edge/AdjustPoint.js +2 -2
- package/lib/view/edge/AdjustPoint.js.map +1 -1
- package/lib/view/edge/BaseEdge.d.ts +2 -2
- package/lib/view/edge/BaseEdge.js +5 -5
- package/lib/view/node/BaseNode.d.ts +2 -2
- package/lib/view/node/BaseNode.js +5 -5
- package/lib/view/node/TextNode.js +1 -1
- package/lib/view/node/TextNode.js.map +1 -1
- package/lib/view/shape/Circle.d.ts +9 -1
- package/lib/view/shape/Circle.js +5 -5
- package/lib/view/shape/Circle.js.map +1 -1
- package/lib/view/shape/Ellipse.d.ts +10 -1
- package/lib/view/shape/Ellipse.js +5 -5
- package/lib/view/shape/Ellipse.js.map +1 -1
- package/lib/view/shape/Line.d.ts +14 -1
- package/lib/view/shape/Line.js +5 -7
- package/lib/view/shape/Line.js.map +1 -1
- package/lib/view/shape/Path.d.ts +3 -2
- package/lib/view/shape/Path.js +3 -3
- package/lib/view/shape/Path.js.map +1 -1
- package/lib/view/shape/Polygon.d.ts +5 -3
- package/lib/view/shape/Polygon.js +6 -6
- package/lib/view/shape/Polygon.js.map +1 -1
- package/lib/view/shape/Polyline.d.ts +7 -1
- package/lib/view/shape/Polyline.js +8 -6
- package/lib/view/shape/Polyline.js.map +1 -1
- package/lib/view/shape/Rect.d.ts +11 -13
- package/lib/view/shape/Rect.js +6 -9
- package/lib/view/shape/Rect.js.map +1 -1
- package/lib/view/shape/Text.d.ts +19 -1
- package/lib/view/shape/Text.js +29 -21
- package/lib/view/shape/Text.js.map +1 -1
- package/lib/view/text/BaseText.d.ts +12 -15
- package/lib/view/text/BaseText.js +40 -27
- package/lib/view/text/BaseText.js.map +1 -1
- package/lib/view/text/LineText.d.ts +19 -7
- package/lib/view/text/LineText.js +62 -57
- package/lib/view/text/LineText.js.map +1 -1
- package/package.json +2 -1
- package/src/LogicFlow.tsx +19 -7
- package/src/common/drag.ts +205 -0
- package/src/common/history.ts +108 -0
- package/src/common/index.ts +6 -0
- package/src/common/keyboard.ts +108 -0
- package/src/common/matrix.ts +122 -0
- package/src/common/vector.ts +93 -0
- package/src/constant/index.ts +1 -0
- package/src/event/eventArgs.ts +6 -0
- package/src/event/eventEmitter.ts +1 -2
- package/src/index.ts +1 -1
- package/src/model/GraphModel.ts +22 -2
- package/src/model/edge/BaseEdgeModel.ts +31 -21
- package/src/model/node/BaseNodeModel.ts +27 -19
- package/src/model/node/CircleNodeModel.ts +2 -2
- package/src/model/node/DiamondNodeModel.ts +2 -0
- package/src/model/node/EllipseNodeModel.ts +2 -0
- package/src/model/node/HtmlNodeModel.ts +2 -2
- package/src/model/node/PolygonNodeModel.ts +2 -2
- package/src/model/node/RectNodeModel.ts +9 -2
- package/src/options.ts +3 -12
- package/src/tool/tool.ts +1 -1
- package/src/util/edge.ts +26 -1
- package/src/util/node.ts +29 -8
- package/src/view/Anchor.tsx +4 -4
- package/src/view/Control.tsx +5 -2
- package/src/view/Graph.tsx +19 -3
- package/src/view/edge/AdjustPoint.tsx +3 -3
- package/src/view/edge/BaseEdge.tsx +7 -7
- package/src/view/node/BaseNode.tsx +7 -7
- package/src/view/node/TextNode.tsx +1 -1
- package/src/view/shape/Circle.tsx +21 -7
- package/src/view/shape/Ellipse.tsx +20 -6
- package/src/view/shape/Line.tsx +24 -9
- package/src/view/shape/Path.tsx +9 -6
- package/src/view/shape/Polygon.tsx +13 -10
- package/src/view/shape/Polyline.tsx +20 -8
- package/src/view/shape/Rect.tsx +19 -19
- package/src/view/shape/Text.tsx +64 -33
- package/src/view/text/BaseText.tsx +67 -41
- package/src/view/text/LineText.tsx +94 -80
package/src/model/GraphModel.ts
CHANGED
|
@@ -420,8 +420,11 @@ export class GraphModel {
|
|
|
420
420
|
this.nodes = []
|
|
421
421
|
}
|
|
422
422
|
if (graphData.edges) {
|
|
423
|
+
const currEdgeType = this.edgeType
|
|
423
424
|
this.edges = map(graphData.edges, (edge) => {
|
|
424
|
-
const Model = this.getModel(
|
|
425
|
+
const Model = this.getModel(
|
|
426
|
+
edge.type ?? currEdgeType,
|
|
427
|
+
) as BaseEdgeModelCtor
|
|
425
428
|
if (!Model) {
|
|
426
429
|
throw new Error(`找不到${edge.type}对应的边。`)
|
|
427
430
|
}
|
|
@@ -1326,7 +1329,7 @@ export class GraphModel {
|
|
|
1326
1329
|
}
|
|
1327
1330
|
|
|
1328
1331
|
/**
|
|
1329
|
-
*
|
|
1332
|
+
* 获取节点所有的下一级节点
|
|
1330
1333
|
*/
|
|
1331
1334
|
@action getNodeOutgoingNode(nodeId?: string) {
|
|
1332
1335
|
const nodes: BaseNodeModel[] = []
|
|
@@ -1484,6 +1487,23 @@ export class GraphModel {
|
|
|
1484
1487
|
const edgeModel = this.getEdgeModelById(edgeId)
|
|
1485
1488
|
edgeModel?.closeEdgeAnimation()
|
|
1486
1489
|
}
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* 获取当前局部渲染模式
|
|
1493
|
+
* @returns boolean
|
|
1494
|
+
*/
|
|
1495
|
+
getPartial(): boolean {
|
|
1496
|
+
return this.partial
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
/**
|
|
1500
|
+
* 设置是否开启局部渲染模式
|
|
1501
|
+
* @param partial boolean
|
|
1502
|
+
* @returns
|
|
1503
|
+
*/
|
|
1504
|
+
@action setPartial(partial: boolean): void {
|
|
1505
|
+
this.partial = partial
|
|
1506
|
+
}
|
|
1487
1507
|
}
|
|
1488
1508
|
|
|
1489
1509
|
export namespace GraphModel {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assign, cloneDeep, find } from 'lodash-es'
|
|
1
|
+
import { assign, cloneDeep, find, isUndefined } from 'lodash-es'
|
|
2
2
|
import { action, computed, observable, toJS } from 'mobx'
|
|
3
3
|
import { BaseNodeModel, GraphModel, Model } from '..'
|
|
4
4
|
import LogicFlow from '../../LogicFlow'
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import Point = LogicFlow.Point
|
|
21
21
|
import EdgeData = LogicFlow.EdgeData
|
|
22
22
|
import EdgeConfig = LogicFlow.EdgeConfig
|
|
23
|
+
import TextConfig = LogicFlow.TextConfig
|
|
23
24
|
|
|
24
25
|
export interface IBaseEdgeModel extends Model.BaseModel {
|
|
25
26
|
/**
|
|
@@ -56,7 +57,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
56
57
|
@observable startPoint!: Point
|
|
57
58
|
@observable endPoint!: Point
|
|
58
59
|
|
|
59
|
-
@observable text = {
|
|
60
|
+
@observable text: Required<TextConfig> = {
|
|
60
61
|
value: '',
|
|
61
62
|
x: 0,
|
|
62
63
|
y: 0,
|
|
@@ -431,8 +432,7 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
431
432
|
|
|
432
433
|
/**
|
|
433
434
|
* 设置边的属性,会触发重新渲染
|
|
434
|
-
* @param
|
|
435
|
-
* @param val 属性值
|
|
435
|
+
* @param properties 要更新的 properties,会做合并
|
|
436
436
|
*/
|
|
437
437
|
@action
|
|
438
438
|
setProperties(properties: Record<string, any>): void {
|
|
@@ -497,28 +497,38 @@ export class BaseEdgeModel implements IBaseEdgeModel {
|
|
|
497
497
|
* 内部方法,处理初始化文本格式
|
|
498
498
|
*/
|
|
499
499
|
@action formatText(data: EdgeConfig) {
|
|
500
|
-
// 暂时处理,只传入text的情况
|
|
501
500
|
const { x, y } = this.textPosition
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
return
|
|
501
|
+
const { text } = data
|
|
502
|
+
let textConfig: Required<TextConfig> = {
|
|
503
|
+
value: '',
|
|
504
|
+
x,
|
|
505
|
+
y,
|
|
506
|
+
draggable: false,
|
|
507
|
+
editable: true,
|
|
511
508
|
}
|
|
512
509
|
|
|
513
|
-
if (
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
510
|
+
if (text) {
|
|
511
|
+
if (typeof text === 'string') {
|
|
512
|
+
textConfig = {
|
|
513
|
+
...textConfig,
|
|
514
|
+
value: text,
|
|
515
|
+
}
|
|
516
|
+
} else {
|
|
517
|
+
textConfig = {
|
|
518
|
+
...textConfig,
|
|
519
|
+
x: text.x ?? x,
|
|
520
|
+
y: text.y ?? y,
|
|
521
|
+
value: text.value ?? '',
|
|
522
|
+
}
|
|
523
|
+
if (!isUndefined(text.draggable)) {
|
|
524
|
+
textConfig.draggable = text.draggable
|
|
525
|
+
}
|
|
526
|
+
if (!isUndefined(text.editable)) {
|
|
527
|
+
textConfig.editable = text.editable
|
|
528
|
+
}
|
|
520
529
|
}
|
|
521
530
|
}
|
|
531
|
+
this.text = textConfig
|
|
522
532
|
}
|
|
523
533
|
|
|
524
534
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { action, computed, isObservable, observable, toJS } from 'mobx'
|
|
2
|
-
import { assign, cloneDeep, has, isNil, mapKeys } from 'lodash-es'
|
|
2
|
+
import { assign, cloneDeep, has, isNil, isUndefined, mapKeys } from 'lodash-es'
|
|
3
3
|
import { GraphModel, Model } from '..'
|
|
4
4
|
import LogicFlow from '../../LogicFlow'
|
|
5
5
|
import {
|
|
@@ -186,6 +186,7 @@ export class BaseNodeModel implements IBaseNodeModel {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
this.formatText(data)
|
|
189
|
+
// 在下面又将 NodeConfig 中的数据赋值给了 this,应该会触发 setAttributes,确认是否符合预期
|
|
189
190
|
assign(this, pickNodeConfig(data)) // TODO: 确认 constructor 中赋值 properties 是否必要
|
|
190
191
|
const { overlapMode } = this.graphModel
|
|
191
192
|
if (overlapMode === OverlapMode.INCREASE) {
|
|
@@ -219,27 +220,34 @@ export class BaseNodeModel implements IBaseNodeModel {
|
|
|
219
220
|
* 始化文本属性
|
|
220
221
|
*/
|
|
221
222
|
private formatText(data: NodeConfig): void {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (typeof
|
|
232
|
-
|
|
233
|
-
value: data.text,
|
|
234
|
-
x: data.x,
|
|
235
|
-
y: data.y,
|
|
236
|
-
draggable: false,
|
|
237
|
-
editable: true,
|
|
238
|
-
}
|
|
223
|
+
const { x, y, text } = data
|
|
224
|
+
let textConfig: TextConfig = {
|
|
225
|
+
value: '',
|
|
226
|
+
x,
|
|
227
|
+
y,
|
|
228
|
+
draggable: false,
|
|
229
|
+
editable: true,
|
|
230
|
+
}
|
|
231
|
+
if (text) {
|
|
232
|
+
if (typeof text === 'string') {
|
|
233
|
+
textConfig.value = text
|
|
239
234
|
} else {
|
|
240
|
-
|
|
235
|
+
textConfig = {
|
|
236
|
+
...textConfig,
|
|
237
|
+
x: text.x ?? x,
|
|
238
|
+
y: text.y ?? y,
|
|
239
|
+
value: text.value ?? '',
|
|
240
|
+
}
|
|
241
|
+
if (!isUndefined(text.draggable)) {
|
|
242
|
+
textConfig.draggable = text.draggable
|
|
243
|
+
}
|
|
244
|
+
if (!isUndefined(text.editable)) {
|
|
245
|
+
textConfig.draggable = text.draggable
|
|
246
|
+
}
|
|
241
247
|
}
|
|
242
248
|
}
|
|
249
|
+
|
|
250
|
+
data.text = textConfig
|
|
243
251
|
}
|
|
244
252
|
|
|
245
253
|
/**
|
|
@@ -54,11 +54,11 @@ export class CircleNodeModel extends BaseNodeModel {
|
|
|
54
54
|
theme: { circle },
|
|
55
55
|
},
|
|
56
56
|
} = this
|
|
57
|
-
const { style: customStyle } = this.properties
|
|
57
|
+
const { style: customStyle = {} } = this.properties
|
|
58
58
|
return {
|
|
59
59
|
...style,
|
|
60
|
-
...(customStyle ?? {}),
|
|
61
60
|
...cloneDeep(circle),
|
|
61
|
+
...cloneDeep(customStyle),
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -7,7 +7,7 @@ import { observable } from 'mobx'
|
|
|
7
7
|
import LogicFlow from '../../LogicFlow'
|
|
8
8
|
import GraphModel from '../GraphModel'
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type IHtmlNodeProperties = {
|
|
11
11
|
width?: number
|
|
12
12
|
height?: number
|
|
13
13
|
style?: LogicFlow.CommonTheme
|
|
@@ -18,7 +18,7 @@ export type IHtmlNodeModel = {
|
|
|
18
18
|
|
|
19
19
|
export class HtmlNodeModel extends BaseNodeModel {
|
|
20
20
|
modelType = ModelType.HTML_NODE
|
|
21
|
-
@observable properties:
|
|
21
|
+
@observable properties: IHtmlNodeProperties = {}
|
|
22
22
|
|
|
23
23
|
constructor(data: LogicFlow.NodeConfig, graphModel: GraphModel) {
|
|
24
24
|
super(data, graphModel)
|
|
@@ -66,11 +66,11 @@ export class PolygonNodeModel extends BaseNodeModel {
|
|
|
66
66
|
theme: { polygon },
|
|
67
67
|
},
|
|
68
68
|
} = this
|
|
69
|
-
const { style: customStyle } = this.properties
|
|
69
|
+
const { style: customStyle = {} } = this.properties
|
|
70
70
|
return {
|
|
71
71
|
...style,
|
|
72
72
|
...cloneDeep(polygon),
|
|
73
|
-
...
|
|
73
|
+
...cloneDeep(customStyle),
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -8,6 +8,7 @@ import { ModelType } from '../../constant'
|
|
|
8
8
|
export type IRectNodeModel = {
|
|
9
9
|
width?: number
|
|
10
10
|
height?: number
|
|
11
|
+
radius?: number
|
|
11
12
|
style?: LogicFlow.CommonTheme
|
|
12
13
|
textStyle?: LogicFlow.CommonTheme
|
|
13
14
|
|
|
@@ -21,17 +22,21 @@ export class RectNodeModel extends BaseNodeModel {
|
|
|
21
22
|
|
|
22
23
|
constructor(data: LogicFlow.NodeConfig, graphModel: GraphModel) {
|
|
23
24
|
super(data, graphModel)
|
|
24
|
-
this.properties = data.properties || {}
|
|
25
25
|
|
|
26
|
+
// TODO:类字段初始化会覆盖 super、setAttributes 中设置的属性
|
|
27
|
+
this.properties = data.properties || {}
|
|
28
|
+
// TODO: bug here, 上面更新 properties 会触发 setAttributes,下面再主动调用,会导致触发两次
|
|
26
29
|
this.setAttributes()
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
setAttributes() {
|
|
30
33
|
super.setAttributes()
|
|
31
34
|
|
|
32
|
-
const { width, height } = this.properties
|
|
35
|
+
const { width, height, radius } = this.properties
|
|
33
36
|
if (width) this.width = width
|
|
34
37
|
if (height) this.height = height
|
|
38
|
+
// 矩形特有
|
|
39
|
+
if (radius) this.radius = radius
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
getDefaultAnchor() {
|
|
@@ -47,9 +52,11 @@ export class RectNodeModel extends BaseNodeModel {
|
|
|
47
52
|
getNodeStyle() {
|
|
48
53
|
const style = super.getNodeStyle()
|
|
49
54
|
const { rect } = this.graphModel.theme
|
|
55
|
+
const { style: customStyle = {} } = this.properties
|
|
50
56
|
return {
|
|
51
57
|
...style,
|
|
52
58
|
...cloneDeep(rect),
|
|
59
|
+
...cloneDeep(customStyle),
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
62
|
}
|
package/src/options.ts
CHANGED
|
@@ -71,7 +71,7 @@ export namespace Options {
|
|
|
71
71
|
allowRotate?: boolean // 允许节点旋转
|
|
72
72
|
allowResize?: boolean // 是否允许缩放
|
|
73
73
|
|
|
74
|
-
isSilentMode?: boolean
|
|
74
|
+
isSilentMode?: boolean // 是否为静默模式:可以简单理解为“只读”模式,这种模式下,画布中的节点和边不可移动,不可进行文案修改,没有锚点。
|
|
75
75
|
stopScrollGraph?: boolean
|
|
76
76
|
stopZoomGraph?: boolean
|
|
77
77
|
stopMoveGraph?:
|
|
@@ -111,22 +111,13 @@ export namespace Options {
|
|
|
111
111
|
export function get(options: Partial<Manual>) {
|
|
112
112
|
const { ...others } = options
|
|
113
113
|
const container = options.container
|
|
114
|
-
if (container
|
|
115
|
-
if (options.width == null) {
|
|
116
|
-
others.width = container.clientWidth
|
|
117
|
-
}
|
|
118
|
-
if (options.height == null) {
|
|
119
|
-
others.height = container.clientHeight
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
114
|
+
if (!container) {
|
|
122
115
|
throw new Error(
|
|
123
116
|
'Ensure the container of LogicFlow is specified and valid.',
|
|
124
117
|
)
|
|
125
118
|
}
|
|
126
119
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return result
|
|
120
|
+
return assign({}, defaults, others) as Options.Definition
|
|
130
121
|
}
|
|
131
122
|
}
|
|
132
123
|
|
package/src/tool/tool.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { VNode } from 'preact'
|
|
|
3
3
|
import TextEdit from './TextEditTool'
|
|
4
4
|
import MultipleSelect from './MultipleSelectTool'
|
|
5
5
|
import LogicFlow from '../LogicFlow'
|
|
6
|
-
import { GraphModel, BaseEdgeModel, BaseNodeModel } from '../model'
|
|
7
6
|
import { ElementState, EventType } from '../constant'
|
|
7
|
+
import { GraphModel, BaseEdgeModel, BaseNodeModel } from '../model'
|
|
8
8
|
|
|
9
9
|
export type IToolProps = {
|
|
10
10
|
textEditElement?: BaseNodeModel | BaseEdgeModel
|
package/src/util/edge.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pick } from 'lodash-es'
|
|
1
|
+
import { forEach, pick } from 'lodash-es'
|
|
2
2
|
import { getNodeBBox, isInNode, distance, sampleCubic } from '.'
|
|
3
3
|
import LogicFlow from '../LogicFlow'
|
|
4
4
|
import { Options } from '../options'
|
|
@@ -1032,3 +1032,28 @@ export function createEdgeGenerator(
|
|
|
1032
1032
|
return Object.assign({ type: result }, currentEdge)
|
|
1033
1033
|
}
|
|
1034
1034
|
}
|
|
1035
|
+
|
|
1036
|
+
// 获取 Svg 标签文案高度,自动换行
|
|
1037
|
+
export type IGetSvgTextSizeParams = {
|
|
1038
|
+
rows: string[]
|
|
1039
|
+
rowsLength: number
|
|
1040
|
+
fontSize: number
|
|
1041
|
+
}
|
|
1042
|
+
export const getSvgTextSize = ({
|
|
1043
|
+
rows,
|
|
1044
|
+
rowsLength,
|
|
1045
|
+
fontSize,
|
|
1046
|
+
}: IGetSvgTextSizeParams): LogicFlow.RectSize => {
|
|
1047
|
+
let longestBytes = 0
|
|
1048
|
+
forEach(rows, (row) => {
|
|
1049
|
+
const rowBytesLength = getBytesLength(row)
|
|
1050
|
+
longestBytes = rowBytesLength > longestBytes ? rowBytesLength : longestBytes
|
|
1051
|
+
})
|
|
1052
|
+
|
|
1053
|
+
// 背景框宽度,最长一行字节数/2 * fontsize + 2
|
|
1054
|
+
// 背景框宽度, 行数 * fontsize + 2
|
|
1055
|
+
return {
|
|
1056
|
+
width: Math.ceil(longestBytes / 2) * fontSize + fontSize / 4,
|
|
1057
|
+
height: rowsLength * (fontSize + 2) + fontSize / 4,
|
|
1058
|
+
}
|
|
1059
|
+
}
|
package/src/util/node.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { pick } from 'lodash-es'
|
|
2
|
+
import { createElement as h } from 'preact/compat'
|
|
2
3
|
import { getBytesLength } from './edge'
|
|
3
4
|
import LogicFlow from '../LogicFlow'
|
|
4
5
|
import {
|
|
@@ -444,7 +445,26 @@ export const getNodeAnchorPosition = (
|
|
|
444
445
|
}
|
|
445
446
|
}
|
|
446
447
|
|
|
447
|
-
|
|
448
|
+
/*********************************************************
|
|
449
|
+
* Text 节点文本相关工具函数
|
|
450
|
+
********************************************************/
|
|
451
|
+
// Text 相关节点工具函数
|
|
452
|
+
// TODO: 获取文案高度,设置自动换行,利用 dom 计算高度
|
|
453
|
+
// function getTextHeight(text: string, font: string): number {
|
|
454
|
+
// const span = document.createElement('span');
|
|
455
|
+
// span.textContent = text;
|
|
456
|
+
// span.style.font = font;
|
|
457
|
+
|
|
458
|
+
// const range = document.createRange();
|
|
459
|
+
// range.selectNodeContents(span);
|
|
460
|
+
|
|
461
|
+
// const rect = range.getBoundingClientRect();
|
|
462
|
+
// const height = rect.height;
|
|
463
|
+
|
|
464
|
+
// return height;
|
|
465
|
+
// }
|
|
466
|
+
|
|
467
|
+
// 获取文案高度,自动换行,利用 dom 计算高度
|
|
448
468
|
export const getHtmlTextHeight = ({
|
|
449
469
|
rows,
|
|
450
470
|
style,
|
|
@@ -452,18 +472,18 @@ export const getHtmlTextHeight = ({
|
|
|
452
472
|
className,
|
|
453
473
|
}: {
|
|
454
474
|
rows: string[]
|
|
455
|
-
style:
|
|
475
|
+
style: h.JSX.CSSProperties
|
|
456
476
|
rowsLength: number
|
|
457
477
|
className: string
|
|
458
478
|
}) => {
|
|
459
479
|
const dom = document.createElement('div')
|
|
460
|
-
dom.style.fontSize = style.fontSize
|
|
461
|
-
dom.style.width = style.width
|
|
462
480
|
dom.className = className
|
|
463
|
-
dom.style.
|
|
464
|
-
dom.style.
|
|
481
|
+
dom.style.fontSize = `${style.fontSize}`
|
|
482
|
+
dom.style.width = `${style.width}`
|
|
483
|
+
dom.style.lineHeight = `${style.lineHeight}`
|
|
484
|
+
dom.style.padding = `${style.padding}`
|
|
465
485
|
if (style.fontFamily) {
|
|
466
|
-
dom.style.fontFamily = style.fontFamily
|
|
486
|
+
dom.style.fontFamily = `${style.fontFamily}`
|
|
467
487
|
}
|
|
468
488
|
if (rowsLength > 1) {
|
|
469
489
|
rows.forEach((row) => {
|
|
@@ -479,6 +499,7 @@ export const getHtmlTextHeight = ({
|
|
|
479
499
|
document.body.removeChild(dom)
|
|
480
500
|
return height
|
|
481
501
|
}
|
|
502
|
+
|
|
482
503
|
// 获取文案高度,自动换行,利用dom计算高度
|
|
483
504
|
export const getSvgTextWidthHeight = ({
|
|
484
505
|
rows,
|
|
@@ -506,7 +527,7 @@ export const getSvgTextWidthHeight = ({
|
|
|
506
527
|
/**
|
|
507
528
|
* @description 格式化边校验信息
|
|
508
529
|
*/
|
|
509
|
-
export const
|
|
530
|
+
export const formatAnchorConnectValidateData = (
|
|
510
531
|
data: Model.ConnectRuleResult,
|
|
511
532
|
) => {
|
|
512
533
|
if (typeof data !== 'object') {
|
package/src/view/Anchor.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import { ElementState, EventType } from '../constant'
|
|
|
6
6
|
import { GraphModel, BaseNodeModel, Model } from '../model'
|
|
7
7
|
import {
|
|
8
8
|
StepDrag,
|
|
9
|
-
|
|
9
|
+
formatAnchorConnectValidateData,
|
|
10
10
|
targetNodeInfo,
|
|
11
11
|
distance,
|
|
12
12
|
cancelRaf,
|
|
@@ -29,7 +29,7 @@ interface IProps {
|
|
|
29
29
|
anchorIndex: number
|
|
30
30
|
graphModel: GraphModel
|
|
31
31
|
nodeModel: BaseNodeModel
|
|
32
|
-
|
|
32
|
+
setHoverOff: (e: MouseEvent) => void
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
interface IState {
|
|
@@ -326,11 +326,11 @@ class Anchor extends Component<IProps, IState> {
|
|
|
326
326
|
)
|
|
327
327
|
this.sourceRuleResults.set(
|
|
328
328
|
targetInfoId,
|
|
329
|
-
|
|
329
|
+
formatAnchorConnectValidateData(sourceRuleResult),
|
|
330
330
|
)
|
|
331
331
|
this.targetRuleResults.set(
|
|
332
332
|
targetInfoId,
|
|
333
|
-
|
|
333
|
+
formatAnchorConnectValidateData(targetRuleResult),
|
|
334
334
|
)
|
|
335
335
|
}
|
|
336
336
|
const { isAllPass: isSourcePass } =
|
package/src/view/Control.tsx
CHANGED
|
@@ -304,6 +304,7 @@ export class ResizeControl extends Component<
|
|
|
304
304
|
|
|
305
305
|
// 由于将拖拽放大缩小改成丝滑模式,这个时候需要再拖拽结束的时候,将节点的位置更新到 grid 上。
|
|
306
306
|
onDragEnd = () => {
|
|
307
|
+
// TODO: 确认下面该代码是否还需要(应该是默认让节点拖拽以 gridSize 为步长移动)
|
|
307
308
|
// const { gridSize = 1 } = this.graphModel
|
|
308
309
|
// const x = gridSize * Math.round(this.nodeModel.x / gridSize)
|
|
309
310
|
// const y = gridSize * Math.round(this.nodeModel.y / gridSize)
|
|
@@ -319,14 +320,16 @@ export class ResizeControl extends Component<
|
|
|
319
320
|
|
|
320
321
|
render(): h.JSX.Element {
|
|
321
322
|
const { x, y, direction, model } = this.props
|
|
322
|
-
const
|
|
323
|
+
const { width, height, ...restStyle } = model.getResizeControlStyle()
|
|
323
324
|
return (
|
|
324
325
|
<g className={`lf-resize-control lf-resize-control-${direction}`}>
|
|
325
326
|
<Rect
|
|
326
327
|
className="lf-resize-control-content"
|
|
327
328
|
x={x}
|
|
328
329
|
y={y}
|
|
329
|
-
{
|
|
330
|
+
width={width ?? 7}
|
|
331
|
+
height={height ?? 7}
|
|
332
|
+
{...restStyle}
|
|
330
333
|
onMouseDown={this.dragHandler.handleMouseDown}
|
|
331
334
|
/>
|
|
332
335
|
</g>
|
package/src/view/Graph.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, ComponentType } from 'preact/compat'
|
|
2
|
-
import { map } from 'lodash-es'
|
|
2
|
+
import { map, throttle } from 'lodash-es'
|
|
3
3
|
import {
|
|
4
4
|
CanvasOverlay,
|
|
5
5
|
ToolOverlay,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
BaseNodeModel,
|
|
21
21
|
SnaplineModel,
|
|
22
22
|
} from '../model'
|
|
23
|
+
import { EventType } from '../constant'
|
|
23
24
|
|
|
24
25
|
type IGraphProps = {
|
|
25
26
|
getView: (type: string) => ComponentType<any> | undefined
|
|
@@ -37,6 +38,22 @@ type ContainerStyle = {
|
|
|
37
38
|
|
|
38
39
|
@observer
|
|
39
40
|
class Graph extends Component<IGraphProps> {
|
|
41
|
+
handleResize = () => {
|
|
42
|
+
this.props.graphModel.resize()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
componentDidMount() {
|
|
46
|
+
window.addEventListener('resize', throttle(this.handleResize, 200))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
componentDidUpdate() {
|
|
50
|
+
this.props.graphModel.eventCenter.emit(EventType.GRAPH_UPDATED, {})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
componentWillUnmount() {
|
|
54
|
+
window.removeEventListener('resize', throttle(this.handleResize, 200))
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
getComponent(
|
|
41
58
|
model: BaseEdgeModel | BaseNodeModel,
|
|
42
59
|
graphModel: GraphModel,
|
|
@@ -71,9 +88,8 @@ class Graph extends Component<IGraphProps> {
|
|
|
71
88
|
const grid = options.grid && Grid.getGridOptions(options.grid)
|
|
72
89
|
const { fakeNode, editConfigModel } = graphModel
|
|
73
90
|
const { adjustEdge } = editConfigModel
|
|
74
|
-
|
|
75
91
|
return (
|
|
76
|
-
<div className="lf-graph" flow-id={graphModel.flowId}
|
|
92
|
+
<div className="lf-graph" flow-id={graphModel.flowId}>
|
|
77
93
|
<CanvasOverlay graphModel={graphModel} dnd={dnd}>
|
|
78
94
|
<g className="lf-base">
|
|
79
95
|
{map(graphModel.sortElements, (nodeModel) =>
|
|
@@ -4,7 +4,7 @@ import { GraphModel, BaseNodeModel, BaseEdgeModel, Model } from '../../model'
|
|
|
4
4
|
import {
|
|
5
5
|
IDragParams,
|
|
6
6
|
StepDrag,
|
|
7
|
-
|
|
7
|
+
formatAnchorConnectValidateData,
|
|
8
8
|
targetNodeInfo,
|
|
9
9
|
NodeContaint,
|
|
10
10
|
} from '../../util'
|
|
@@ -394,11 +394,11 @@ export class AdjustPoint extends Component<IProps, IState> {
|
|
|
394
394
|
)
|
|
395
395
|
this.sourceRuleResults.set(
|
|
396
396
|
targetInfoId,
|
|
397
|
-
|
|
397
|
+
formatAnchorConnectValidateData(sourceRuleResult),
|
|
398
398
|
)
|
|
399
399
|
this.targetRuleResults.set(
|
|
400
400
|
targetInfoId,
|
|
401
|
-
|
|
401
|
+
formatAnchorConnectValidateData(targetRuleResult),
|
|
402
402
|
)
|
|
403
403
|
}
|
|
404
404
|
const { isAllPass: isSourcePass, msg: sourceMsg } =
|
|
@@ -307,24 +307,24 @@ export abstract class BaseEdge<P extends IProps> extends Component<
|
|
|
307
307
|
/**
|
|
308
308
|
* 不支持重写,如果想要基于hover状态设置不同的样式,请在model中使用isHovered属性。
|
|
309
309
|
*/
|
|
310
|
-
|
|
310
|
+
setHoverOn = (ev: MouseEvent) => {
|
|
311
311
|
// ! hover多次触发, onMouseOver + onMouseEnter
|
|
312
312
|
const {
|
|
313
313
|
model: { isHovered },
|
|
314
314
|
} = this.props
|
|
315
315
|
if (isHovered) return
|
|
316
|
-
this.textRef && this.textRef.current && this.textRef.current.
|
|
316
|
+
this.textRef && this.textRef.current && this.textRef.current.setHoverOn()
|
|
317
317
|
this.handleHover(true, ev)
|
|
318
318
|
}
|
|
319
319
|
/**
|
|
320
320
|
* 不支持重写,如果想要基于hover状态设置不同的样式,请在model中使用isHovered属性。
|
|
321
321
|
*/
|
|
322
|
-
|
|
322
|
+
setHoverOff = (ev: MouseEvent) => {
|
|
323
323
|
const {
|
|
324
324
|
model: { isHovered },
|
|
325
325
|
} = this.props
|
|
326
326
|
if (!isHovered) return
|
|
327
|
-
this.textRef && this.textRef.current && this.textRef.current.
|
|
327
|
+
this.textRef && this.textRef.current && this.textRef.current.setHoverOff()
|
|
328
328
|
this.handleHover(false, ev)
|
|
329
329
|
}
|
|
330
330
|
/**
|
|
@@ -471,9 +471,9 @@ export abstract class BaseEdge<P extends IProps> extends Component<
|
|
|
471
471
|
onMouseDown={this.handleMouseDown}
|
|
472
472
|
onMouseUp={this.handleMouseUp}
|
|
473
473
|
onContextMenu={this.handleContextMenu}
|
|
474
|
-
onMouseOver={this.
|
|
475
|
-
onMouseEnter={this.
|
|
476
|
-
onMouseLeave={this.
|
|
474
|
+
onMouseOver={this.setHoverOn}
|
|
475
|
+
onMouseEnter={this.setHoverOn}
|
|
476
|
+
onMouseLeave={this.setHoverOff}
|
|
477
477
|
>
|
|
478
478
|
{this.getShape()}
|
|
479
479
|
{this.getAppend()}
|