@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
|
@@ -106,7 +106,7 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
|
|
|
106
106
|
anchorIndex={index}
|
|
107
107
|
nodeModel={model}
|
|
108
108
|
graphModel={graphModel}
|
|
109
|
-
|
|
109
|
+
setHoverOff={this.setHoverOff}
|
|
110
110
|
/>
|
|
111
111
|
)
|
|
112
112
|
})
|
|
@@ -395,7 +395,7 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
|
|
|
395
395
|
}
|
|
396
396
|
// 为什么将hover状态放到model中?
|
|
397
397
|
// 因为自定义节点的时候,可能会基于hover状态自定义不同的样式。
|
|
398
|
-
|
|
398
|
+
setHoverOn = (ev: MouseEvent) => {
|
|
399
399
|
const { model, graphModel } = this.props
|
|
400
400
|
if (model.isHovered) return
|
|
401
401
|
const nodeData = model.getData()
|
|
@@ -405,7 +405,7 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
|
|
|
405
405
|
e: ev,
|
|
406
406
|
})
|
|
407
407
|
}
|
|
408
|
-
|
|
408
|
+
setHoverOff = (ev: MouseEvent) => {
|
|
409
409
|
const { model, graphModel } = this.props
|
|
410
410
|
const nodeData = model.getData()
|
|
411
411
|
if (!model.isHovered) return
|
|
@@ -417,7 +417,7 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
|
|
|
417
417
|
}
|
|
418
418
|
onMouseOut = (ev: MouseEvent) => {
|
|
419
419
|
if (isIe) {
|
|
420
|
-
this.
|
|
420
|
+
this.setHoverOff(ev)
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
|
|
@@ -476,9 +476,9 @@ export abstract class BaseNode<P extends IProps> extends Component<P, IState> {
|
|
|
476
476
|
onMouseDown={this.handleMouseDown}
|
|
477
477
|
onMouseUp={this.handleMouseUp}
|
|
478
478
|
onClick={this.handleClick}
|
|
479
|
-
onMouseEnter={this.
|
|
480
|
-
onMouseOver={this.
|
|
481
|
-
onMouseLeave={this.
|
|
479
|
+
onMouseEnter={this.setHoverOn}
|
|
480
|
+
onMouseOver={this.setHoverOn}
|
|
481
|
+
onMouseLeave={this.setHoverOff}
|
|
482
482
|
onMouseOut={this.onMouseOut}
|
|
483
483
|
onContextMenu={this.handleContextMenu}
|
|
484
484
|
{...restAttributes}
|
|
@@ -1,26 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
import { createElement as h } from 'preact/compat'
|
|
2
|
+
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
+
import { LogicFlow } from '../..'
|
|
4
|
+
|
|
5
|
+
export type ICircleProps = {
|
|
6
|
+
x?: number
|
|
7
|
+
y?: number
|
|
8
|
+
r?: number
|
|
9
|
+
className?: string
|
|
10
|
+
} & LogicFlow.CommonTheme
|
|
11
|
+
|
|
12
|
+
export function Circle(props: ICircleProps): h.JSX.Element {
|
|
2
13
|
const { x = 0, y = 0, r = 4, className } = props
|
|
3
|
-
|
|
14
|
+
|
|
15
|
+
const attrs: ICircleProps = {
|
|
4
16
|
cx: x,
|
|
5
17
|
cy: y,
|
|
6
18
|
r,
|
|
7
19
|
fill: 'transparent',
|
|
8
20
|
fillOpacity: 1,
|
|
9
|
-
strokeWidth:
|
|
21
|
+
strokeWidth: 1,
|
|
10
22
|
stroke: '#000',
|
|
11
23
|
strokeOpacity: 1,
|
|
12
24
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
25
|
+
|
|
26
|
+
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
27
|
+
if (typeof v !== 'object') {
|
|
16
28
|
attrs[k] = v
|
|
17
29
|
}
|
|
18
30
|
})
|
|
31
|
+
|
|
19
32
|
if (className) {
|
|
20
33
|
attrs.className = `lf-basic-shape ${className}`
|
|
21
34
|
} else {
|
|
22
|
-
attrs.className =
|
|
35
|
+
attrs.className = `lf-basic-shape`
|
|
23
36
|
}
|
|
37
|
+
|
|
24
38
|
return <circle {...attrs} />
|
|
25
39
|
}
|
|
26
40
|
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { createElement as h } from 'preact/compat'
|
|
2
|
+
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
+
import { LogicFlow } from '../..'
|
|
4
|
+
|
|
5
|
+
export type IEllipseProps = {
|
|
6
|
+
x?: number
|
|
7
|
+
y?: number
|
|
8
|
+
rx?: number
|
|
9
|
+
ry?: number
|
|
10
|
+
className?: string
|
|
11
|
+
} & LogicFlow.CommonTheme
|
|
12
|
+
|
|
13
|
+
export function Ellipse(props: IEllipseProps): h.JSX.Element {
|
|
2
14
|
const { x = 0, y = 0, rx = 4, ry = 4, className } = props
|
|
15
|
+
|
|
3
16
|
const attrs: Record<string, any> = {
|
|
4
17
|
cx: x,
|
|
5
18
|
cy: y,
|
|
@@ -7,21 +20,22 @@ export function Ellipse(props) {
|
|
|
7
20
|
ry,
|
|
8
21
|
fill: 'transparent',
|
|
9
22
|
fillOpacity: 1,
|
|
10
|
-
strokeWidth:
|
|
23
|
+
strokeWidth: 1,
|
|
11
24
|
stroke: '#000',
|
|
12
25
|
strokeOpacity: 1,
|
|
13
26
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (valueType !== 'object') {
|
|
27
|
+
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
28
|
+
if (typeof v !== 'object') {
|
|
17
29
|
attrs[k] = v
|
|
18
30
|
}
|
|
19
31
|
})
|
|
32
|
+
|
|
20
33
|
if (className) {
|
|
21
34
|
attrs.className = `lf-basic-shape ${className}`
|
|
22
35
|
} else {
|
|
23
|
-
attrs.className =
|
|
36
|
+
attrs.className = `lf-basic-shape`
|
|
24
37
|
}
|
|
38
|
+
|
|
25
39
|
return <ellipse {...attrs} />
|
|
26
40
|
}
|
|
27
41
|
|
package/src/view/shape/Line.tsx
CHANGED
|
@@ -1,23 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createElement as h } from 'preact/compat'
|
|
2
|
+
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
+
|
|
4
|
+
export type ILineProps = {
|
|
5
|
+
id?: string
|
|
6
|
+
tabindex?: number
|
|
7
|
+
x1?: number
|
|
8
|
+
y1?: number
|
|
9
|
+
x2?: number
|
|
10
|
+
y2?: number
|
|
11
|
+
stroke?: string // Color
|
|
12
|
+
className?: string
|
|
13
|
+
style?: h.JSX.CSSProperties
|
|
14
|
+
[key: string]: any
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function Line(props: ILineProps): h.JSX.Element {
|
|
18
|
+
const attrs: ILineProps = {
|
|
3
19
|
// default
|
|
4
20
|
x1: 10,
|
|
5
21
|
y1: 10,
|
|
6
22
|
x2: 20,
|
|
7
23
|
y2: 20,
|
|
8
24
|
stroke: 'black',
|
|
9
|
-
// ...props
|
|
25
|
+
// ...props
|
|
10
26
|
}
|
|
11
|
-
|
|
27
|
+
|
|
28
|
+
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
12
29
|
if (k === 'style') {
|
|
13
30
|
attrs[k] = v
|
|
14
|
-
} else {
|
|
15
|
-
|
|
16
|
-
if (valueType !== 'object') {
|
|
17
|
-
attrs[k] = v
|
|
18
|
-
}
|
|
31
|
+
} else if (typeof v !== 'object') {
|
|
32
|
+
attrs[k] = v
|
|
19
33
|
}
|
|
20
34
|
})
|
|
35
|
+
|
|
21
36
|
return <line {...attrs} />
|
|
22
37
|
}
|
|
23
38
|
|
package/src/view/shape/Path.tsx
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import { createElement as h } from 'preact/compat'
|
|
2
|
+
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
+
|
|
4
|
+
export type IPathProps = {
|
|
2
5
|
d: string
|
|
3
6
|
[key: string]: any
|
|
4
7
|
}
|
|
5
8
|
|
|
6
|
-
export function Path(props:
|
|
7
|
-
const attrs = {
|
|
9
|
+
export function Path(props: IPathProps): h.JSX.Element {
|
|
10
|
+
const attrs: Record<string, any> = {
|
|
8
11
|
d: '',
|
|
9
12
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (k === 'style' || valueType !== 'object') {
|
|
13
|
+
forEach(toPairs(props), ([k, v]: [key: string, v: any]) => {
|
|
14
|
+
if (k === 'style' || typeof v !== 'object') {
|
|
13
15
|
attrs[k] = v
|
|
14
16
|
}
|
|
15
17
|
})
|
|
18
|
+
|
|
16
19
|
return <path {...attrs} />
|
|
17
20
|
}
|
|
18
21
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createElement as h } from 'preact/compat'
|
|
2
|
+
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
+
import { LogicFlow } from '../..'
|
|
2
4
|
|
|
3
|
-
// TODO: 定义基础图形的类型
|
|
4
5
|
export type IPolygonProps = {
|
|
5
6
|
points: LogicFlow.PointTuple[]
|
|
7
|
+
x?: number
|
|
8
|
+
y?: number
|
|
6
9
|
className?: string
|
|
7
|
-
[key: string]: any
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
export function Polygon(props: IPolygonProps) {
|
|
11
|
-
const { points, className } = props
|
|
12
|
+
export function Polygon(props: IPolygonProps): h.JSX.Element {
|
|
13
|
+
const { points = [], className } = props
|
|
12
14
|
const attrs: Record<string, any> = {
|
|
13
15
|
fill: 'transparent',
|
|
14
16
|
fillOpacity: 1,
|
|
@@ -17,16 +19,17 @@ export function Polygon(props: IPolygonProps) {
|
|
|
17
19
|
strokeOpacity: 1,
|
|
18
20
|
points: '',
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
22
|
+
|
|
23
|
+
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
24
|
+
if (typeof v !== 'object') {
|
|
23
25
|
attrs[k] = v
|
|
24
26
|
}
|
|
25
27
|
})
|
|
28
|
+
|
|
26
29
|
if (className) {
|
|
27
|
-
attrs.
|
|
30
|
+
attrs.classNmae = `lf-basic-shape ${className}`
|
|
28
31
|
} else {
|
|
29
|
-
attrs.className = 'lf-shape'
|
|
32
|
+
attrs.className = 'lf-basic-shape'
|
|
30
33
|
}
|
|
31
34
|
attrs.points = points.map((point) => point.join(',')).join(' ')
|
|
32
35
|
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createElement as h } from 'preact/compat'
|
|
2
|
+
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
+
|
|
4
|
+
export type IPolylineProps = {
|
|
5
|
+
points: string
|
|
6
|
+
pathLength?: number | 'none'
|
|
7
|
+
className?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Polyline(props: IPolylineProps): h.JSX.Element {
|
|
11
|
+
const { className } = props
|
|
12
|
+
const attrs: Record<string, unknown> = {
|
|
3
13
|
points: '',
|
|
4
14
|
fill: 'none',
|
|
5
15
|
}
|
|
6
|
-
|
|
16
|
+
|
|
17
|
+
forEach(toPairs(props), ([k, v]: [k: string, v: unknown]) => {
|
|
7
18
|
if (k === 'style') {
|
|
8
19
|
attrs[k] = v
|
|
9
|
-
} else {
|
|
10
|
-
|
|
11
|
-
if (valueType !== 'object') {
|
|
12
|
-
attrs[k] = v
|
|
13
|
-
}
|
|
20
|
+
} else if (typeof v !== 'object') {
|
|
21
|
+
attrs[k] = v
|
|
14
22
|
}
|
|
15
23
|
})
|
|
24
|
+
if (className) {
|
|
25
|
+
attrs.className = `${className}`
|
|
26
|
+
}
|
|
27
|
+
|
|
16
28
|
return <polyline {...attrs} />
|
|
17
29
|
}
|
|
18
30
|
|
package/src/view/shape/Rect.tsx
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createElement as h } from 'preact/compat'
|
|
2
|
+
import { forEach, toPairs } from 'lodash-es'
|
|
3
|
+
import LogicFlow from '../..'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export type IRectProps = {
|
|
6
|
+
x: number
|
|
7
|
+
y: number
|
|
8
|
+
width: number
|
|
9
|
+
height: number
|
|
7
10
|
className?: string
|
|
8
|
-
radius?:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
radius?: LogicFlow.NumberOrPercent
|
|
12
|
+
[key: string]: any
|
|
13
|
+
}
|
|
11
14
|
|
|
12
|
-
export function Rect(props: IRectProps) {
|
|
13
|
-
const { x, y, width, height, className, radius } = props
|
|
15
|
+
export function Rect(props: IRectProps): h.JSX.Element {
|
|
16
|
+
const { x, y, width, height, className, strokeWidth, radius = 0 } = props
|
|
14
17
|
|
|
15
18
|
const leftTopX = x - width / 2
|
|
16
19
|
const leftTopY = y - height / 2
|
|
17
20
|
const attrs: Record<string, any> = {}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
+
attrs['stroke-width'] = strokeWidth
|
|
22
|
+
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
23
|
+
if (typeof v !== 'object') {
|
|
21
24
|
attrs[k] = v
|
|
22
25
|
}
|
|
23
26
|
})
|
|
@@ -25,20 +28,17 @@ export function Rect(props: IRectProps) {
|
|
|
25
28
|
if (className) {
|
|
26
29
|
attrs.className = `lf-basic-shape ${className}`
|
|
27
30
|
} else {
|
|
28
|
-
attrs.className = 'lf-shape'
|
|
31
|
+
attrs.className = 'lf-basic-shape'
|
|
29
32
|
}
|
|
33
|
+
|
|
30
34
|
if (radius) {
|
|
31
35
|
attrs.rx = radius
|
|
32
36
|
attrs.ry = radius
|
|
33
37
|
}
|
|
34
38
|
attrs.x = leftTopX
|
|
35
39
|
attrs.y = leftTopY
|
|
36
|
-
return <rect {...attrs} />
|
|
37
|
-
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
className: '',
|
|
41
|
-
radius: '',
|
|
41
|
+
return <rect {...attrs} />
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export default Rect
|
package/src/view/shape/Text.tsx
CHANGED
|
@@ -1,37 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createElement as h } from 'preact/compat'
|
|
2
|
+
import { BaseNodeModel, BaseEdgeModel } from '../../model'
|
|
2
3
|
import { ElementType, ModelType } from '../../constant'
|
|
4
|
+
import { getHtmlTextHeight } from '../../util'
|
|
5
|
+
import { forEach, toPairs } from 'lodash-es'
|
|
6
|
+
|
|
7
|
+
export type ITextProps = {
|
|
8
|
+
x: number
|
|
9
|
+
y: number
|
|
10
|
+
value: string
|
|
11
|
+
fontSize?: number
|
|
12
|
+
fill?: string
|
|
13
|
+
overflowMode?: 'default' | 'autoWrap' | 'ellipsis'
|
|
14
|
+
textWidth?: number
|
|
15
|
+
lineHeight?: number
|
|
16
|
+
fontFamily?: string | null
|
|
17
|
+
wrapPadding?: string | number | null
|
|
18
|
+
model: BaseNodeModel | BaseEdgeModel
|
|
19
|
+
[key: string]: any
|
|
20
|
+
}
|
|
21
|
+
export type ForeignObjectPropsType =
|
|
22
|
+
'string | number | SignalLike<string | number | undefined> | undefined'
|
|
3
23
|
|
|
4
|
-
export function Text(props) {
|
|
24
|
+
export function Text(props: ITextProps): h.JSX.Element | null {
|
|
5
25
|
const {
|
|
6
26
|
x = 0,
|
|
7
27
|
y = 0,
|
|
8
28
|
value,
|
|
9
|
-
fontSize,
|
|
29
|
+
fontSize = 12,
|
|
10
30
|
fill = 'currentColor',
|
|
11
31
|
overflowMode = 'default',
|
|
12
|
-
textWidth
|
|
32
|
+
// TODO: 确认该 textWidth 为 '' 时跟设置什么值一致
|
|
33
|
+
textWidth = undefined,
|
|
13
34
|
model,
|
|
14
35
|
} = props
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
'dominant-baseline': 'middle',
|
|
36
|
+
|
|
37
|
+
const attrs: Record<string, any> = {
|
|
18
38
|
x,
|
|
19
39
|
y,
|
|
20
40
|
fill,
|
|
41
|
+
fontSize,
|
|
42
|
+
textAnchor: 'middle',
|
|
43
|
+
dominantBaseline: 'central',
|
|
21
44
|
// ...props,
|
|
22
45
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
46
|
+
|
|
47
|
+
forEach(toPairs(props), ([k, v]: [k: string, v: any]) => {
|
|
48
|
+
if (typeof v !== 'object') {
|
|
26
49
|
attrs[k] = v
|
|
27
50
|
}
|
|
28
51
|
})
|
|
52
|
+
|
|
29
53
|
if (value) {
|
|
30
|
-
// String(value)
|
|
54
|
+
// String(value),兼容纯数字的文案
|
|
55
|
+
// TODO: 将 value 转为纯文本,移除其中 \n \r 等特殊字符,看是否应该丰富该功能
|
|
31
56
|
const rows = String(value).split(/[\r\n]/g)
|
|
32
57
|
const rowsLength = rows.length
|
|
58
|
+
|
|
33
59
|
if (overflowMode !== 'default') {
|
|
34
|
-
//
|
|
60
|
+
// 非文本节点设置了自动换行,或者边设置了自动换行并且设置了 textWidth
|
|
35
61
|
const { BaseType, modelType } = model
|
|
36
62
|
if (
|
|
37
63
|
(BaseType === ElementType.NODE && modelType !== ModelType.TEXT_NODE) ||
|
|
@@ -40,11 +66,12 @@ export function Text(props) {
|
|
|
40
66
|
return renderHtmlText(props)
|
|
41
67
|
}
|
|
42
68
|
}
|
|
69
|
+
|
|
43
70
|
if (rowsLength > 1) {
|
|
44
|
-
const tSpans = rows.map((row,
|
|
45
|
-
// 保证文字居中,文字Y轴偏移为当前行数对应中心行数的偏移行 * 行高
|
|
46
|
-
const
|
|
47
|
-
const offsetY = (
|
|
71
|
+
const tSpans = rows.map((row, idx) => {
|
|
72
|
+
// 保证文字居中,文字 Y 轴偏移为当前行数对应中心行数的偏移行 * 行高
|
|
73
|
+
const tSpanLineHeight = fontSize + 2
|
|
74
|
+
const offsetY = (idx - (rowsLength - 1) / 2) * tSpanLineHeight
|
|
48
75
|
return (
|
|
49
76
|
<tspan className="lf-text-tspan" x={x} y={y + offsetY}>
|
|
50
77
|
{row}
|
|
@@ -55,24 +82,26 @@ export function Text(props) {
|
|
|
55
82
|
}
|
|
56
83
|
return <text {...attrs}>{value}</text>
|
|
57
84
|
}
|
|
58
|
-
|
|
59
85
|
return null
|
|
60
86
|
}
|
|
61
87
|
|
|
62
|
-
function renderHtmlText(props) {
|
|
88
|
+
export function renderHtmlText(props: ITextProps): h.JSX.Element {
|
|
63
89
|
const {
|
|
90
|
+
x,
|
|
91
|
+
y,
|
|
64
92
|
value,
|
|
65
|
-
fontSize,
|
|
66
93
|
model,
|
|
67
|
-
|
|
94
|
+
textWidth,
|
|
95
|
+
fontSize = 12,
|
|
68
96
|
lineHeight,
|
|
97
|
+
fontFamily = '',
|
|
69
98
|
wrapPadding = '0, 0',
|
|
70
99
|
overflowMode,
|
|
71
|
-
x,
|
|
72
|
-
y,
|
|
73
100
|
} = props
|
|
74
|
-
|
|
75
|
-
const
|
|
101
|
+
|
|
102
|
+
const { width, height, textHeight } = model
|
|
103
|
+
// TODO: 设置文本宽度为 textWidth 或 节点的宽度
|
|
104
|
+
const textRealWidth: number = textWidth || (width as number)
|
|
76
105
|
const rows = String(value).split(/[\r\n]/g)
|
|
77
106
|
const rowsLength = rows.length
|
|
78
107
|
const textRealHeight = getHtmlTextHeight({
|
|
@@ -87,17 +116,20 @@ function renderHtmlText(props) {
|
|
|
87
116
|
rowsLength,
|
|
88
117
|
className: 'lf-get-text-height',
|
|
89
118
|
})
|
|
119
|
+
|
|
90
120
|
// 当文字超过边框时,取文字高度的实际值,也就是文字可以超过边框
|
|
91
|
-
let foreignObjectHeight =
|
|
92
|
-
|
|
93
|
-
//
|
|
121
|
+
let foreignObjectHeight: number =
|
|
122
|
+
(height as number) > textRealHeight ? (height as number) : textRealHeight
|
|
123
|
+
// 如果设置了文本高度,取设置的高度
|
|
94
124
|
if (textHeight) {
|
|
95
|
-
foreignObjectHeight = textHeight
|
|
125
|
+
foreignObjectHeight = textHeight as number
|
|
96
126
|
}
|
|
127
|
+
|
|
97
128
|
const isEllipsis = overflowMode === 'ellipsis'
|
|
98
129
|
if (isEllipsis) {
|
|
99
130
|
foreignObjectHeight = fontSize + 2
|
|
100
131
|
}
|
|
132
|
+
|
|
101
133
|
return (
|
|
102
134
|
<g>
|
|
103
135
|
<foreignObject
|
|
@@ -105,6 +137,7 @@ function renderHtmlText(props) {
|
|
|
105
137
|
height={foreignObjectHeight}
|
|
106
138
|
x={x - textRealWidth / 2}
|
|
107
139
|
y={y - foreignObjectHeight / 2}
|
|
140
|
+
style={{ overflow: 'visible', textAlign: 'left' }}
|
|
108
141
|
>
|
|
109
142
|
<div
|
|
110
143
|
className="lf-node-text-auto-wrap"
|
|
@@ -121,12 +154,10 @@ function renderHtmlText(props) {
|
|
|
121
154
|
: 'lf-node-text-auto-wrap-content'
|
|
122
155
|
}
|
|
123
156
|
title={isEllipsis ? rows.join('') : ''}
|
|
124
|
-
style={{
|
|
125
|
-
...props,
|
|
126
|
-
}}
|
|
157
|
+
style={{ ...(props as h.JSX.CSSProperties) }}
|
|
127
158
|
>
|
|
128
|
-
{rows.map((
|
|
129
|
-
<div className="lf-node-text--auto-wrap-inner">{
|
|
159
|
+
{rows.map((row) => (
|
|
160
|
+
<div className="lf-node-text--auto-wrap-inner">{row}</div>
|
|
130
161
|
))}
|
|
131
162
|
</div>
|
|
132
163
|
</div>
|