@logicflow/core 2.0.0-beta.1 → 2.0.0-beta.3
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 +8 -8
- package/dist/index.min.js +9 -3
- package/es/LogicFlow.d.ts +37 -20
- package/es/LogicFlow.js +27 -24
- 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/event/eventEmitter.js +1 -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/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.d.ts +2 -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 +3 -0
- package/es/view/Graph.js +38 -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 +37 -20
- package/lib/LogicFlow.js +26 -23
- 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/event/eventEmitter.js +1 -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/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.d.ts +2 -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 +3 -0
- package/lib/view/Graph.js +37 -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 +97 -55
- 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/event/eventEmitter.ts +1 -1
- package/src/index.ts +1 -1
- 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 +4 -13
- 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 +14 -2
- 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/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,
|
|
@@ -37,6 +37,18 @@ type ContainerStyle = {
|
|
|
37
37
|
|
|
38
38
|
@observer
|
|
39
39
|
class Graph extends Component<IGraphProps> {
|
|
40
|
+
handleResize = () => {
|
|
41
|
+
this.props.graphModel.resize()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
componentDidMount() {
|
|
45
|
+
window.addEventListener('resize', throttle(this.handleResize, 200))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
componentWillUnmount() {
|
|
49
|
+
window.removeEventListener('resize', throttle(this.handleResize, 200))
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
getComponent(
|
|
41
53
|
model: BaseEdgeModel | BaseNodeModel,
|
|
42
54
|
graphModel: GraphModel,
|
|
@@ -73,7 +85,7 @@ class Graph extends Component<IGraphProps> {
|
|
|
73
85
|
const { adjustEdge } = editConfigModel
|
|
74
86
|
|
|
75
87
|
return (
|
|
76
|
-
<div className="lf-graph" flow-id={graphModel.flowId}
|
|
88
|
+
<div className="lf-graph" flow-id={graphModel.flowId}>
|
|
77
89
|
<CanvasOverlay graphModel={graphModel} dnd={dnd}>
|
|
78
90
|
<g className="lf-base">
|
|
79
91
|
{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()}
|
|
@@ -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
|