@logicflow/core 2.0.0-beta.0 → 2.0.0-beta.10
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 +16 -22
- package/__tests__/bugs/1545-spec.test.ts +19 -15
- package/__tests__/util/edge.test.ts +57 -57
- package/dist/index.min.js +32 -0
- package/dist/index.min.js.map +1 -0
- package/es/LogicFlow.d.ts +88 -40
- package/es/LogicFlow.js +38 -33
- package/es/LogicFlow.js.map +1 -1
- package/es/algorithm/edge.js.map +1 -1
- package/es/algorithm/index.d.ts +2 -0
- package/es/algorithm/index.js +2 -0
- package/es/algorithm/index.js.map +1 -1
- package/es/algorithm/outline.d.ts +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 +39 -2
- package/es/constant/index.js +41 -1
- package/es/constant/index.js.map +1 -1
- package/es/event/eventArgs.d.ts +103 -25
- package/es/event/eventEmitter.d.ts +2 -2
- package/es/event/eventEmitter.js +0 -1
- package/es/event/eventEmitter.js.map +1 -1
- package/es/index.d.ts +6 -1
- package/es/index.js +6 -1
- package/es/index.js.map +1 -1
- package/es/keyboard/index.d.ts +1 -0
- package/es/keyboard/index.js +1 -0
- package/es/keyboard/index.js.map +1 -1
- package/es/keyboard/shortcut.d.ts +8 -0
- package/es/keyboard/shortcut.js +70 -8
- package/es/keyboard/shortcut.js.map +1 -1
- package/es/model/BaseModel.d.ts +16 -7
- package/es/model/EditConfigModel.d.ts +97 -36
- package/es/model/EditConfigModel.js +169 -82
- package/es/model/EditConfigModel.js.map +1 -1
- package/es/model/GraphModel.d.ts +36 -14
- package/es/model/GraphModel.js +60 -10
- package/es/model/GraphModel.js.map +1 -1
- package/es/model/SnaplineModel.d.ts +2 -0
- package/es/model/TransformModel.js +1 -1
- package/es/model/TransformModel.js.map +1 -1
- package/es/model/edge/BaseEdgeModel.d.ts +21 -17
- package/es/model/edge/BaseEdgeModel.js +64 -42
- package/es/model/edge/BaseEdgeModel.js.map +1 -1
- package/es/model/edge/BezierEdgeModel.d.ts +5 -3
- package/es/model/edge/BezierEdgeModel.js +7 -3
- package/es/model/edge/BezierEdgeModel.js.map +1 -1
- package/es/model/edge/LineEdgeModel.d.ts +2 -0
- package/es/model/edge/LineEdgeModel.js +2 -1
- package/es/model/edge/LineEdgeModel.js.map +1 -1
- package/es/model/edge/PolylineEdgeModel.d.ts +5 -3
- package/es/model/edge/PolylineEdgeModel.js +22 -15
- package/es/model/edge/PolylineEdgeModel.js.map +1 -1
- package/es/model/node/BaseNodeModel.d.ts +42 -14
- package/es/model/node/BaseNodeModel.js +62 -48
- package/es/model/node/BaseNodeModel.js.map +1 -1
- package/es/model/node/CircleNodeModel.d.ts +4 -3
- package/es/model/node/CircleNodeModel.js +4 -7
- package/es/model/node/CircleNodeModel.js.map +1 -1
- package/es/model/node/DiamondNodeModel.d.ts +5 -4
- package/es/model/node/DiamondNodeModel.js +4 -6
- package/es/model/node/DiamondNodeModel.js.map +1 -1
- package/es/model/node/EllipseNodeModel.d.ts +5 -4
- package/es/model/node/EllipseNodeModel.js +4 -6
- package/es/model/node/EllipseNodeModel.js.map +1 -1
- package/es/model/node/HtmlNodeModel.d.ts +4 -5
- package/es/model/node/HtmlNodeModel.js +2 -12
- package/es/model/node/HtmlNodeModel.js.map +1 -1
- package/es/model/node/PolygonNodeModel.d.ts +5 -4
- package/es/model/node/PolygonNodeModel.js +4 -7
- package/es/model/node/PolygonNodeModel.js.map +1 -1
- package/es/model/node/RectNodeModel.d.ts +7 -5
- package/es/model/node/RectNodeModel.js +10 -7
- package/es/model/node/RectNodeModel.js.map +1 -1
- package/es/model/node/TextNodeModel.d.ts +17 -9
- package/es/model/node/TextNodeModel.js +2 -1
- package/es/model/node/TextNodeModel.js.map +1 -1
- package/es/options.d.ts +11 -14
- package/es/options.js +3 -42
- package/es/options.js.map +1 -1
- package/es/tool/MultipleSelectTool.d.ts +1 -1
- package/es/tool/MultipleSelectTool.js +5 -5
- package/es/tool/MultipleSelectTool.js.map +1 -1
- package/es/tool/TextEditTool.d.ts +3 -3
- package/es/tool/TextEditTool.js +2 -2
- package/es/tool/TextEditTool.js.map +1 -1
- package/es/tool/index.d.ts +24 -2
- package/es/tool/index.js +82 -2
- package/es/tool/index.js.map +1 -1
- package/es/util/drag.d.ts +5 -5
- package/es/util/drag.js +3 -1
- package/es/util/drag.js.map +1 -1
- package/es/util/edge.d.ts +9 -2
- package/es/util/edge.js +23 -12
- package/es/util/edge.js.map +1 -1
- package/es/util/index.d.ts +1 -0
- package/es/util/index.js +1 -0
- package/es/util/index.js.map +1 -1
- package/es/util/node.d.ts +8 -7
- package/es/util/node.js +26 -7
- package/es/util/node.js.map +1 -1
- package/es/util/resize.d.ts +32 -0
- package/es/util/resize.js +197 -0
- package/es/util/resize.js.map +1 -0
- package/es/view/Anchor.d.ts +6 -7
- package/es/view/Anchor.js +6 -3
- package/es/view/Anchor.js.map +1 -1
- package/es/view/Control.d.ts +1 -1
- package/es/view/Control.js +88 -39
- package/es/view/Control.js.map +1 -1
- package/es/view/Graph.d.ts +5 -1
- package/es/view/Graph.js +45 -5
- package/es/view/Graph.js.map +1 -1
- package/es/view/Rotate.js +2 -1
- package/es/view/Rotate.js.map +1 -1
- package/es/view/behavior/index.d.ts +2 -0
- package/es/view/behavior/index.js +3 -0
- package/es/view/behavior/index.js.map +1 -0
- package/es/view/behavior/snapline.d.ts +3 -0
- package/es/{tool → view/behavior}/snapline.js +0 -1
- package/es/view/behavior/snapline.js.map +1 -0
- package/es/view/edge/AdjustPoint.js +12 -23
- package/es/view/edge/AdjustPoint.js.map +1 -1
- package/es/view/edge/BaseEdge.d.ts +2 -2
- package/es/view/edge/BaseEdge.js +30 -22
- package/es/view/edge/BaseEdge.js.map +1 -1
- package/es/view/node/BaseNode.d.ts +4 -4
- package/es/view/node/BaseNode.js +33 -24
- package/es/view/node/BaseNode.js.map +1 -1
- package/es/view/node/CircleNode.d.ts +1 -1
- package/es/view/node/CircleNode.js.map +1 -1
- package/es/view/node/DiamondNode.d.ts +1 -1
- package/es/view/node/DiamondNode.js.map +1 -1
- package/es/view/node/EllipseNode.d.ts +1 -1
- package/es/view/node/EllipseNode.js.map +1 -1
- package/es/view/node/HtmlNode.d.ts +1 -1
- package/es/view/node/HtmlNode.js +2 -2
- package/es/view/node/HtmlNode.js.map +1 -1
- package/es/view/node/PolygonNode.d.ts +1 -1
- package/es/view/node/PolygonNode.js.map +1 -1
- package/es/view/node/RectNode.d.ts +1 -1
- package/es/view/node/RectNode.js.map +1 -1
- package/es/view/node/TextNode.d.ts +1 -1
- package/es/view/node/TextNode.js +1 -1
- package/es/view/node/TextNode.js.map +1 -1
- package/es/view/overlay/CanvasOverlay.js +5 -4
- package/es/view/overlay/CanvasOverlay.js.map +1 -1
- package/es/view/overlay/Grid.d.ts +35 -20
- package/es/view/overlay/Grid.js +35 -26
- package/es/view/overlay/Grid.js.map +1 -1
- package/es/view/overlay/ToolOverlay.d.ts +1 -1
- package/es/view/overlay/ToolOverlay.js +1 -1
- package/es/view/overlay/ToolOverlay.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 +43 -29
- 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 +88 -40
- package/lib/LogicFlow.js +40 -35
- package/lib/LogicFlow.js.map +1 -1
- package/lib/algorithm/edge.js.map +1 -1
- package/lib/algorithm/index.d.ts +2 -0
- package/lib/algorithm/index.js +17 -1
- package/lib/algorithm/index.js.map +1 -1
- package/lib/algorithm/outline.d.ts +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 +39 -2
- package/lib/constant/index.js +42 -2
- package/lib/constant/index.js.map +1 -1
- package/lib/event/eventArgs.d.ts +103 -25
- package/lib/event/eventEmitter.d.ts +2 -2
- package/lib/event/eventEmitter.js +0 -1
- package/lib/event/eventEmitter.js.map +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.js +7 -2
- package/lib/index.js.map +1 -1
- package/lib/keyboard/index.d.ts +1 -0
- package/lib/keyboard/index.js +15 -0
- package/lib/keyboard/index.js.map +1 -1
- package/lib/keyboard/shortcut.d.ts +8 -0
- package/lib/keyboard/shortcut.js +75 -9
- package/lib/keyboard/shortcut.js.map +1 -1
- package/lib/model/BaseModel.d.ts +16 -7
- package/lib/model/EditConfigModel.d.ts +97 -36
- package/lib/model/EditConfigModel.js +168 -81
- package/lib/model/EditConfigModel.js.map +1 -1
- package/lib/model/GraphModel.d.ts +36 -14
- package/lib/model/GraphModel.js +59 -9
- package/lib/model/GraphModel.js.map +1 -1
- package/lib/model/SnaplineModel.d.ts +2 -0
- package/lib/model/TransformModel.js +1 -1
- package/lib/model/TransformModel.js.map +1 -1
- package/lib/model/edge/BaseEdgeModel.d.ts +21 -17
- package/lib/model/edge/BaseEdgeModel.js +61 -39
- package/lib/model/edge/BaseEdgeModel.js.map +1 -1
- package/lib/model/edge/BezierEdgeModel.d.ts +5 -3
- package/lib/model/edge/BezierEdgeModel.js +6 -2
- package/lib/model/edge/BezierEdgeModel.js.map +1 -1
- package/lib/model/edge/LineEdgeModel.d.ts +2 -0
- package/lib/model/edge/LineEdgeModel.js +2 -1
- package/lib/model/edge/LineEdgeModel.js.map +1 -1
- package/lib/model/edge/PolylineEdgeModel.d.ts +5 -3
- package/lib/model/edge/PolylineEdgeModel.js +21 -14
- package/lib/model/edge/PolylineEdgeModel.js.map +1 -1
- package/lib/model/node/BaseNodeModel.d.ts +42 -14
- package/lib/model/node/BaseNodeModel.js +60 -46
- package/lib/model/node/BaseNodeModel.js.map +1 -1
- package/lib/model/node/CircleNodeModel.d.ts +4 -3
- package/lib/model/node/CircleNodeModel.js +4 -7
- package/lib/model/node/CircleNodeModel.js.map +1 -1
- package/lib/model/node/DiamondNodeModel.d.ts +5 -4
- package/lib/model/node/DiamondNodeModel.js +4 -6
- package/lib/model/node/DiamondNodeModel.js.map +1 -1
- package/lib/model/node/EllipseNodeModel.d.ts +5 -4
- package/lib/model/node/EllipseNodeModel.js +4 -6
- package/lib/model/node/EllipseNodeModel.js.map +1 -1
- package/lib/model/node/HtmlNodeModel.d.ts +4 -5
- package/lib/model/node/HtmlNodeModel.js +2 -12
- package/lib/model/node/HtmlNodeModel.js.map +1 -1
- package/lib/model/node/PolygonNodeModel.d.ts +5 -4
- package/lib/model/node/PolygonNodeModel.js +4 -7
- package/lib/model/node/PolygonNodeModel.js.map +1 -1
- package/lib/model/node/RectNodeModel.d.ts +7 -5
- package/lib/model/node/RectNodeModel.js +10 -7
- package/lib/model/node/RectNodeModel.js.map +1 -1
- package/lib/model/node/TextNodeModel.d.ts +17 -9
- package/lib/model/node/TextNodeModel.js +2 -1
- package/lib/model/node/TextNodeModel.js.map +1 -1
- package/lib/options.d.ts +11 -14
- package/lib/options.js +3 -42
- package/lib/options.js.map +1 -1
- package/lib/tool/MultipleSelectTool.d.ts +1 -1
- package/lib/tool/MultipleSelectTool.js +5 -5
- package/lib/tool/MultipleSelectTool.js.map +1 -1
- package/lib/tool/TextEditTool.d.ts +3 -3
- package/lib/tool/TextEditTool.js +4 -4
- package/lib/tool/TextEditTool.js.map +1 -1
- package/lib/tool/index.d.ts +24 -2
- package/lib/tool/index.js +85 -15
- package/lib/tool/index.js.map +1 -1
- package/lib/util/drag.d.ts +5 -5
- package/lib/util/drag.js +3 -1
- package/lib/util/drag.js.map +1 -1
- package/lib/util/edge.d.ts +9 -2
- package/lib/util/edge.js +27 -15
- package/lib/util/edge.js.map +1 -1
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/node.d.ts +8 -7
- package/lib/util/node.js +28 -9
- package/lib/util/node.js.map +1 -1
- package/lib/util/resize.d.ts +32 -0
- package/lib/util/resize.js +204 -0
- package/lib/util/resize.js.map +1 -0
- package/lib/view/Anchor.d.ts +6 -7
- package/lib/view/Anchor.js +5 -2
- package/lib/view/Anchor.js.map +1 -1
- package/lib/view/Control.d.ts +1 -1
- package/lib/view/Control.js +87 -38
- package/lib/view/Control.js.map +1 -1
- package/lib/view/Graph.d.ts +5 -1
- package/lib/view/Graph.js +44 -4
- package/lib/view/Graph.js.map +1 -1
- package/lib/view/Rotate.js +2 -1
- package/lib/view/Rotate.js.map +1 -1
- package/lib/view/behavior/index.d.ts +2 -0
- package/lib/view/behavior/index.js +19 -0
- package/lib/view/behavior/index.js.map +1 -0
- package/lib/view/behavior/snapline.d.ts +3 -0
- package/lib/{tool → view/behavior}/snapline.js +0 -1
- package/lib/view/behavior/snapline.js.map +1 -0
- package/lib/view/edge/AdjustPoint.js +11 -22
- package/lib/view/edge/AdjustPoint.js.map +1 -1
- package/lib/view/edge/BaseEdge.d.ts +2 -2
- package/lib/view/edge/BaseEdge.js +29 -21
- package/lib/view/edge/BaseEdge.js.map +1 -1
- package/lib/view/node/BaseNode.d.ts +4 -4
- package/lib/view/node/BaseNode.js +32 -23
- package/lib/view/node/BaseNode.js.map +1 -1
- package/lib/view/node/CircleNode.d.ts +1 -1
- package/lib/view/node/CircleNode.js.map +1 -1
- package/lib/view/node/DiamondNode.d.ts +1 -1
- package/lib/view/node/DiamondNode.js.map +1 -1
- package/lib/view/node/EllipseNode.d.ts +1 -1
- package/lib/view/node/EllipseNode.js.map +1 -1
- package/lib/view/node/HtmlNode.d.ts +1 -1
- package/lib/view/node/HtmlNode.js +2 -2
- package/lib/view/node/HtmlNode.js.map +1 -1
- package/lib/view/node/PolygonNode.d.ts +1 -1
- package/lib/view/node/PolygonNode.js.map +1 -1
- package/lib/view/node/RectNode.d.ts +1 -1
- package/lib/view/node/RectNode.js.map +1 -1
- package/lib/view/node/TextNode.d.ts +1 -1
- package/lib/view/node/TextNode.js +1 -1
- package/lib/view/node/TextNode.js.map +1 -1
- package/lib/view/overlay/CanvasOverlay.js +5 -4
- package/lib/view/overlay/CanvasOverlay.js.map +1 -1
- package/lib/view/overlay/Grid.d.ts +35 -20
- package/lib/view/overlay/Grid.js +35 -26
- package/lib/view/overlay/Grid.js.map +1 -1
- package/lib/view/overlay/ToolOverlay.d.ts +1 -1
- package/lib/view/overlay/ToolOverlay.js +1 -1
- package/lib/view/overlay/ToolOverlay.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 +46 -29
- 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 +5 -4
- package/src/LogicFlow.tsx +163 -79
- package/src/algorithm/edge.ts +1 -0
- package/src/algorithm/index.ts +2 -0
- package/src/algorithm/outline.ts +2 -2
- package/src/common/drag.ts +219 -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 +43 -1
- package/src/event/eventArgs.ts +173 -34
- package/src/event/eventEmitter.ts +2 -3
- package/src/index.ts +6 -1
- package/src/keyboard/index.ts +2 -0
- package/src/keyboard/shortcut.ts +79 -8
- package/src/model/BaseModel.ts +18 -7
- package/src/model/EditConfigModel.ts +209 -97
- package/src/model/GraphModel.ts +64 -9
- package/src/model/TransformModel.ts +1 -1
- package/src/model/edge/BaseEdgeModel.ts +105 -42
- package/src/model/edge/BezierEdgeModel.ts +7 -6
- package/src/model/edge/LineEdgeModel.ts +2 -0
- package/src/model/edge/PolylineEdgeModel.ts +24 -18
- package/src/model/node/BaseNodeModel.ts +72 -47
- package/src/model/node/CircleNodeModel.ts +8 -7
- package/src/model/node/DiamondNodeModel.ts +9 -6
- package/src/model/node/EllipseNodeModel.ts +9 -6
- package/src/model/node/HtmlNodeModel.ts +8 -7
- package/src/model/node/PolygonNodeModel.ts +9 -7
- package/src/model/node/RectNodeModel.ts +16 -8
- package/src/model/node/TextNodeModel.ts +14 -1
- package/src/options.ts +18 -53
- package/src/tool/MultipleSelectTool.tsx +6 -6
- package/src/tool/TextEditTool.tsx +3 -3
- package/src/tool/index.ts +96 -2
- package/src/util/drag.ts +22 -6
- package/src/util/edge.ts +39 -13
- package/src/util/index.ts +1 -0
- package/src/util/node.ts +36 -13
- package/src/util/resize.ts +286 -0
- package/src/view/Anchor.tsx +7 -5
- package/src/view/Control.tsx +93 -62
- package/src/view/Graph.tsx +23 -6
- package/src/view/Rotate.tsx +2 -1
- package/src/view/behavior/index.ts +2 -0
- package/src/{tool → view/behavior}/snapline.ts +3 -4
- package/src/view/edge/AdjustPoint.tsx +35 -49
- package/src/view/edge/BaseEdge.tsx +65 -45
- package/src/view/node/BaseNode.tsx +55 -28
- package/src/view/node/CircleNode.tsx +3 -1
- package/src/view/node/DiamondNode.tsx +3 -1
- package/src/view/node/EllipseNode.tsx +3 -1
- package/src/view/node/HtmlNode.tsx +5 -3
- package/src/view/node/PolygonNode.tsx +3 -1
- package/src/view/node/RectNode.tsx +3 -1
- package/src/view/node/TextNode.tsx +4 -2
- package/src/view/overlay/CanvasOverlay.tsx +5 -4
- package/src/view/overlay/Grid.tsx +75 -53
- package/src/view/overlay/ToolOverlay.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 +76 -42
- package/src/view/text/LineText.tsx +94 -80
- package/tsconfig.json +1 -1
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
- package/es/tool/snapline.d.ts +0 -3
- package/es/tool/snapline.js.map +0 -1
- package/es/tool/tool.d.ts +0 -22
- package/es/tool/tool.js +0 -43
- package/es/tool/tool.js.map +0 -1
- package/lib/tool/snapline.d.ts +0 -3
- package/lib/tool/snapline.js.map +0 -1
- package/lib/tool/tool.d.ts +0 -22
- package/lib/tool/tool.js +0 -49
- package/lib/tool/tool.js.map +0 -1
- package/src/tool/tool.ts +0 -66
|
@@ -1,33 +1,16 @@
|
|
|
1
1
|
import { Component } from 'preact/compat'
|
|
2
|
+
import { cloneDeep, assign } from 'lodash-es'
|
|
2
3
|
import { observer } from '../..'
|
|
3
4
|
import { createUuid } from '../../util'
|
|
4
5
|
import { GraphModel } from '../../model'
|
|
5
6
|
import { DEFAULT_GRID_SIZE } from '../../constant'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 网格格子间距
|
|
10
|
-
*/
|
|
11
|
-
size?: number
|
|
12
|
-
/**
|
|
13
|
-
* 网格是否可见
|
|
14
|
-
*/
|
|
15
|
-
visible?: boolean
|
|
8
|
+
import GridOptions = Grid.GridOptions
|
|
16
9
|
|
|
10
|
+
type IProps = GridOptions & {
|
|
17
11
|
graphModel: GraphModel
|
|
18
|
-
/**
|
|
19
|
-
* 网格类型
|
|
20
|
-
* 'dot' || 'mesh'
|
|
21
|
-
*/
|
|
22
|
-
type?: string
|
|
23
|
-
config?: {
|
|
24
|
-
color: string
|
|
25
|
-
thickness?: number
|
|
26
|
-
}
|
|
27
12
|
}
|
|
28
13
|
|
|
29
|
-
type IProps = GridOptions
|
|
30
|
-
|
|
31
14
|
@observer
|
|
32
15
|
export class Grid extends Component<IProps> {
|
|
33
16
|
readonly id = createUuid()
|
|
@@ -38,21 +21,16 @@ export class Grid extends Component<IProps> {
|
|
|
38
21
|
|
|
39
22
|
const { color, thickness = 2 } = config ?? {}
|
|
40
23
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
opacity = 0
|
|
45
|
-
}
|
|
46
|
-
/* eslint-disable-next-line */
|
|
24
|
+
// 对于点状网格,点的半径不能大于网格大小的四分之一
|
|
25
|
+
const radius = Math.min(Math.max(2, thickness), size / 4)
|
|
26
|
+
const opacity = visible ? 1 : 0
|
|
47
27
|
return (
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
opacity={opacity}
|
|
55
|
-
/>
|
|
28
|
+
<g fill={color} opacity={opacity}>
|
|
29
|
+
<circle cx={0} cy={0} r={radius / 2} />
|
|
30
|
+
<circle cx={0} cy={size} r={radius / 2} />
|
|
31
|
+
<circle cx={size} cy={0} r={radius / 2} />
|
|
32
|
+
<circle cx={size} cy={size} r={radius / 2} />
|
|
33
|
+
</g>
|
|
56
34
|
)
|
|
57
35
|
}
|
|
58
36
|
|
|
@@ -61,22 +39,26 @@ export class Grid extends Component<IProps> {
|
|
|
61
39
|
renderMesh() {
|
|
62
40
|
const { config, size = 1, visible } = this.props
|
|
63
41
|
const { color, thickness = 1 } = config ?? {}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
42
|
+
|
|
43
|
+
// 对于交叉线网格,线的宽度不能大于网格大小的一半
|
|
44
|
+
const strokeWidth = Math.min(Math.max(1, thickness), size / 2)
|
|
45
|
+
const d = `M 0 0 H ${size} V ${size} H 0 Z`
|
|
46
|
+
const opacity = visible ? 1 : 0
|
|
70
47
|
return (
|
|
71
|
-
<path
|
|
48
|
+
<path
|
|
49
|
+
d={d}
|
|
50
|
+
stroke={color}
|
|
51
|
+
strokeWidth={strokeWidth}
|
|
52
|
+
opacity={opacity}
|
|
53
|
+
fill="transparent"
|
|
54
|
+
/>
|
|
72
55
|
)
|
|
73
56
|
}
|
|
74
57
|
|
|
75
58
|
render() {
|
|
76
|
-
// TODO 生成网格️️️✔、网格支持 options(size)✔
|
|
77
59
|
const {
|
|
78
60
|
type,
|
|
79
|
-
size,
|
|
61
|
+
size = 1,
|
|
80
62
|
graphModel: { transformModel },
|
|
81
63
|
} = this.props
|
|
82
64
|
const { SCALE_X, SKEW_Y, SKEW_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y } =
|
|
@@ -122,14 +104,54 @@ export class Grid extends Component<IProps> {
|
|
|
122
104
|
}
|
|
123
105
|
}
|
|
124
106
|
|
|
125
|
-
Grid
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
107
|
+
export namespace Grid {
|
|
108
|
+
export type GridOptions = {
|
|
109
|
+
/**
|
|
110
|
+
* 网格格子间距
|
|
111
|
+
*/
|
|
112
|
+
size?: number
|
|
113
|
+
/**
|
|
114
|
+
* 网格是否可见
|
|
115
|
+
*/
|
|
116
|
+
visible?: boolean
|
|
117
|
+
/**
|
|
118
|
+
* 网格类型
|
|
119
|
+
* - `dot` 点状网格
|
|
120
|
+
* - `mesh` 交叉线网格
|
|
121
|
+
*/
|
|
122
|
+
type?: 'dot' | 'mesh'
|
|
123
|
+
config?: {
|
|
124
|
+
/**
|
|
125
|
+
* 网格的颜色
|
|
126
|
+
*/
|
|
127
|
+
color: string
|
|
128
|
+
/**
|
|
129
|
+
* 网格的宽度
|
|
130
|
+
* - 对于 `dot` 点状网格,表示点的大小
|
|
131
|
+
* - 对于 `mesh` 交叉线网格,表示线的宽度
|
|
132
|
+
*/
|
|
133
|
+
thickness?: number
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const defaultProps: GridOptions = {
|
|
138
|
+
size: DEFAULT_GRID_SIZE,
|
|
139
|
+
visible: true,
|
|
140
|
+
type: 'dot',
|
|
141
|
+
config: {
|
|
142
|
+
color: '#ababab',
|
|
143
|
+
thickness: 1,
|
|
144
|
+
},
|
|
145
|
+
}
|
|
134
146
|
|
|
135
|
-
export
|
|
147
|
+
export function getGridOptions(options: number | boolean | GridOptions) {
|
|
148
|
+
const defaultOptions = cloneDeep(Grid.defaultProps)
|
|
149
|
+
if (typeof options === 'number') {
|
|
150
|
+
return assign(defaultOptions, { size: options })
|
|
151
|
+
} else if (typeof options === 'boolean') {
|
|
152
|
+
return assign(defaultOptions, { visible: options })
|
|
153
|
+
} else {
|
|
154
|
+
return assign(defaultOptions, options)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -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>
|