@logicflow/core 1.2.27 → 2.0.0-beta.0
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 +10 -0
- package/.turbo/turbo-build.log +42 -0
- package/CHANGELOG.md +2114 -0
- package/LICENSE +206 -0
- package/__tests__/algorithm/egde.test.ts +118 -0
- package/__tests__/algorithm/index.test.ts +69 -0
- package/__tests__/algorithm/outline.test.ts +43 -0
- package/__tests__/bugs/1545-spec.test.ts +38 -0
- package/__tests__/event/event.test.ts +22 -0
- package/__tests__/history/history.test.ts +28 -0
- package/__tests__/logicflow.test.ts +567 -0
- package/__tests__/model/graphmodel.test.ts +67 -0
- package/__tests__/util/compatible.test.ts +48 -0
- package/__tests__/util/edge.test.ts +224 -0
- package/__tests__/util/geometry.test.ts +14 -0
- package/__tests__/util/graph.test.ts +16 -0
- package/__tests__/util/matrix.test.ts +41 -0
- package/__tests__/util/node.test.ts +68 -0
- package/__tests__/util/sampling.test.ts +16 -0
- package/__tests__/util/vector.test.ts +50 -0
- package/__tests__/util/zIndex.test.ts +10 -0
- package/dist/{style/index.css → index.css} +64 -52
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/es/LogicFlow.d.ts +966 -0
- package/es/LogicFlow.js +1174 -0
- package/es/LogicFlow.js.map +1 -0
- package/es/algorithm/edge.d.ts +15 -0
- package/es/algorithm/edge.js +57 -0
- package/es/algorithm/edge.js.map +1 -0
- package/es/algorithm/index.js +71 -0
- package/es/algorithm/index.js.map +1 -0
- package/es/algorithm/outline.d.ts +7 -0
- package/es/algorithm/outline.js +61 -0
- package/es/algorithm/outline.js.map +1 -0
- package/{types/constant/constant.d.ts → es/constant/index.d.ts} +23 -22
- package/es/constant/index.js +117 -0
- package/es/constant/index.js.map +1 -0
- package/es/event/eventArgs.d.ts +428 -0
- package/es/event/eventArgs.js +2 -0
- package/es/event/eventArgs.js.map +1 -0
- package/es/event/eventEmitter.d.ts +48 -0
- package/es/event/eventEmitter.js +92 -0
- package/es/event/eventEmitter.js.map +1 -0
- package/es/history/index.d.ts +23 -0
- package/es/history/index.js +111 -0
- package/es/history/index.js.map +1 -0
- package/es/index.css +210 -0
- package/{types → es}/index.d.ts +4 -6
- package/es/index.js +16 -0
- package/es/index.js.map +1 -0
- package/es/index.less +1 -0
- package/{types → es}/keyboard/index.d.ts +7 -8
- package/es/keyboard/index.js +87 -0
- package/es/keyboard/index.js.map +1 -0
- package/es/keyboard/shortcut.js +116 -0
- package/es/keyboard/shortcut.js.map +1 -0
- package/es/model/BaseModel.d.ts +181 -0
- package/es/model/BaseModel.js +2 -0
- package/es/model/BaseModel.js.map +1 -0
- package/{types → es}/model/EditConfigModel.d.ts +13 -8
- package/es/model/EditConfigModel.js +192 -0
- package/es/model/EditConfigModel.js.map +1 -0
- package/{types → es}/model/GraphModel.d.ts +118 -178
- package/es/model/GraphModel.js +1473 -0
- package/es/model/GraphModel.js.map +1 -0
- package/es/model/SnaplineModel.d.ts +34 -0
- package/es/model/SnaplineModel.js +217 -0
- package/es/model/SnaplineModel.js.map +1 -0
- package/{types → es}/model/TransformModel.d.ts +21 -11
- package/es/model/TransformModel.js +240 -0
- package/es/model/TransformModel.js.map +1 -0
- package/{types → es}/model/edge/BaseEdgeModel.d.ts +82 -63
- package/es/model/edge/BaseEdgeModel.js +739 -0
- package/es/model/edge/BaseEdgeModel.js.map +1 -0
- package/es/model/edge/BezierEdgeModel.d.ts +63 -0
- package/es/model/edge/BezierEdgeModel.js +244 -0
- package/es/model/edge/BezierEdgeModel.js.map +1 -0
- package/es/model/edge/LineEdgeModel.d.ts +19 -0
- package/es/model/edge/LineEdgeModel.js +77 -0
- package/es/model/edge/LineEdgeModel.js.map +1 -0
- package/es/model/edge/PolylineEdgeModel.d.ts +85 -0
- package/es/model/edge/PolylineEdgeModel.js +593 -0
- package/es/model/edge/PolylineEdgeModel.js.map +1 -0
- package/es/model/edge/index.js +5 -0
- package/es/model/edge/index.js.map +1 -0
- package/es/model/index.js +8 -0
- package/es/model/index.js.map +1 -0
- package/es/model/node/BaseNodeModel.d.ts +260 -0
- package/es/model/node/BaseNodeModel.js +883 -0
- package/es/model/node/BaseNodeModel.js.map +1 -0
- package/es/model/node/CircleNodeModel.d.ts +40 -0
- package/es/model/node/CircleNodeModel.js +110 -0
- package/es/model/node/CircleNodeModel.js.map +1 -0
- package/es/model/node/DiamondNodeModel.d.ts +46 -0
- package/es/model/node/DiamondNodeModel.js +187 -0
- package/es/model/node/DiamondNodeModel.js.map +1 -0
- package/es/model/node/EllipseNodeModel.d.ts +42 -0
- package/es/model/node/EllipseNodeModel.js +118 -0
- package/es/model/node/EllipseNodeModel.js.map +1 -0
- package/es/model/node/HtmlNodeModel.d.ts +21 -0
- package/es/model/node/HtmlNodeModel.js +59 -0
- package/es/model/node/HtmlNodeModel.js.map +1 -0
- package/es/model/node/PolygonNodeModel.d.ts +50 -0
- package/es/model/node/PolygonNodeModel.js +196 -0
- package/es/model/node/PolygonNodeModel.js.map +1 -0
- package/es/model/node/RectNodeModel.d.ts +34 -0
- package/es/model/node/RectNodeModel.js +80 -0
- package/es/model/node/RectNodeModel.js.map +1 -0
- package/es/model/node/TextNodeModel.d.ts +27 -0
- package/es/model/node/TextNodeModel.js +113 -0
- package/es/model/node/TextNodeModel.js.map +1 -0
- package/es/model/node/index.js +9 -0
- package/es/model/node/index.js.map +1 -0
- package/es/options.d.ts +86 -0
- package/es/options.js +74 -0
- package/es/options.js.map +1 -0
- package/es/style/index.css +210 -0
- package/es/style/index.less +256 -0
- package/es/style/raw.d.ts +4 -0
- package/es/style/raw.js +6 -0
- package/es/style/raw.js.map +1 -0
- package/es/tool/MultipleSelectTool.d.ts +13 -0
- package/es/tool/MultipleSelectTool.js +159 -0
- package/es/tool/MultipleSelectTool.js.map +1 -0
- package/es/tool/TextEditTool.d.ts +26 -0
- package/es/tool/TextEditTool.js +187 -0
- package/es/tool/TextEditTool.js.map +1 -0
- package/es/tool/index.d.ts +2 -0
- package/es/tool/index.js +3 -0
- package/es/tool/index.js.map +1 -0
- package/{types/tool/SnaplineTool.d.ts → es/tool/snapline.d.ts} +1 -1
- package/es/tool/snapline.js +13 -0
- package/es/tool/snapline.js.map +1 -0
- package/es/tool/tool.d.ts +22 -0
- package/es/tool/tool.js +43 -0
- package/es/tool/tool.js.map +1 -0
- package/es/util/animation.d.ts +12 -0
- package/es/util/animation.js +20 -0
- package/es/util/animation.js.map +1 -0
- package/es/util/browser.js +3 -0
- package/es/util/browser.js.map +1 -0
- package/es/util/compatible.d.ts +6 -0
- package/es/util/compatible.js +17 -0
- package/es/util/compatible.js.map +1 -0
- package/es/util/drag.d.ts +47 -0
- package/es/util/drag.js +139 -0
- package/es/util/drag.js.map +1 -0
- package/es/util/edge.d.ts +94 -0
- package/es/util/edge.js +833 -0
- package/es/util/edge.js.map +1 -0
- package/es/util/geometry.d.ts +11 -0
- package/es/util/geometry.js +72 -0
- package/es/util/geometry.js.map +1 -0
- package/{types → es}/util/graph.d.ts +4 -3
- package/es/util/graph.js +54 -0
- package/es/util/graph.js.map +1 -0
- package/es/util/index.d.ts +16 -0
- package/es/util/index.js +17 -0
- package/es/util/index.js.map +1 -0
- package/{types → es}/util/matrix.d.ts +1 -1
- package/es/util/matrix.js +161 -0
- package/es/util/matrix.js.map +1 -0
- package/es/util/mobx.js +4 -0
- package/es/util/mobx.js.map +1 -0
- package/es/util/node.d.ts +69 -0
- package/es/util/node.js +402 -0
- package/es/util/node.js.map +1 -0
- package/es/util/raf.d.ts +2 -0
- package/es/util/raf.js +24 -0
- package/es/util/raf.js.map +1 -0
- package/{types → es}/util/sampling.d.ts +4 -2
- package/es/util/sampling.js +66 -0
- package/es/util/sampling.js.map +1 -0
- package/es/util/theme.d.ts +4 -0
- package/es/util/theme.js +156 -0
- package/es/util/theme.js.map +1 -0
- package/es/util/uuid.d.ts +7 -0
- package/es/util/uuid.js +20 -0
- package/es/util/uuid.js.map +1 -0
- package/{types → es}/util/vector.d.ts +2 -2
- package/es/util/vector.js +97 -0
- package/es/util/vector.js.map +1 -0
- package/es/util/zIndex.js +5 -0
- package/es/util/zIndex.js.map +1 -0
- package/es/view/Anchor.d.ts +47 -0
- package/es/view/Anchor.js +315 -0
- package/es/view/Anchor.js.map +1 -0
- package/es/view/Control.d.ts +100 -0
- package/es/view/Control.js +324 -0
- package/es/view/Control.js.map +1 -0
- package/es/view/Graph.d.ts +18 -0
- package/es/view/Graph.js +77 -0
- package/es/view/Graph.js.map +1 -0
- package/{types → es}/view/Rotate.d.ts +9 -9
- package/es/view/Rotate.js +108 -0
- package/es/view/Rotate.js.map +1 -0
- package/es/view/behavior/dnd.d.ts +27 -0
- package/es/view/behavior/dnd.js +110 -0
- package/es/view/behavior/dnd.js.map +1 -0
- package/es/view/edge/AdjustPoint.d.ts +50 -0
- package/es/view/edge/AdjustPoint.js +368 -0
- package/es/view/edge/AdjustPoint.js.map +1 -0
- package/es/view/edge/Arrow.d.ts +25 -0
- package/es/view/edge/Arrow.js +60 -0
- package/es/view/edge/Arrow.js.map +1 -0
- package/{types → es}/view/edge/BaseEdge.d.ts +25 -17
- package/es/view/edge/BaseEdge.js +381 -0
- package/es/view/edge/BaseEdge.js.map +1 -0
- package/es/view/edge/BezierEdge.d.ts +26 -0
- package/es/view/edge/BezierEdge.js +118 -0
- package/es/view/edge/BezierEdge.js.map +1 -0
- package/{types → es}/view/edge/LineEdge.d.ts +9 -4
- package/es/view/edge/LineEdge.js +78 -0
- package/es/view/edge/LineEdge.js.map +1 -0
- package/{types → es}/view/edge/PolylineEdge.d.ts +18 -8
- package/es/view/edge/PolylineEdge.js +274 -0
- package/es/view/edge/PolylineEdge.js.map +1 -0
- package/es/view/edge/index.d.ts +6 -0
- package/es/view/edge/index.js +7 -0
- package/es/view/edge/index.js.map +1 -0
- package/es/view/index.d.ts +7 -0
- package/es/view/index.js +8 -0
- package/es/view/index.js.map +1 -0
- package/es/view/node/BaseNode.d.ts +49 -0
- package/es/view/node/BaseNode.js +420 -0
- package/es/view/node/BaseNode.js.map +1 -0
- package/es/view/node/CircleNode.d.ts +10 -0
- package/es/view/node/CircleNode.js +45 -0
- package/es/view/node/CircleNode.js.map +1 -0
- package/es/view/node/DiamondNode.d.ts +10 -0
- package/es/view/node/DiamondNode.js +44 -0
- package/es/view/node/DiamondNode.js.map +1 -0
- package/es/view/node/EllipseNode.d.ts +10 -0
- package/es/view/node/EllipseNode.js +44 -0
- package/es/view/node/EllipseNode.js.map +1 -0
- package/{types → es}/view/node/HtmlNode.d.ts +15 -9
- package/es/view/node/HtmlNode.js +129 -0
- package/es/view/node/HtmlNode.js.map +1 -0
- package/es/view/node/PolygonNode.d.ts +10 -0
- package/es/view/node/PolygonNode.js +48 -0
- package/es/view/node/PolygonNode.js.map +1 -0
- package/es/view/node/RectNode.d.ts +11 -0
- package/es/view/node/RectNode.js +44 -0
- package/es/view/node/RectNode.js.map +1 -0
- package/es/view/node/TextNode.d.ts +12 -0
- package/es/view/node/TextNode.js +55 -0
- package/es/view/node/TextNode.js.map +1 -0
- package/es/view/node/index.d.ts +8 -0
- package/es/view/node/index.js +9 -0
- package/es/view/node/index.js.map +1 -0
- package/{types → es}/view/overlay/BackgroundOverlay.d.ts +7 -7
- package/es/view/overlay/BackgroundOverlay.js +31 -0
- package/es/view/overlay/BackgroundOverlay.js.map +1 -0
- package/es/view/overlay/BezierAdjustOverlay.d.ts +31 -0
- package/es/view/overlay/BezierAdjustOverlay.js +142 -0
- package/es/view/overlay/BezierAdjustOverlay.js.map +1 -0
- package/{types → es}/view/overlay/CanvasOverlay.d.ts +8 -11
- package/es/view/overlay/CanvasOverlay.js +172 -0
- package/es/view/overlay/CanvasOverlay.js.map +1 -0
- package/es/view/overlay/Grid.d.ts +30 -0
- package/es/view/overlay/Grid.js +118 -0
- package/es/view/overlay/Grid.js.map +1 -0
- package/es/view/overlay/ModificationOverlay.d.ts +9 -0
- package/es/view/overlay/ModificationOverlay.js +43 -0
- package/es/view/overlay/ModificationOverlay.js.map +1 -0
- package/es/view/overlay/OutlineOverlay.d.ts +14 -0
- package/es/view/overlay/OutlineOverlay.js +134 -0
- package/es/view/overlay/OutlineOverlay.js.map +1 -0
- package/es/view/overlay/SnaplineOverlay.d.ts +10 -0
- package/es/view/overlay/SnaplineOverlay.js +60 -0
- package/es/view/overlay/SnaplineOverlay.js.map +1 -0
- package/es/view/overlay/ToolOverlay.d.ts +19 -0
- package/es/view/overlay/ToolOverlay.js +76 -0
- package/es/view/overlay/ToolOverlay.js.map +1 -0
- package/{types → es}/view/overlay/getTransformHoc.d.ts +17 -14
- package/es/view/overlay/getTransformHoc.js +57 -0
- package/es/view/overlay/getTransformHoc.js.map +1 -0
- package/es/view/overlay/index.d.ts +8 -0
- package/es/view/overlay/index.js +9 -0
- package/es/view/overlay/index.js.map +1 -0
- package/es/view/shape/Circle.d.ts +2 -0
- package/es/view/shape/Circle.js +57 -0
- package/es/view/shape/Circle.js.map +1 -0
- package/es/view/shape/Ellipse.d.ts +2 -0
- package/es/view/shape/Ellipse.js +58 -0
- package/es/view/shape/Ellipse.js.map +1 -0
- package/es/view/shape/Line.d.ts +2 -0
- package/es/view/shape/Line.js +54 -0
- package/es/view/shape/Line.js.map +1 -0
- package/es/view/shape/Path.d.ts +6 -0
- package/es/view/shape/Path.js +43 -0
- package/es/view/shape/Path.js.map +1 -0
- package/es/view/shape/Polygon.d.ts +8 -0
- package/es/view/shape/Polygon.js +56 -0
- package/es/view/shape/Polygon.js.map +1 -0
- package/es/view/shape/Polyline.d.ts +2 -0
- package/es/view/shape/Polyline.js +49 -0
- package/es/view/shape/Polyline.js.map +1 -0
- package/es/view/shape/Rect.d.ts +15 -0
- package/es/view/shape/Rect.js +60 -0
- package/es/view/shape/Rect.js.map +1 -0
- package/es/view/shape/Text.d.ts +2 -0
- package/es/view/shape/Text.js +110 -0
- package/es/view/shape/Text.js.map +1 -0
- package/es/view/shape/index.d.ts +8 -0
- package/es/view/shape/index.js +9 -0
- package/es/view/shape/index.js.map +1 -0
- package/es/view/text/BaseText.d.ts +25 -0
- package/es/view/text/BaseText.js +114 -0
- package/es/view/text/BaseText.js.map +1 -0
- package/es/view/text/LineText.d.ts +9 -0
- package/es/view/text/LineText.js +149 -0
- package/es/view/text/LineText.js.map +1 -0
- package/es/view/text/index.d.ts +2 -0
- package/es/view/text/index.js +3 -0
- package/es/view/text/index.js.map +1 -0
- package/lib/LogicFlow.d.ts +966 -0
- package/lib/LogicFlow.js +1203 -0
- package/lib/LogicFlow.js.map +1 -0
- package/lib/algorithm/edge.d.ts +15 -0
- package/lib/algorithm/edge.js +62 -0
- package/lib/algorithm/edge.js.map +1 -0
- package/lib/algorithm/index.d.ts +6 -0
- package/lib/algorithm/index.js +75 -0
- package/lib/algorithm/index.js.map +1 -0
- package/lib/algorithm/outline.d.ts +7 -0
- package/lib/algorithm/outline.js +69 -0
- package/lib/algorithm/outline.js.map +1 -0
- package/lib/constant/index.d.ts +102 -0
- package/lib/constant/index.js +120 -0
- package/lib/constant/index.js.map +1 -0
- package/lib/event/eventArgs.d.ts +428 -0
- package/lib/event/eventArgs.js +3 -0
- package/lib/event/eventArgs.js.map +1 -0
- package/lib/event/eventEmitter.d.ts +48 -0
- package/lib/event/eventEmitter.js +95 -0
- package/lib/event/eventEmitter.js.map +1 -0
- package/lib/history/index.d.ts +23 -0
- package/lib/history/index.js +114 -0
- package/lib/history/index.js.map +1 -0
- package/lib/index.css +210 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +58 -0
- package/lib/index.js.map +1 -0
- package/lib/index.less +1 -0
- package/lib/keyboard/index.d.ts +31 -0
- package/lib/keyboard/index.js +93 -0
- package/lib/keyboard/index.js.map +1 -0
- package/lib/keyboard/shortcut.d.ts +3 -0
- package/lib/keyboard/shortcut.js +120 -0
- package/lib/keyboard/shortcut.js.map +1 -0
- package/lib/model/BaseModel.d.ts +181 -0
- package/lib/model/BaseModel.js +3 -0
- package/lib/model/BaseModel.js.map +1 -0
- package/lib/model/EditConfigModel.d.ts +114 -0
- package/lib/model/EditConfigModel.js +195 -0
- package/lib/model/EditConfigModel.js.map +1 -0
- package/lib/model/GraphModel.d.ts +426 -0
- package/lib/model/GraphModel.js +1479 -0
- package/lib/model/GraphModel.js.map +1 -0
- package/lib/model/SnaplineModel.d.ts +34 -0
- package/lib/model/SnaplineModel.js +220 -0
- package/lib/model/SnaplineModel.js.map +1 -0
- package/lib/model/TransformModel.d.ts +101 -0
- package/lib/model/TransformModel.js +243 -0
- package/lib/model/TransformModel.js.map +1 -0
- package/lib/model/edge/BaseEdgeModel.d.ts +270 -0
- package/lib/model/edge/BaseEdgeModel.js +742 -0
- package/lib/model/edge/BaseEdgeModel.js.map +1 -0
- package/lib/model/edge/BezierEdgeModel.d.ts +63 -0
- package/lib/model/edge/BezierEdgeModel.js +250 -0
- package/lib/model/edge/BezierEdgeModel.js.map +1 -0
- package/lib/model/edge/LineEdgeModel.d.ts +19 -0
- package/lib/model/edge/LineEdgeModel.js +83 -0
- package/lib/model/edge/LineEdgeModel.js.map +1 -0
- package/lib/model/edge/PolylineEdgeModel.d.ts +85 -0
- package/lib/model/edge/PolylineEdgeModel.js +596 -0
- package/lib/model/edge/PolylineEdgeModel.js.map +1 -0
- package/lib/model/edge/index.d.ts +4 -0
- package/lib/model/edge/index.js +21 -0
- package/lib/model/edge/index.js.map +1 -0
- package/lib/model/index.d.ts +7 -0
- package/lib/model/index.js +24 -0
- package/lib/model/index.js.map +1 -0
- package/lib/model/node/BaseNodeModel.d.ts +260 -0
- package/lib/model/node/BaseNodeModel.js +886 -0
- package/lib/model/node/BaseNodeModel.js.map +1 -0
- package/lib/model/node/CircleNodeModel.d.ts +40 -0
- package/lib/model/node/CircleNodeModel.js +116 -0
- package/lib/model/node/CircleNodeModel.js.map +1 -0
- package/lib/model/node/DiamondNodeModel.d.ts +46 -0
- package/lib/model/node/DiamondNodeModel.js +193 -0
- package/lib/model/node/DiamondNodeModel.js.map +1 -0
- package/lib/model/node/EllipseNodeModel.d.ts +42 -0
- package/lib/model/node/EllipseNodeModel.js +124 -0
- package/lib/model/node/EllipseNodeModel.js.map +1 -0
- package/lib/model/node/HtmlNodeModel.d.ts +21 -0
- package/lib/model/node/HtmlNodeModel.js +65 -0
- package/lib/model/node/HtmlNodeModel.js.map +1 -0
- package/lib/model/node/PolygonNodeModel.d.ts +50 -0
- package/lib/model/node/PolygonNodeModel.js +202 -0
- package/lib/model/node/PolygonNodeModel.js.map +1 -0
- package/lib/model/node/RectNodeModel.d.ts +34 -0
- package/lib/model/node/RectNodeModel.js +86 -0
- package/lib/model/node/RectNodeModel.js.map +1 -0
- package/lib/model/node/TextNodeModel.d.ts +27 -0
- package/lib/model/node/TextNodeModel.js +119 -0
- package/lib/model/node/TextNodeModel.js.map +1 -0
- package/lib/model/node/index.d.ts +8 -0
- package/lib/model/node/index.js +25 -0
- package/lib/model/node/index.js.map +1 -0
- package/lib/options.d.ts +86 -0
- package/lib/options.js +77 -0
- package/lib/options.js.map +1 -0
- package/lib/style/index.css +210 -0
- package/lib/style/index.less +256 -0
- package/lib/style/raw.d.ts +4 -0
- package/lib/style/raw.js +9 -0
- package/lib/style/raw.js.map +1 -0
- package/lib/tool/MultipleSelectTool.d.ts +13 -0
- package/lib/tool/MultipleSelectTool.js +161 -0
- package/lib/tool/MultipleSelectTool.js.map +1 -0
- package/lib/tool/TextEditTool.d.ts +26 -0
- package/lib/tool/TextEditTool.js +190 -0
- package/lib/tool/TextEditTool.js.map +1 -0
- package/lib/tool/index.d.ts +2 -0
- package/lib/tool/index.js +19 -0
- package/lib/tool/index.js.map +1 -0
- package/lib/tool/snapline.d.ts +3 -0
- package/lib/tool/snapline.js +17 -0
- package/lib/tool/snapline.js.map +1 -0
- package/lib/tool/tool.d.ts +22 -0
- package/lib/tool/tool.js +49 -0
- package/lib/tool/tool.js.map +1 -0
- package/lib/util/animation.d.ts +12 -0
- package/lib/util/animation.js +24 -0
- package/lib/util/animation.js.map +1 -0
- package/lib/util/browser.d.ts +1 -0
- package/lib/util/browser.js +6 -0
- package/lib/util/browser.js.map +1 -0
- package/lib/util/compatible.d.ts +6 -0
- package/lib/util/compatible.js +21 -0
- package/lib/util/compatible.js.map +1 -0
- package/lib/util/drag.d.ts +47 -0
- package/lib/util/drag.js +142 -0
- package/lib/util/drag.js.map +1 -0
- package/lib/util/edge.d.ts +94 -0
- package/lib/util/edge.js +879 -0
- package/lib/util/edge.js.map +1 -0
- package/lib/util/geometry.d.ts +11 -0
- package/lib/util/geometry.js +78 -0
- package/lib/util/geometry.js.map +1 -0
- package/lib/util/graph.d.ts +13 -0
- package/lib/util/graph.js +59 -0
- package/lib/util/graph.js.map +1 -0
- package/lib/util/index.d.ts +16 -0
- package/lib/util/index.js +33 -0
- package/lib/util/index.js.map +1 -0
- package/lib/util/matrix.d.ts +32 -0
- package/lib/util/matrix.js +164 -0
- package/lib/util/matrix.js.map +1 -0
- package/lib/util/mobx.d.ts +2 -0
- package/lib/util/mobx.js +13 -0
- package/lib/util/mobx.js.map +1 -0
- package/lib/util/node.d.ts +69 -0
- package/lib/util/node.js +424 -0
- package/lib/util/node.js.map +1 -0
- package/lib/util/raf.d.ts +2 -0
- package/lib/util/raf.js +29 -0
- package/lib/util/raf.js.map +1 -0
- package/lib/util/sampling.d.ts +6 -0
- package/lib/util/sampling.js +72 -0
- package/lib/util/sampling.js.map +1 -0
- package/lib/util/theme.d.ts +4 -0
- package/lib/util/theme.js +160 -0
- package/lib/util/theme.js.map +1 -0
- package/lib/util/uuid.d.ts +7 -0
- package/lib/util/uuid.js +25 -0
- package/lib/util/uuid.js.map +1 -0
- package/lib/util/vector.d.ts +23 -0
- package/lib/util/vector.js +101 -0
- package/lib/util/vector.js.map +1 -0
- package/lib/util/zIndex.d.ts +2 -0
- package/lib/util/zIndex.js +10 -0
- package/lib/util/zIndex.js.map +1 -0
- package/lib/view/Anchor.d.ts +47 -0
- package/lib/view/Anchor.js +317 -0
- package/lib/view/Anchor.js.map +1 -0
- package/lib/view/Control.d.ts +100 -0
- package/lib/view/Control.js +327 -0
- package/lib/view/Control.js.map +1 -0
- package/lib/view/Graph.d.ts +18 -0
- package/lib/view/Graph.js +79 -0
- package/lib/view/Graph.js.map +1 -0
- package/lib/view/Rotate.d.ts +21 -0
- package/lib/view/Rotate.js +113 -0
- package/lib/view/Rotate.js.map +1 -0
- package/lib/view/behavior/dnd.d.ts +27 -0
- package/lib/view/behavior/dnd.js +113 -0
- package/lib/view/behavior/dnd.js.map +1 -0
- package/lib/view/edge/AdjustPoint.d.ts +50 -0
- package/lib/view/edge/AdjustPoint.js +371 -0
- package/lib/view/edge/AdjustPoint.js.map +1 -0
- package/lib/view/edge/Arrow.d.ts +25 -0
- package/lib/view/edge/Arrow.js +63 -0
- package/lib/view/edge/Arrow.js.map +1 -0
- package/lib/view/edge/BaseEdge.d.ts +148 -0
- package/lib/view/edge/BaseEdge.js +407 -0
- package/lib/view/edge/BaseEdge.js.map +1 -0
- package/lib/view/edge/BezierEdge.d.ts +26 -0
- package/lib/view/edge/BezierEdge.js +124 -0
- package/lib/view/edge/BezierEdge.js.map +1 -0
- package/{types/view/edge/BezierEdge.d.ts → lib/view/edge/LineEdge.d.ts} +9 -10
- package/lib/view/edge/LineEdge.js +84 -0
- package/lib/view/edge/LineEdge.js.map +1 -0
- package/lib/view/edge/PolylineEdge.d.ts +55 -0
- package/lib/view/edge/PolylineEdge.js +280 -0
- package/lib/view/edge/PolylineEdge.js.map +1 -0
- package/lib/view/edge/index.d.ts +6 -0
- package/lib/view/edge/index.js +23 -0
- package/lib/view/edge/index.js.map +1 -0
- package/lib/view/index.d.ts +7 -0
- package/lib/view/index.js +24 -0
- package/lib/view/index.js.map +1 -0
- package/lib/view/node/BaseNode.d.ts +49 -0
- package/lib/view/node/BaseNode.js +424 -0
- package/lib/view/node/BaseNode.js.map +1 -0
- package/lib/view/node/CircleNode.d.ts +10 -0
- package/lib/view/node/CircleNode.js +51 -0
- package/lib/view/node/CircleNode.js.map +1 -0
- package/lib/view/node/DiamondNode.d.ts +10 -0
- package/lib/view/node/DiamondNode.js +50 -0
- package/lib/view/node/DiamondNode.js.map +1 -0
- package/lib/view/node/EllipseNode.d.ts +10 -0
- package/lib/view/node/EllipseNode.js +50 -0
- package/lib/view/node/EllipseNode.js.map +1 -0
- package/lib/view/node/HtmlNode.d.ts +38 -0
- package/lib/view/node/HtmlNode.js +135 -0
- package/lib/view/node/HtmlNode.js.map +1 -0
- package/lib/view/node/PolygonNode.d.ts +10 -0
- package/lib/view/node/PolygonNode.js +54 -0
- package/lib/view/node/PolygonNode.js.map +1 -0
- package/lib/view/node/RectNode.d.ts +11 -0
- package/lib/view/node/RectNode.js +50 -0
- package/lib/view/node/RectNode.js.map +1 -0
- package/lib/view/node/TextNode.d.ts +12 -0
- package/lib/view/node/TextNode.js +61 -0
- package/lib/view/node/TextNode.js.map +1 -0
- package/lib/view/node/index.d.ts +8 -0
- package/lib/view/node/index.js +25 -0
- package/lib/view/node/index.js.map +1 -0
- package/lib/view/overlay/BackgroundOverlay.d.ts +28 -0
- package/lib/view/overlay/BackgroundOverlay.js +34 -0
- package/lib/view/overlay/BackgroundOverlay.js.map +1 -0
- package/lib/view/overlay/BezierAdjustOverlay.d.ts +31 -0
- package/lib/view/overlay/BezierAdjustOverlay.js +145 -0
- package/lib/view/overlay/BezierAdjustOverlay.js.map +1 -0
- package/lib/view/overlay/CanvasOverlay.d.ts +25 -0
- package/lib/view/overlay/CanvasOverlay.js +175 -0
- package/lib/view/overlay/CanvasOverlay.js.map +1 -0
- package/lib/view/overlay/Grid.d.ts +30 -0
- package/lib/view/overlay/Grid.js +121 -0
- package/lib/view/overlay/Grid.js.map +1 -0
- package/lib/view/overlay/ModificationOverlay.d.ts +9 -0
- package/lib/view/overlay/ModificationOverlay.js +46 -0
- package/lib/view/overlay/ModificationOverlay.js.map +1 -0
- package/lib/view/overlay/OutlineOverlay.d.ts +14 -0
- package/lib/view/overlay/OutlineOverlay.js +137 -0
- package/lib/view/overlay/OutlineOverlay.js.map +1 -0
- package/lib/view/overlay/SnaplineOverlay.d.ts +10 -0
- package/lib/view/overlay/SnaplineOverlay.js +66 -0
- package/lib/view/overlay/SnaplineOverlay.js.map +1 -0
- package/lib/view/overlay/ToolOverlay.d.ts +19 -0
- package/lib/view/overlay/ToolOverlay.js +79 -0
- package/lib/view/overlay/ToolOverlay.js.map +1 -0
- package/lib/view/overlay/getTransformHoc.d.ts +37 -0
- package/lib/view/overlay/getTransformHoc.js +61 -0
- package/lib/view/overlay/getTransformHoc.js.map +1 -0
- package/lib/view/overlay/index.d.ts +8 -0
- package/lib/view/overlay/index.js +25 -0
- package/lib/view/overlay/index.js.map +1 -0
- package/lib/view/shape/Circle.d.ts +2 -0
- package/lib/view/shape/Circle.js +61 -0
- package/lib/view/shape/Circle.js.map +1 -0
- package/lib/view/shape/Ellipse.d.ts +2 -0
- package/lib/view/shape/Ellipse.js +62 -0
- package/lib/view/shape/Ellipse.js.map +1 -0
- package/lib/view/shape/Line.d.ts +2 -0
- package/lib/view/shape/Line.js +58 -0
- package/lib/view/shape/Line.js.map +1 -0
- package/lib/view/shape/Path.d.ts +6 -0
- package/lib/view/shape/Path.js +47 -0
- package/lib/view/shape/Path.js.map +1 -0
- package/lib/view/shape/Polygon.d.ts +8 -0
- package/lib/view/shape/Polygon.js +60 -0
- package/lib/view/shape/Polygon.js.map +1 -0
- package/lib/view/shape/Polyline.d.ts +2 -0
- package/lib/view/shape/Polyline.js +53 -0
- package/lib/view/shape/Polyline.js.map +1 -0
- package/lib/view/shape/Rect.d.ts +15 -0
- package/lib/view/shape/Rect.js +64 -0
- package/lib/view/shape/Rect.js.map +1 -0
- package/lib/view/shape/Text.d.ts +2 -0
- package/lib/view/shape/Text.js +114 -0
- package/lib/view/shape/Text.js.map +1 -0
- package/lib/view/shape/index.d.ts +8 -0
- package/lib/view/shape/index.js +25 -0
- package/lib/view/shape/index.js.map +1 -0
- package/lib/view/text/BaseText.d.ts +25 -0
- package/lib/view/text/BaseText.js +117 -0
- package/lib/view/text/BaseText.js.map +1 -0
- package/lib/view/text/LineText.d.ts +9 -0
- package/lib/view/text/LineText.js +155 -0
- package/lib/view/text/LineText.js.map +1 -0
- package/lib/view/text/index.d.ts +2 -0
- package/lib/view/text/index.js +19 -0
- package/lib/view/text/index.js.map +1 -0
- package/package.json +41 -88
- package/rollup.config.js +15 -0
- package/src/LogicFlow.tsx +1831 -0
- package/src/algorithm/edge.ts +68 -0
- package/src/algorithm/index.ts +68 -0
- package/src/algorithm/outline.ts +77 -0
- package/src/constant/index.ts +127 -0
- package/src/event/event.md +66 -0
- package/src/event/eventArgs.ts +476 -0
- package/src/event/eventEmitter.ts +153 -0
- package/src/history/index.ts +112 -0
- package/src/index.less +1 -0
- package/src/index.ts +21 -0
- package/src/keyboard/index.ts +106 -0
- package/src/keyboard/shortcut.ts +123 -0
- package/src/model/BaseModel.ts +223 -0
- package/src/model/EditConfigModel.ts +215 -0
- package/src/model/GraphModel.ts +1516 -0
- package/src/model/SnaplineModel.ts +238 -0
- package/src/model/TransformModel.ts +258 -0
- package/src/model/edge/BaseEdgeModel.ts +688 -0
- package/src/model/edge/BezierEdgeModel.ts +196 -0
- package/src/model/edge/LineEdgeModel.ts +26 -0
- package/src/model/edge/PolylineEdgeModel.ts +656 -0
- package/src/model/edge/index.ts +4 -0
- package/src/model/index.ts +8 -0
- package/src/model/node/BaseNodeModel.ts +839 -0
- package/src/model/node/CircleNodeModel.ts +89 -0
- package/src/model/node/DiamondNodeModel.ts +128 -0
- package/src/model/node/EllipseNodeModel.ts +94 -0
- package/src/model/node/HtmlNodeModel.ts +49 -0
- package/src/model/node/PolygonNodeModel.ts +147 -0
- package/src/model/node/RectNodeModel.ts +57 -0
- package/src/model/node/TextNodeModel.ts +41 -0
- package/src/model/node/index.ts +8 -0
- package/src/options.ts +173 -0
- package/src/style/index.less +256 -0
- package/src/style/raw.ts +217 -0
- package/src/tool/MultipleSelectTool.tsx +132 -0
- package/src/tool/TextEditTool.tsx +193 -0
- package/src/tool/index.ts +2 -0
- package/src/tool/snapline.ts +17 -0
- package/src/tool/tool.ts +66 -0
- package/src/typings.d.ts +5 -0
- package/src/util/animation.ts +29 -0
- package/src/util/browser.ts +4 -0
- package/src/util/compatible.ts +15 -0
- package/src/util/drag.ts +186 -0
- package/src/util/edge.ts +1034 -0
- package/src/util/geometry.ts +53 -0
- package/src/util/graph.ts +46 -0
- package/src/util/index.ts +16 -0
- package/src/util/matrix.ts +129 -0
- package/src/util/mobx.ts +23 -0
- package/src/util/node.ts +519 -0
- package/src/util/raf.ts +28 -0
- package/src/util/sampling.ts +85 -0
- package/src/util/theme.ts +180 -0
- package/src/util/uuid.ts +26 -0
- package/src/util/vector.ts +93 -0
- package/src/util/zIndex.ts +6 -0
- package/src/view/Anchor.tsx +407 -0
- package/src/view/Control.tsx +446 -0
- package/src/view/Graph.tsx +104 -0
- package/src/view/Rotate.tsx +112 -0
- package/src/view/behavior/dnd.ts +116 -0
- package/src/view/edge/AdjustPoint.tsx +439 -0
- package/src/view/edge/Arrow.tsx +54 -0
- package/src/view/edge/BaseEdge.tsx +489 -0
- package/src/view/edge/BezierEdge.tsx +101 -0
- package/src/view/edge/LineEdge.tsx +81 -0
- package/src/view/edge/PolylineEdge.tsx +299 -0
- package/src/view/edge/index.ts +6 -0
- package/src/view/index.ts +8 -0
- package/src/view/node/BaseNode.tsx +494 -0
- package/src/view/node/CircleNode.tsx +19 -0
- package/src/view/node/DiamondNode.tsx +22 -0
- package/src/view/node/EllipseNode.tsx +20 -0
- package/src/view/node/HtmlNode.tsx +92 -0
- package/src/view/node/PolygonNode.tsx +26 -0
- package/src/view/node/RectNode.tsx +28 -0
- package/src/view/node/TextNode.tsx +37 -0
- package/src/view/node/index.ts +8 -0
- package/src/view/overlay/BackgroundOverlay.tsx +39 -0
- package/src/view/overlay/BezierAdjustOverlay.tsx +150 -0
- package/src/view/overlay/CanvasOverlay.tsx +180 -0
- package/src/view/overlay/Grid.tsx +135 -0
- package/src/view/overlay/ModificationOverlay.tsx +31 -0
- package/src/view/overlay/OutlineOverlay.tsx +170 -0
- package/src/view/overlay/SnaplineOverlay.tsx +44 -0
- package/src/view/overlay/ToolOverlay.tsx +65 -0
- package/src/view/overlay/getTransformHoc.tsx +50 -0
- package/src/view/overlay/index.ts +8 -0
- package/src/view/shape/Circle.tsx +27 -0
- package/src/view/shape/Ellipse.tsx +28 -0
- package/src/view/shape/Line.tsx +24 -0
- package/src/view/shape/Path.tsx +19 -0
- package/src/view/shape/Polygon.tsx +36 -0
- package/src/view/shape/Polyline.tsx +19 -0
- package/src/view/shape/Rect.tsx +44 -0
- package/src/view/shape/Text.tsx +138 -0
- package/src/view/shape/index.ts +8 -0
- package/src/view/text/BaseText.tsx +96 -0
- package/src/view/text/LineText.tsx +154 -0
- package/src/view/text/index.ts +2 -0
- package/tsconfig.json +18 -0
- package/dist/entry.js +0 -7
- package/dist/logic-flow.js +0 -23
- package/dist/logic-flow.min.js +0 -23
- package/types/LogicFlow.d.ts +0 -581
- package/types/algorithm/edge.d.ts +0 -6
- package/types/algorithm/outline.d.ts +0 -35
- package/types/constant/DefaultAnimation.d.ts +0 -12
- package/types/constant/DefaultTheme.d.ts +0 -270
- package/types/event/eventEmitter.d.ts +0 -36
- package/types/history/History.d.ts +0 -20
- package/types/model/BaseModel.d.ts +0 -99
- package/types/model/SnaplineModel.d.ts +0 -33
- package/types/model/edge/BezierEdgeModel.d.ts +0 -51
- package/types/model/edge/LineEdgeModel.d.ts +0 -14
- package/types/model/edge/PolylineEdgeModel.d.ts +0 -63
- package/types/model/node/BaseNodeModel.d.ts +0 -232
- package/types/model/node/CircleNodeModel.d.ts +0 -21
- package/types/model/node/DiamondNodeModel.d.ts +0 -25
- package/types/model/node/EllipseNodeModel.d.ts +0 -22
- package/types/model/node/HtmlNodeModel.d.ts +0 -12
- package/types/model/node/PolygonNodeModel.d.ts +0 -28
- package/types/model/node/RectNodeModel.d.ts +0 -19
- package/types/model/node/TextNodeModel.d.ts +0 -19
- package/types/options.d.ts +0 -240
- package/types/tool/MultipleSelectTool.d.ts +0 -20
- package/types/tool/TextEditTool.d.ts +0 -34
- package/types/tool/index.d.ts +0 -13
- package/types/type/index.d.ts +0 -429
- package/types/util/animation.d.ts +0 -2
- package/types/util/compatible.d.ts +0 -1
- package/types/util/drag.d.ts +0 -38
- package/types/util/edge.d.ts +0 -108
- package/types/util/geometry.d.ts +0 -2
- package/types/util/index.d.ts +0 -7
- package/types/util/node.d.ts +0 -66
- package/types/util/raf.d.ts +0 -2
- package/types/util/theme.d.ts +0 -2
- package/types/util/uuid.d.ts +0 -6
- package/types/view/Anchor.d.ts +0 -54
- package/types/view/Graph.d.ts +0 -21
- package/types/view/basic-shape/Circle.d.ts +0 -2
- package/types/view/basic-shape/Ellipse.d.ts +0 -2
- package/types/view/basic-shape/Line.d.ts +0 -3
- package/types/view/basic-shape/LinearGradient.d.ts +0 -1
- package/types/view/basic-shape/Path.d.ts +0 -7
- package/types/view/basic-shape/Polygon.d.ts +0 -2
- package/types/view/basic-shape/Polyline.d.ts +0 -3
- package/types/view/basic-shape/Rect.d.ts +0 -14
- package/types/view/basic-shape/Text.d.ts +0 -2
- package/types/view/behavior/DnD.d.ts +0 -35
- package/types/view/behavior/Transform.d.ts +0 -4
- package/types/view/edge/AdjustPoint.d.ts +0 -56
- package/types/view/edge/Arrow.d.ts +0 -24
- package/types/view/edge/index.d.ts +0 -6
- package/types/view/index.d.ts +0 -2
- package/types/view/node/BaseNode.d.ts +0 -57
- package/types/view/node/CircleNode.d.ts +0 -5
- package/types/view/node/DiamondNode.d.ts +0 -5
- package/types/view/node/EllipseNode.d.ts +0 -5
- package/types/view/node/PolygonNode.d.ts +0 -5
- package/types/view/node/RectNode.d.ts +0 -5
- package/types/view/node/TextNode.d.ts +0 -6
- package/types/view/node/index.d.ts +0 -9
- package/types/view/overlay/BezierAdjustOverlay.d.ts +0 -12
- package/types/view/overlay/Grid.d.ts +0 -30
- package/types/view/overlay/HtmlOverlay.d.ts +0 -15
- package/types/view/overlay/ModificationOverlay.d.ts +0 -9
- package/types/view/overlay/OutlineOverlay.d.ts +0 -17
- package/types/view/overlay/SnaplineOverlay.d.ts +0 -9
- package/types/view/overlay/ToolOverlay.d.ts +0 -17
- package/types/view/text/BaseText.d.ts +0 -29
- package/types/view/text/LineText.d.ts +0 -9
- /package/{types → es}/algorithm/index.d.ts +0 -0
- /package/{types → es}/keyboard/shortcut.d.ts +0 -0
- /package/{types → es}/model/edge/index.d.ts +0 -0
- /package/{types → es}/model/index.d.ts +0 -0
- /package/{types → es}/model/node/index.d.ts +0 -0
- /package/{types → es}/util/browser.d.ts +0 -0
- /package/{types → es}/util/mobx.d.ts +0 -0
- /package/{types → es}/util/zIndex.d.ts +0 -0
|
@@ -0,0 +1,1831 @@
|
|
|
1
|
+
import { ComponentType, createElement as h, render } from 'preact/compat'
|
|
2
|
+
import { cloneDeep, forEach } from 'lodash-es'
|
|
3
|
+
import { observer } from '.'
|
|
4
|
+
import { Options as LFOptions } from './options'
|
|
5
|
+
import * as _Model from './model'
|
|
6
|
+
import {
|
|
7
|
+
BaseEdgeModel,
|
|
8
|
+
BaseNodeModel,
|
|
9
|
+
EditConfigInterface,
|
|
10
|
+
GraphModel,
|
|
11
|
+
SnaplineModel,
|
|
12
|
+
ZoomParamType,
|
|
13
|
+
} from './model'
|
|
14
|
+
|
|
15
|
+
import Graph from './view/Graph'
|
|
16
|
+
import * as _View from './view'
|
|
17
|
+
import { formatData } from './util'
|
|
18
|
+
|
|
19
|
+
import Dnd from './view/behavior/dnd'
|
|
20
|
+
import Tool from './tool/tool'
|
|
21
|
+
import { snapline } from './tool'
|
|
22
|
+
import Keyboard from './keyboard'
|
|
23
|
+
import History from './history'
|
|
24
|
+
import { EventCallback, CallbackArgs, EventArgs } from './event/eventEmitter'
|
|
25
|
+
import { ElementType, EventType, SegmentDirection } from './constant'
|
|
26
|
+
import { initDefaultShortcut } from './keyboard/shortcut'
|
|
27
|
+
import Extension = LogicFlow.Extension
|
|
28
|
+
import RegisteredExtension = LogicFlow.RegisteredExtension
|
|
29
|
+
import ExtensionConstructor = LogicFlow.ExtensionConstructor
|
|
30
|
+
import GraphConfigData = LogicFlow.GraphConfigData
|
|
31
|
+
import NodeConfig = LogicFlow.NodeConfig
|
|
32
|
+
import EdgeConfig = LogicFlow.EdgeConfig
|
|
33
|
+
import GraphData = LogicFlow.GraphData
|
|
34
|
+
import NodeData = LogicFlow.NodeData
|
|
35
|
+
import EdgeData = LogicFlow.EdgeData
|
|
36
|
+
import RegisterConfig = LogicFlow.RegisterConfig
|
|
37
|
+
import RegisterParam = LogicFlow.RegisterParam
|
|
38
|
+
import GraphElements = LogicFlow.GraphElements
|
|
39
|
+
import Position = LogicFlow.Position
|
|
40
|
+
import PointTuple = LogicFlow.PointTuple
|
|
41
|
+
import ExtensionRender = LogicFlow.ExtensionRender
|
|
42
|
+
import RegisterElementFunc = LogicFlow.RegisterElementFunc
|
|
43
|
+
import PropertiesType = LogicFlow.PropertiesType
|
|
44
|
+
import BaseNodeModelCtor = LogicFlow.BaseNodeModelCtor
|
|
45
|
+
import ClientPosition = LogicFlow.ClientPosition
|
|
46
|
+
|
|
47
|
+
const pluginFlag = Symbol('plugin registered by Logicflow.use')
|
|
48
|
+
|
|
49
|
+
export class LogicFlow {
|
|
50
|
+
// 只读:logicflow实例挂载的容器。
|
|
51
|
+
readonly container: HTMLElement
|
|
52
|
+
// 只读:logicflow实例的配置
|
|
53
|
+
readonly options: LFOptions.Definition
|
|
54
|
+
// 只读:控制整个 LogicFlow 画布的model
|
|
55
|
+
readonly graphModel: GraphModel
|
|
56
|
+
|
|
57
|
+
viewMap: Map<string, ComponentType> = new Map()
|
|
58
|
+
history: History
|
|
59
|
+
keyboard: Keyboard
|
|
60
|
+
dnd: Dnd
|
|
61
|
+
tool: Tool
|
|
62
|
+
snaplineModel?: SnaplineModel
|
|
63
|
+
|
|
64
|
+
components: ExtensionRender[] = []
|
|
65
|
+
// 个性配置的插件,覆盖全局配置的插件
|
|
66
|
+
readonly plugins: ExtensionConstructor[]
|
|
67
|
+
// 全局配置的插件,所有的LogicFlow示例都会使用
|
|
68
|
+
static extensions: Map<string, RegisteredExtension> = new Map()
|
|
69
|
+
// 插件扩展方法
|
|
70
|
+
extension: Record<string, Extension> = {}
|
|
71
|
+
|
|
72
|
+
readonly width?: number // 只读:画布宽度
|
|
73
|
+
readonly height?: number // 只读:画布高度
|
|
74
|
+
/**
|
|
75
|
+
* 自定义数据转换方法
|
|
76
|
+
* 当接入系统格式和 LogicFlow 数据格式不一致时,可自定义此方法来进行数据格式转换
|
|
77
|
+
* 详情请参考 adapter docs
|
|
78
|
+
* 包括 adapterIn 和 adapterOut 两个方法
|
|
79
|
+
*/
|
|
80
|
+
// TODO: 如何让用户执行时定义下面方法参数和返回值的类型
|
|
81
|
+
private adapterIn?: (data: unknown) => GraphData
|
|
82
|
+
private adapterOut?: (data: GraphData, ...rest: any) => unknown;
|
|
83
|
+
|
|
84
|
+
// 支持插件在 LogicFlow 实例上增加自定义方法
|
|
85
|
+
[propName: string]: any
|
|
86
|
+
|
|
87
|
+
private initContainer(container: HTMLElement | HTMLDivElement) {
|
|
88
|
+
// TODO: 确认是否需要,后续是否只要返回 container 即可(下面方法是为了解决事件绑定问题的)
|
|
89
|
+
// fix: destroy keyboard events while destroy LogicFlow.(#1110)
|
|
90
|
+
const lfContainer = document.createElement('div')
|
|
91
|
+
lfContainer.style.position = 'relative'
|
|
92
|
+
lfContainer.style.width = '100%'
|
|
93
|
+
lfContainer.style.height = '100%'
|
|
94
|
+
container.innerHTML = ''
|
|
95
|
+
container.appendChild(lfContainer)
|
|
96
|
+
return lfContainer
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected get [Symbol.toStringTag]() {
|
|
100
|
+
return LogicFlow.toStringTag
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
constructor(options: LFOptions.Common) {
|
|
104
|
+
const initOptions = LFOptions.get(options)
|
|
105
|
+
this.options = initOptions
|
|
106
|
+
this.container = this.initContainer(initOptions.container)
|
|
107
|
+
this.graphModel = new GraphModel({
|
|
108
|
+
...initOptions,
|
|
109
|
+
container: this.container, // TODO:测试该部分是否会有问题
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
this.plugins = initOptions.plugins ?? []
|
|
113
|
+
|
|
114
|
+
const { eventCenter } = this.graphModel
|
|
115
|
+
this.tool = new Tool(this)
|
|
116
|
+
this.dnd = new Dnd({ lf: this })
|
|
117
|
+
this.history = new History(eventCenter)
|
|
118
|
+
this.keyboard = new Keyboard({
|
|
119
|
+
lf: this,
|
|
120
|
+
keyboard: initOptions.keyboard,
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
if (initOptions.snapline !== false) {
|
|
124
|
+
this.snaplineModel = new SnaplineModel(this.graphModel)
|
|
125
|
+
snapline(eventCenter, this.snaplineModel)
|
|
126
|
+
}
|
|
127
|
+
if (!initOptions.isSilentMode) {
|
|
128
|
+
// 先初始化默认内置快捷键,自定义快捷键可以覆盖默认快捷键
|
|
129
|
+
initDefaultShortcut(this, this.graphModel)
|
|
130
|
+
// 然后再初始化自定义快捷键,自定义快捷键可以覆盖默认快捷键.
|
|
131
|
+
// 插件最后初始化。方便插件强制覆盖内置快捷键
|
|
132
|
+
this.keyboard.initShortcuts()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.defaultRegister()
|
|
136
|
+
this.installPlugins(initOptions.disabledPlugins)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/*********************************************************
|
|
140
|
+
* Register 相关
|
|
141
|
+
********************************************************/
|
|
142
|
+
private setView = (type: string, component: ComponentType) =>
|
|
143
|
+
this.viewMap.set(type, component)
|
|
144
|
+
// 根据 type 获取对应的 view
|
|
145
|
+
private getView = (type: string): ComponentType | undefined =>
|
|
146
|
+
this.viewMap.get(type)
|
|
147
|
+
|
|
148
|
+
// register 方法重载
|
|
149
|
+
register(element: RegisterConfig): void
|
|
150
|
+
register(
|
|
151
|
+
type: string,
|
|
152
|
+
fn: RegisterElementFunc,
|
|
153
|
+
isObserverView?: boolean,
|
|
154
|
+
): void
|
|
155
|
+
/**
|
|
156
|
+
* 注册自定义节点和边
|
|
157
|
+
* 支持两种方式
|
|
158
|
+
* 方式一(推荐)
|
|
159
|
+
* 详情见 todo: docs link
|
|
160
|
+
* @example
|
|
161
|
+
* import { RectNode, RectModel } from '@logicflow/core'
|
|
162
|
+
* class CustomView extends RectNode {
|
|
163
|
+
* }
|
|
164
|
+
* class CustomModel extends RectModel {
|
|
165
|
+
* }
|
|
166
|
+
* lf.register({
|
|
167
|
+
* type: 'custom',
|
|
168
|
+
* view: CustomView,
|
|
169
|
+
* model: CustomModel
|
|
170
|
+
* })
|
|
171
|
+
* 方式二
|
|
172
|
+
* 不推荐,极个别在自定义的时候需要用到lf的情况下可以用这种方式。
|
|
173
|
+
* 大多数情况下,我们可以直接在view中从this.props中获取graphModel
|
|
174
|
+
* 或者model中直接this.graphModel获取model的方法。
|
|
175
|
+
* @example
|
|
176
|
+
* lf.register('custom', ({ RectNode, RectModel }) => {
|
|
177
|
+
* class CustomView extends RectNode {}
|
|
178
|
+
* class CustomModel extends RectModel {}
|
|
179
|
+
* return {
|
|
180
|
+
* view: CustomView,
|
|
181
|
+
* model: CustomModel
|
|
182
|
+
* }
|
|
183
|
+
* })
|
|
184
|
+
*/
|
|
185
|
+
register(
|
|
186
|
+
element: string | RegisterConfig,
|
|
187
|
+
fn?: RegisterElementFunc,
|
|
188
|
+
isObserverView = true,
|
|
189
|
+
) {
|
|
190
|
+
// 方式1
|
|
191
|
+
if (typeof element !== 'string') {
|
|
192
|
+
this.registerElement(element)
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 方式2 TODO: 优化下面这段代码,没太看懂这一块的背景
|
|
197
|
+
const registerParam: RegisterParam = {
|
|
198
|
+
BaseEdge: _View.BaseEdge,
|
|
199
|
+
BaseEdgeModel: _Model.BaseEdgeModel,
|
|
200
|
+
BaseNode: _View.BaseNode,
|
|
201
|
+
BaseNodeModel: _Model.BaseNodeModel,
|
|
202
|
+
RectNode: _View.RectNode,
|
|
203
|
+
RectNodeModel: _Model.RectNodeModel,
|
|
204
|
+
CircleNode: _View.CircleNode,
|
|
205
|
+
CircleNodeModel: _Model.CircleNodeModel,
|
|
206
|
+
PolygonNode: _View.PolygonNode,
|
|
207
|
+
PolygonNodeModel: _Model.PolygonNodeModel,
|
|
208
|
+
TextNode: _View.TextNode,
|
|
209
|
+
TextNodeModel: _Model.TextNodeModel,
|
|
210
|
+
LineEdge: _View.LineEdge,
|
|
211
|
+
LineEdgeModel: _Model.LineEdgeModel,
|
|
212
|
+
DiamondNode: _View.DiamondNode,
|
|
213
|
+
DiamondNodeModel: _Model.DiamondNodeModel,
|
|
214
|
+
PolylineEdge: _View.PolylineEdge,
|
|
215
|
+
PolylineEdgeModel: _Model.PolylineEdgeModel,
|
|
216
|
+
BezierEdge: _View.BezierEdge,
|
|
217
|
+
BezierEdgeModel: _Model.BezierEdgeModel,
|
|
218
|
+
EllipseNode: _View.EllipseNode,
|
|
219
|
+
EllipseNodeModel: _Model.EllipseNodeModel,
|
|
220
|
+
HtmlNode: _View.HtmlNode,
|
|
221
|
+
HtmlNodeModel: _Model.HtmlNodeModel,
|
|
222
|
+
// mobx,
|
|
223
|
+
h,
|
|
224
|
+
type: element,
|
|
225
|
+
}
|
|
226
|
+
// 为了能让后来注册的可以继承前面注册的
|
|
227
|
+
// 例如我注册一个“开始节点”
|
|
228
|
+
// 然后我再想注册一个“立即开始节点”
|
|
229
|
+
// 注册传递参数改为动态。
|
|
230
|
+
// TODO: 确定 extendKey 的作用
|
|
231
|
+
this.viewMap.forEach((component) => {
|
|
232
|
+
const key = (component as any).extendKey
|
|
233
|
+
if (key) {
|
|
234
|
+
registerParam[key] = component
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
this.graphModel.modelMap.forEach((component) => {
|
|
238
|
+
const key = (component as any).extendKey
|
|
239
|
+
if (key) {
|
|
240
|
+
registerParam[key as string] = component
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
if (fn) {
|
|
244
|
+
const { view: ViewClass, model: ModelClass } = fn(registerParam)
|
|
245
|
+
let vClass = ViewClass as any // TODO: 确认 ViewClass 类型
|
|
246
|
+
if (isObserverView && !vClass.isObserved) {
|
|
247
|
+
vClass.isObserved = true
|
|
248
|
+
vClass = observer(vClass)
|
|
249
|
+
}
|
|
250
|
+
this.setView(element, vClass)
|
|
251
|
+
this.graphModel.setModel(element, ModelClass)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* 注册元素(节点 or 边)
|
|
257
|
+
* @param config 注册元素的配置项
|
|
258
|
+
* @private
|
|
259
|
+
*/
|
|
260
|
+
private registerElement(config: RegisterConfig) {
|
|
261
|
+
let ViewComp = config.view
|
|
262
|
+
|
|
263
|
+
if (config.isObserverView !== false && !ViewComp.isObserved) {
|
|
264
|
+
ViewComp.isObserved = true
|
|
265
|
+
ViewComp = observer(ViewComp)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
this.setView(config.type, ViewComp)
|
|
269
|
+
this.graphModel.setModel(config.type, config.model)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 批量注册元素
|
|
274
|
+
* @param elements 注册的元素
|
|
275
|
+
*/
|
|
276
|
+
batchRegister(elements: RegisterConfig[] = []) {
|
|
277
|
+
forEach(elements, (element) => {
|
|
278
|
+
this.registerElement(element)
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private defaultRegister() {
|
|
283
|
+
// LogicFlow default Nodes and Edges
|
|
284
|
+
const defaultElements: RegisterConfig[] = [
|
|
285
|
+
// Node
|
|
286
|
+
{
|
|
287
|
+
type: 'rect',
|
|
288
|
+
view: _View.RectNode,
|
|
289
|
+
model: _Model.RectNodeModel,
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
type: 'circle',
|
|
293
|
+
view: _View.CircleNode,
|
|
294
|
+
model: _Model.CircleNodeModel,
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
type: 'polygon',
|
|
298
|
+
view: _View.PolygonNode,
|
|
299
|
+
model: _Model.PolygonNodeModel,
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
type: 'text',
|
|
303
|
+
view: _View.TextNode,
|
|
304
|
+
model: _Model.TextNodeModel,
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
type: 'ellipse',
|
|
308
|
+
view: _View.EllipseNode,
|
|
309
|
+
model: _Model.EllipseNodeModel,
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
type: 'diamond',
|
|
313
|
+
view: _View.DiamondNode,
|
|
314
|
+
model: _Model.DiamondNodeModel,
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
type: 'html',
|
|
318
|
+
view: _View.HtmlNode,
|
|
319
|
+
model: _Model.HtmlNodeModel,
|
|
320
|
+
},
|
|
321
|
+
// Edge
|
|
322
|
+
{
|
|
323
|
+
type: 'line',
|
|
324
|
+
view: _View.LineEdge,
|
|
325
|
+
model: _Model.LineEdgeModel,
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
type: 'polyline',
|
|
329
|
+
view: _View.PolylineEdge,
|
|
330
|
+
model: _Model.PolylineEdgeModel,
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
type: 'bezier',
|
|
334
|
+
view: _View.BezierEdge,
|
|
335
|
+
model: _Model.BezierEdgeModel,
|
|
336
|
+
},
|
|
337
|
+
]
|
|
338
|
+
this.batchRegister(defaultElements)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/*********************************************************
|
|
342
|
+
* Node 相关方法
|
|
343
|
+
********************************************************/
|
|
344
|
+
/**
|
|
345
|
+
* 添加节点
|
|
346
|
+
* @param nodeConfig 节点配置
|
|
347
|
+
* @param eventType 新增节点事件类型,默认EventType.NODE_ADD
|
|
348
|
+
* @param e MouseEvent 事件
|
|
349
|
+
*/
|
|
350
|
+
addNode(
|
|
351
|
+
nodeConfig: NodeConfig,
|
|
352
|
+
eventType: EventType = EventType.NODE_ADD,
|
|
353
|
+
e?: MouseEvent,
|
|
354
|
+
): BaseNodeModel {
|
|
355
|
+
return this.graphModel.addNode(nodeConfig, eventType, e)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* 删除节点
|
|
360
|
+
* @param {string} nodeId 节点Id
|
|
361
|
+
*/
|
|
362
|
+
deleteNode(nodeId: string): boolean {
|
|
363
|
+
const nodeModel = this.graphModel.getNodeModelById(nodeId)
|
|
364
|
+
if (!nodeModel) return false
|
|
365
|
+
|
|
366
|
+
const nodeData = nodeModel.getData()
|
|
367
|
+
const { guards } = this.options
|
|
368
|
+
const isEnableDelete = guards?.beforeDelete
|
|
369
|
+
? guards.beforeDelete(nodeData)
|
|
370
|
+
: true
|
|
371
|
+
if (isEnableDelete) {
|
|
372
|
+
this.graphModel.deleteNode(nodeId)
|
|
373
|
+
}
|
|
374
|
+
return isEnableDelete
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 克隆节点
|
|
379
|
+
* @param nodeId 节点Id
|
|
380
|
+
*/
|
|
381
|
+
cloneNode(nodeId: string): NodeData | undefined {
|
|
382
|
+
const nodeModel = this.graphModel.getNodeModelById(nodeId)
|
|
383
|
+
const nodeData = nodeModel?.getData()
|
|
384
|
+
|
|
385
|
+
if (nodeData) {
|
|
386
|
+
const { guards } = this.options
|
|
387
|
+
const isEnableClone = guards?.beforeClone
|
|
388
|
+
? guards.beforeClone(nodeData)
|
|
389
|
+
: true
|
|
390
|
+
if (isEnableClone) {
|
|
391
|
+
return this.graphModel.cloneNode(nodeId)
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* 修改节点的id,如果不传新的id,会内部自动创建一个。
|
|
398
|
+
* @param { string } nodeId 将要被修改的id
|
|
399
|
+
* @param { string } newId 可选,修改后的id
|
|
400
|
+
* @returns 修改后的节点id, 如果传入的oldId不存在,返回空字符串
|
|
401
|
+
*/
|
|
402
|
+
changeNodeId(nodeId: string, newId?: string): string {
|
|
403
|
+
return this.graphModel.changeNodeId(nodeId, newId)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 修改指定节点类型
|
|
408
|
+
* @param nodeId 节点id
|
|
409
|
+
* @param type 节点类型
|
|
410
|
+
*/
|
|
411
|
+
changeNodeType(nodeId: string, type: string): void {
|
|
412
|
+
this.graphModel.changeNodeType(nodeId, type)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* 获取节点对象
|
|
417
|
+
* @param nodeId 节点Id
|
|
418
|
+
*/
|
|
419
|
+
getNodeModelById(nodeId: string): BaseNodeModel | undefined {
|
|
420
|
+
return this.graphModel.getNodeModelById(nodeId)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 获取节点数据
|
|
425
|
+
* @param nodeId 节点
|
|
426
|
+
*/
|
|
427
|
+
getNodeDataById(nodeId: string): NodeData | undefined {
|
|
428
|
+
const nodeModel = this.getNodeModelById(nodeId)
|
|
429
|
+
return nodeModel?.getData()
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* 获取所有以此节点为终点的边
|
|
434
|
+
* @param { string } nodeId
|
|
435
|
+
*/
|
|
436
|
+
getNodeIncomingEdge(nodeId: string) {
|
|
437
|
+
return this.graphModel.getNodeIncomingEdge(nodeId)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 获取所有以此节点为起点的边
|
|
442
|
+
* @param {string} nodeId
|
|
443
|
+
*/
|
|
444
|
+
getNodeOutgoingEdge(nodeId: string) {
|
|
445
|
+
return this.graphModel.getNodeOutgoingEdge(nodeId)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* 获取节点连接到的所有起始节点
|
|
450
|
+
* @param {string} nodeId
|
|
451
|
+
*/
|
|
452
|
+
getNodeIncomingNode(nodeId: string) {
|
|
453
|
+
return this.graphModel.getNodeIncomingNode(nodeId)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* 获取节点连接到的所有目标节点
|
|
458
|
+
* @param {string} nodeId
|
|
459
|
+
*/
|
|
460
|
+
getNodeOutgoingNode(nodeId: string) {
|
|
461
|
+
return this.graphModel.getNodeOutgoingNode(nodeId)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* 内部保留方法
|
|
466
|
+
* 创建一个fakeNode,用于dnd插件拖动节点进画布的时候使用。
|
|
467
|
+
*/
|
|
468
|
+
createFakeNode(nodeConfig: NodeConfig) {
|
|
469
|
+
const Model = this.graphModel.modelMap.get(
|
|
470
|
+
nodeConfig.type,
|
|
471
|
+
) as BaseNodeModelCtor
|
|
472
|
+
if (!Model) {
|
|
473
|
+
console.warn(`不存在为${nodeConfig.type}类型的节点`)
|
|
474
|
+
return null
|
|
475
|
+
}
|
|
476
|
+
// * initNodeData区分是否为虚拟节点
|
|
477
|
+
const fakeNodeModel = new Model(
|
|
478
|
+
{
|
|
479
|
+
...nodeConfig,
|
|
480
|
+
virtual: true,
|
|
481
|
+
},
|
|
482
|
+
this.graphModel,
|
|
483
|
+
)
|
|
484
|
+
this.graphModel.setFakeNode(fakeNodeModel)
|
|
485
|
+
return fakeNodeModel
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* 内部保留方法
|
|
490
|
+
* 移除fakeNode
|
|
491
|
+
*/
|
|
492
|
+
removeFakeNode() {
|
|
493
|
+
this.graphModel.removeFakeNode()
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* 内部保留方法
|
|
498
|
+
* 用于fakeNode显示对齐线
|
|
499
|
+
*/
|
|
500
|
+
setNodeSnapLine(data: NodeData) {
|
|
501
|
+
this.snaplineModel?.setNodeSnapLine(data)
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* 内部保留方法
|
|
506
|
+
* 用于fakeNode移除对齐线
|
|
507
|
+
*/
|
|
508
|
+
removeNodeSnapLine() {
|
|
509
|
+
this.snaplineModel?.clearSnapline()
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/*********************************************************
|
|
513
|
+
* Edge 相关方法
|
|
514
|
+
********************************************************/
|
|
515
|
+
/**
|
|
516
|
+
* 设置默认的边类型。
|
|
517
|
+
* 也就是设置在节点直接由用户手动绘制的连线类型。
|
|
518
|
+
* @param type LFOptions.EdgeType
|
|
519
|
+
*/
|
|
520
|
+
setDefaultEdgeType(type: LFOptions.EdgeType): void {
|
|
521
|
+
this.graphModel.setDefaultEdgeType(type)
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* 给两个节点之间添加一条边
|
|
526
|
+
* @example
|
|
527
|
+
* lf.addEdge({
|
|
528
|
+
* type: 'polygon'
|
|
529
|
+
* sourceNodeId: 'node_id_1',
|
|
530
|
+
* targetNodeId: 'node_id_2',
|
|
531
|
+
* })
|
|
532
|
+
* @param {EdgeConfig} edgeConfig
|
|
533
|
+
*/
|
|
534
|
+
addEdge(edgeConfig: EdgeConfig): BaseEdgeModel {
|
|
535
|
+
return this.graphModel.addEdge(edgeConfig)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* 基于id获取边数据
|
|
540
|
+
* @param edgeId 边Id
|
|
541
|
+
* @returns EdgeData
|
|
542
|
+
*/
|
|
543
|
+
getEdgeDataById(edgeId: string): EdgeData | undefined {
|
|
544
|
+
const edgeModel = this.getEdgeModelById(edgeId)
|
|
545
|
+
return edgeModel?.getData()
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* 基于边Id获取边的model
|
|
550
|
+
* @param edgeId 边的Id
|
|
551
|
+
* @return model
|
|
552
|
+
*/
|
|
553
|
+
getEdgeModelById(edgeId: string): BaseEdgeModel | undefined {
|
|
554
|
+
return this.graphModel.getEdgeModelById(edgeId)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* 获取满足条件边的model
|
|
559
|
+
* @param edgeFilter 过滤条件
|
|
560
|
+
* @example
|
|
561
|
+
* 获取所有起点为节点 A 的边的 model
|
|
562
|
+
* lf.getEdgeModels({
|
|
563
|
+
* sourceNodeId: 'nodeA_id'
|
|
564
|
+
* })
|
|
565
|
+
* 获取所有终点为节点 B 的边的 model
|
|
566
|
+
* lf.getEdgeModels({
|
|
567
|
+
* targetNodeId: 'nodeB_id'
|
|
568
|
+
* })
|
|
569
|
+
* 获取起点为节点 A,终点为节点 B 的边
|
|
570
|
+
* lf.getEdgeModels({
|
|
571
|
+
* sourceNodeId: 'nodeA_id',
|
|
572
|
+
* targetNodeId: 'nodeB_id'
|
|
573
|
+
* })
|
|
574
|
+
* @return model数组
|
|
575
|
+
*/
|
|
576
|
+
getEdgeModels({
|
|
577
|
+
sourceNodeId,
|
|
578
|
+
targetNodeId,
|
|
579
|
+
}: {
|
|
580
|
+
sourceNodeId?: string
|
|
581
|
+
targetNodeId?: string
|
|
582
|
+
}): BaseEdgeModel[] {
|
|
583
|
+
const results: BaseEdgeModel[] = []
|
|
584
|
+
const { edges } = this.graphModel
|
|
585
|
+
if (sourceNodeId && targetNodeId) {
|
|
586
|
+
forEach(edges, (edge) => {
|
|
587
|
+
if (
|
|
588
|
+
edge.sourceNodeId === sourceNodeId &&
|
|
589
|
+
edge.targetNodeId === targetNodeId
|
|
590
|
+
) {
|
|
591
|
+
results.push(edge)
|
|
592
|
+
}
|
|
593
|
+
})
|
|
594
|
+
} else if (sourceNodeId) {
|
|
595
|
+
forEach(edges, (edge) => {
|
|
596
|
+
if (edge.sourceNodeId === sourceNodeId) {
|
|
597
|
+
results.push(edge)
|
|
598
|
+
}
|
|
599
|
+
})
|
|
600
|
+
} else if (targetNodeId) {
|
|
601
|
+
forEach(edges, (edge) => {
|
|
602
|
+
if (edge.targetNodeId === targetNodeId) {
|
|
603
|
+
results.push(edge)
|
|
604
|
+
}
|
|
605
|
+
})
|
|
606
|
+
}
|
|
607
|
+
return results
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* 修改边的id, 如果不传新的id,会内部自动创建一个。
|
|
612
|
+
* @param { string } edgeId 将要被修改的id
|
|
613
|
+
* @param { string } newId 可选,修改后的id
|
|
614
|
+
* @returns 修改后的节点id, 如果传入的oldId不存在,返回空字符串
|
|
615
|
+
*/
|
|
616
|
+
changeEdgeId(edgeId: string, newId?: string): string {
|
|
617
|
+
return this.graphModel.changeEdgeId(edgeId, newId)
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* 切换边的类型
|
|
622
|
+
* @param edgeId 边Id
|
|
623
|
+
* @param type 边类型
|
|
624
|
+
*/
|
|
625
|
+
changeEdgeType(edgeId: string, type: LFOptions.EdgeType): void {
|
|
626
|
+
this.graphModel.changeEdgeType(edgeId, type)
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* 删除边
|
|
631
|
+
* @param {string} edgeId 边Id
|
|
632
|
+
*/
|
|
633
|
+
deleteEdge(edgeId: string): boolean {
|
|
634
|
+
const edgeModel = this.graphModel.getEdgeModelById(edgeId)
|
|
635
|
+
if (!edgeModel) return false
|
|
636
|
+
|
|
637
|
+
const edgeData = edgeModel.getData()
|
|
638
|
+
const { guards } = this.options
|
|
639
|
+
const isEnableDelete = guards?.beforeDelete
|
|
640
|
+
? guards.beforeDelete(edgeData)
|
|
641
|
+
: true
|
|
642
|
+
if (isEnableDelete) {
|
|
643
|
+
this.graphModel.deleteEdgeById(edgeId)
|
|
644
|
+
}
|
|
645
|
+
return isEnableDelete
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* 基于给定节点(作为边起点或终点,可以只传其一),删除对应的边
|
|
650
|
+
* @param sourceNodeId 边的起点节点ID
|
|
651
|
+
* @param targetNodeId 边的终点节点ID
|
|
652
|
+
*/
|
|
653
|
+
deleteEdgeByNodeId({
|
|
654
|
+
sourceNodeId,
|
|
655
|
+
targetNodeId,
|
|
656
|
+
}: {
|
|
657
|
+
sourceNodeId?: string
|
|
658
|
+
targetNodeId?: string
|
|
659
|
+
}): void {
|
|
660
|
+
// TODO: 将下面方法从 this.graphModel 解构,并测试代码功能是否正常(需要确认 this 指向是否有异常)
|
|
661
|
+
if (sourceNodeId && targetNodeId) {
|
|
662
|
+
this.graphModel.deleteEdgeBySourceAndTarget(sourceNodeId, targetNodeId)
|
|
663
|
+
} else if (sourceNodeId) {
|
|
664
|
+
this.graphModel.deleteEdgeBySource(sourceNodeId)
|
|
665
|
+
} else if (targetNodeId) {
|
|
666
|
+
this.graphModel.deleteEdgeByTarget(targetNodeId)
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* 获取节点连接的所有边的model
|
|
672
|
+
* @param nodeId 节点ID
|
|
673
|
+
* @returns model数组
|
|
674
|
+
*/
|
|
675
|
+
getNodeEdges(nodeId: string): BaseEdgeModel[] {
|
|
676
|
+
return this.graphModel.getNodeEdges(nodeId)
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/*********************************************************
|
|
680
|
+
* Element 相关方法
|
|
681
|
+
********************************************************/
|
|
682
|
+
/**
|
|
683
|
+
* 添加多个元素, 包括边和节点。
|
|
684
|
+
* @param nodes
|
|
685
|
+
* @param edges
|
|
686
|
+
* @param distance
|
|
687
|
+
*/
|
|
688
|
+
addElements(
|
|
689
|
+
{ nodes, edges }: GraphConfigData,
|
|
690
|
+
distance = 40,
|
|
691
|
+
): GraphElements | undefined {
|
|
692
|
+
// TODO: 1. 解决下面方法中 distance 传参缺未使用的问题;该方法在快捷键中有调用
|
|
693
|
+
console.log('addElements', nodes, edges, distance)
|
|
694
|
+
// TODO: 2. review 一下本函数代码逻辑,确认 nodeIdMap 的作用,看是否有优化的空间
|
|
695
|
+
const nodeIdMap: Record<string, string> = {}
|
|
696
|
+
const elements: GraphElements = {
|
|
697
|
+
nodes: [],
|
|
698
|
+
edges: [],
|
|
699
|
+
}
|
|
700
|
+
forEach(nodes, (node) => {
|
|
701
|
+
const nodeId = node.id
|
|
702
|
+
const nodeModel = this.addNode(node)
|
|
703
|
+
|
|
704
|
+
if (nodeId) nodeIdMap[nodeId] = nodeModel.id
|
|
705
|
+
elements.nodes.push(nodeModel)
|
|
706
|
+
})
|
|
707
|
+
|
|
708
|
+
forEach(edges, (edge) => {
|
|
709
|
+
let { sourceNodeId, targetNodeId } = edge
|
|
710
|
+
if (nodeIdMap[sourceNodeId]) sourceNodeId = nodeIdMap[sourceNodeId]
|
|
711
|
+
if (nodeIdMap[targetNodeId]) targetNodeId = nodeIdMap[targetNodeId]
|
|
712
|
+
const edgeModel = this.graphModel.addEdge({
|
|
713
|
+
...edge,
|
|
714
|
+
sourceNodeId,
|
|
715
|
+
targetNodeId,
|
|
716
|
+
})
|
|
717
|
+
elements.edges.push(edgeModel)
|
|
718
|
+
})
|
|
719
|
+
return elements
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* 将图形选中
|
|
724
|
+
* @param id 选择元素ID
|
|
725
|
+
* @param multiple 是否允许多选,如果为true,不会将上一个选中的元素重置
|
|
726
|
+
* @param toFront 是否将选中的元素置顶,默认为true
|
|
727
|
+
*/
|
|
728
|
+
selectElementById(id: string, multiple = false, toFront = true) {
|
|
729
|
+
this.graphModel.selectElementById(id, multiple)
|
|
730
|
+
if (!multiple && toFront) {
|
|
731
|
+
this.graphModel.toFront(id)
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* 获取选中的元素数据
|
|
737
|
+
* @param isIgnoreCheck 是否包括sourceNode和targetNode没有被选中的边,默认包括。
|
|
738
|
+
* 注意:复制的时候不能包括此类边, 因为复制的时候不允许悬空的边。
|
|
739
|
+
*/
|
|
740
|
+
getSelectElements(isIgnoreCheck = true): GraphData {
|
|
741
|
+
return this.graphModel.getSelectElements(isIgnoreCheck)
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* 将所有选中的元素设置为非选中
|
|
746
|
+
*/
|
|
747
|
+
clearSelectElements() {
|
|
748
|
+
this.graphModel.clearSelectElements()
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* 获取节点或边对象
|
|
753
|
+
* @param id id
|
|
754
|
+
*/
|
|
755
|
+
getModelById(id: string): LogicFlow.GraphElement | undefined {
|
|
756
|
+
return this.graphModel.getElement(id)
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* 获取节点或边的数据
|
|
761
|
+
* @param id id
|
|
762
|
+
*/
|
|
763
|
+
getDataById(id: string): NodeData | EdgeData | undefined {
|
|
764
|
+
return this.graphModel.getElement(id)?.getData()
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* 删除元素,在不确定当前id是节点还是边时使用
|
|
769
|
+
* @param id 元素id
|
|
770
|
+
*/
|
|
771
|
+
deleteElement(id: string): boolean {
|
|
772
|
+
const model = this.getModelById(id)
|
|
773
|
+
if (!model) return false
|
|
774
|
+
|
|
775
|
+
const callback = {
|
|
776
|
+
[ElementType.NODE]: this.deleteNode,
|
|
777
|
+
[ElementType.EDGE]: this.deleteEdge,
|
|
778
|
+
}
|
|
779
|
+
return callback[model.BaseType]?.call(this, id) ?? false
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* 设置元素的zIndex.
|
|
784
|
+
* 注意:默认堆叠模式下,不建议使用此方法。
|
|
785
|
+
* @see todo link 堆叠模式
|
|
786
|
+
* @param id 元素id
|
|
787
|
+
* @param zIndex zIndex的值,可以传数字,也支持传入 'top' 和 'bottom'
|
|
788
|
+
*/
|
|
789
|
+
setElementZIndex(id: string, zIndex: number | 'top' | 'bottom') {
|
|
790
|
+
return this.graphModel.setElementZIndex(id, zIndex)
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* 获取指定区域内的所有元素,此区域必须是DOM层。
|
|
795
|
+
* 例如鼠标绘制选区后,获取选区内的所有元素。
|
|
796
|
+
* @see todo 分层
|
|
797
|
+
* @param leftTopPoint 区域左上角坐标, dom层坐标
|
|
798
|
+
* @param rightBottomPoint 区域右下角坐标,dom层坐标
|
|
799
|
+
* @param wholeEdge
|
|
800
|
+
* @param wholeNode
|
|
801
|
+
* @param ignoreHideElement
|
|
802
|
+
*/
|
|
803
|
+
getAreaElement(
|
|
804
|
+
leftTopPoint: PointTuple,
|
|
805
|
+
rightBottomPoint: PointTuple,
|
|
806
|
+
wholeEdge = true,
|
|
807
|
+
wholeNode = true,
|
|
808
|
+
ignoreHideElement = false,
|
|
809
|
+
) {
|
|
810
|
+
return this.graphModel
|
|
811
|
+
.getAreaElement(
|
|
812
|
+
leftTopPoint,
|
|
813
|
+
rightBottomPoint,
|
|
814
|
+
wholeEdge,
|
|
815
|
+
wholeNode,
|
|
816
|
+
ignoreHideElement,
|
|
817
|
+
)
|
|
818
|
+
.map((element) => element.getData())
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* 设置元素的自定义属性
|
|
823
|
+
* @see todo docs link
|
|
824
|
+
* @param id 元素的id
|
|
825
|
+
* @param properties 自定义属性
|
|
826
|
+
*/
|
|
827
|
+
setProperties(id: string, properties: PropertiesType): void {
|
|
828
|
+
this.graphModel.getElement(id)?.setProperties(formatData(properties))
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* 获取元素的自定义属性
|
|
833
|
+
* @param id 元素的id
|
|
834
|
+
* @returns 自定义属性
|
|
835
|
+
*/
|
|
836
|
+
getProperties(id: string): PropertiesType | undefined {
|
|
837
|
+
return this.graphModel.getElement(id)?.getProperties()
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
deleteProperty(id: string, key: string): void {
|
|
841
|
+
this.graphModel.getElement(id)?.deleteProperty(key)
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* FBI WARNING !!! 慎用 === 不要用
|
|
846
|
+
* 修改对应元素 model 中的属性
|
|
847
|
+
* 注意:此方法慎用,除非您对logicflow内部有足够的了解。
|
|
848
|
+
* 大多数情况下,请使用setProperties、updateText、changeNodeId等方法。
|
|
849
|
+
* 例如直接使用此方法修改节点的id,那么就是会导致连接到此节点的边的sourceNodeId出现找不到的情况。
|
|
850
|
+
* @param {string} id 元素id
|
|
851
|
+
* @param {object} attributes 需要更新的属性
|
|
852
|
+
*/
|
|
853
|
+
updateAttributes(id: string, attributes: object) {
|
|
854
|
+
this.graphModel.updateAttributes(id, attributes)
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/*********************************************************
|
|
858
|
+
* Text 相关方法
|
|
859
|
+
********************************************************/
|
|
860
|
+
/**
|
|
861
|
+
* 显示节点、连线文本编辑框
|
|
862
|
+
* @param id 元素id
|
|
863
|
+
*/
|
|
864
|
+
editText(id: string): void {
|
|
865
|
+
this.graphModel.editText(id)
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* 更新节点或边的文案
|
|
870
|
+
* @param id 节点或者边id
|
|
871
|
+
* @param value 文案内容
|
|
872
|
+
*/
|
|
873
|
+
updateText(id: string, value: string) {
|
|
874
|
+
this.graphModel.updateText(id, value)
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/*********************************************************
|
|
878
|
+
* EditConfig 相关方法
|
|
879
|
+
********************************************************/
|
|
880
|
+
/**
|
|
881
|
+
* 更新流程图编辑相关设置
|
|
882
|
+
* @param {object} config 编辑配置
|
|
883
|
+
* @see todo docs link
|
|
884
|
+
*/
|
|
885
|
+
updateEditConfig(config: EditConfigInterface) {
|
|
886
|
+
const { editConfigModel, transformModel } = this.graphModel
|
|
887
|
+
editConfigModel.updateEditConfig(config)
|
|
888
|
+
if (config?.stopMoveGraph !== undefined) {
|
|
889
|
+
transformModel.updateTranslateLimits(config.stopMoveGraph)
|
|
890
|
+
}
|
|
891
|
+
// 静默模式切换时,修改快捷键的启用状态
|
|
892
|
+
config?.isSilentMode ? this.keyboard.disable() : this.keyboard.enable(true)
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* 获取流程图当前编辑相关设置
|
|
897
|
+
* @see todo docs link
|
|
898
|
+
*/
|
|
899
|
+
getEditConfig() {
|
|
900
|
+
return this.graphModel.editConfigModel.getConfig()
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/*********************************************************
|
|
904
|
+
* Graph 相关方法
|
|
905
|
+
********************************************************/
|
|
906
|
+
/**
|
|
907
|
+
* 设置主题样式
|
|
908
|
+
* @param { object } style 自定义主题样式
|
|
909
|
+
* todo docs link
|
|
910
|
+
*/
|
|
911
|
+
setTheme(style: Partial<LogicFlow.Theme>): void {
|
|
912
|
+
this.graphModel.setTheme(style)
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
private focusByElement(id: string) {
|
|
916
|
+
let coordinate: Position | undefined = undefined
|
|
917
|
+
const nodeModel = this.getNodeModelById(id)
|
|
918
|
+
if (nodeModel) {
|
|
919
|
+
const { x, y } = nodeModel.getData()
|
|
920
|
+
coordinate = {
|
|
921
|
+
x,
|
|
922
|
+
y,
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
const edgeModel = this.getEdgeModelById(id)
|
|
926
|
+
if (edgeModel) {
|
|
927
|
+
const { x, y } = edgeModel.textPosition
|
|
928
|
+
coordinate = {
|
|
929
|
+
x,
|
|
930
|
+
y,
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
if (coordinate) {
|
|
935
|
+
this.focusByCoordinate(coordinate)
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
private focusByCoordinate(coordinate: Position) {
|
|
940
|
+
const { transformModel, width, height } = this.graphModel
|
|
941
|
+
const { x, y } = coordinate
|
|
942
|
+
transformModel.focusOn(x, y, width, height)
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* 定位到画布视口中心
|
|
947
|
+
* 支持用户传入图形当前的坐标或id,可以通过type来区分是节点还是边的id,也可以不传(兜底)
|
|
948
|
+
* @param focusOnArgs.id 如果传入的是id, 则画布视口中心移动到此id的元素中心点。
|
|
949
|
+
* @param focusOnArgs.coordinate 如果传入的是坐标,则画布视口中心移动到此坐标。
|
|
950
|
+
* TODO: 测试下面代码,重构了一下逻辑,重载 api 定义
|
|
951
|
+
*/
|
|
952
|
+
focusOn(id: string): void
|
|
953
|
+
focusOn(coordinate: Position): void
|
|
954
|
+
focusOn(focusOnArgs: LogicFlow.FocusOnArgsType): void
|
|
955
|
+
focusOn(focusOnArgs: string | Position | LogicFlow.FocusOnArgsType): void {
|
|
956
|
+
if (typeof focusOnArgs === 'string') {
|
|
957
|
+
// string focusOnArgs -> id
|
|
958
|
+
this.focusByElement(focusOnArgs)
|
|
959
|
+
} else if ('x' in focusOnArgs && 'y' in focusOnArgs) {
|
|
960
|
+
// Position focusOnArgs -> coordinate
|
|
961
|
+
this.focusByCoordinate(focusOnArgs)
|
|
962
|
+
} else {
|
|
963
|
+
// FocusOnArgsType
|
|
964
|
+
const { id, coordinate } = focusOnArgs
|
|
965
|
+
if (id) {
|
|
966
|
+
this.focusByElement(id)
|
|
967
|
+
}
|
|
968
|
+
if (coordinate) {
|
|
969
|
+
this.focusByCoordinate(coordinate)
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* 重新设置画布的宽高
|
|
976
|
+
* 不传会自动计算画布宽高
|
|
977
|
+
*/
|
|
978
|
+
resize(width?: number, height?: number): void {
|
|
979
|
+
this.graphModel.resize(width, height)
|
|
980
|
+
this.options.width = this.graphModel.width
|
|
981
|
+
this.options.height = this.graphModel.height
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* 将某个元素放置到顶部。
|
|
986
|
+
* 如果堆叠模式为默认模式,则将原置顶元素重新恢复原有层级。
|
|
987
|
+
* 如果堆叠模式为递增模式,则将需指定元素zIndex设置为当前最大zIndex + 1。
|
|
988
|
+
* @see todo link 堆叠模式
|
|
989
|
+
* @param id 元素Id
|
|
990
|
+
*/
|
|
991
|
+
toFront(id: string) {
|
|
992
|
+
this.graphModel.toFront(id)
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* 获取事件位置相对于画布左上角的坐标
|
|
997
|
+
* 画布所在的位置可以是页面任何地方,原生事件返回的坐标是相对于页面左上角的,该方法可以提供以画布左上角为原点的准确位置。
|
|
998
|
+
* @param {number} x
|
|
999
|
+
* @param {number} y
|
|
1000
|
+
* @returns {object} Point 事件位置的坐标
|
|
1001
|
+
* @returns {object} Point.domOverlayPosition HTML层上的坐标
|
|
1002
|
+
* @returns {object} Point.canvasOverlayPosition SVG层上的坐标
|
|
1003
|
+
*/
|
|
1004
|
+
getPointByClient(x: number, y: number): ClientPosition
|
|
1005
|
+
getPointByClient(point: Position): ClientPosition
|
|
1006
|
+
getPointByClient(
|
|
1007
|
+
x: number | Position,
|
|
1008
|
+
y?: number,
|
|
1009
|
+
): ClientPosition | undefined {
|
|
1010
|
+
if (typeof x === 'object') {
|
|
1011
|
+
return this.graphModel.getPointByClient(x)
|
|
1012
|
+
} else if (typeof y === 'number') {
|
|
1013
|
+
return this.graphModel.getPointByClient({
|
|
1014
|
+
x,
|
|
1015
|
+
y,
|
|
1016
|
+
})
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* 获取流程绘图数据
|
|
1022
|
+
* 注意: getGraphData返回的数据受到adapter影响,所以其数据格式不一定是logicflow内部图数据格式。
|
|
1023
|
+
* 如果实现通用插件,请使用getGraphRawData
|
|
1024
|
+
*/
|
|
1025
|
+
getGraphData(...params: any): GraphData | unknown {
|
|
1026
|
+
const data = this.getGraphRawData()
|
|
1027
|
+
if (this.adapterOut) {
|
|
1028
|
+
return this.adapterOut(data, ...params)
|
|
1029
|
+
}
|
|
1030
|
+
return data
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* 获取流程绘图原始数据
|
|
1035
|
+
* 在存在adapter时,可以使用getGraphRawData获取图原始数据
|
|
1036
|
+
*/
|
|
1037
|
+
getGraphRawData(): GraphData {
|
|
1038
|
+
return this.graphModel.modelToGraphData()
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* 清空画布
|
|
1043
|
+
*/
|
|
1044
|
+
clearData() {
|
|
1045
|
+
this.graphModel.clearData()
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/*********************************************************
|
|
1049
|
+
* LogicFlow Render方法
|
|
1050
|
+
********************************************************/
|
|
1051
|
+
renderRawData(graphRawData: GraphConfigData) {
|
|
1052
|
+
this.graphModel.graphDataToModel(formatData(graphRawData))
|
|
1053
|
+
if (this.options.history !== false) {
|
|
1054
|
+
this.history.watch(this.graphModel)
|
|
1055
|
+
}
|
|
1056
|
+
render(
|
|
1057
|
+
<Graph
|
|
1058
|
+
getView={this.getView}
|
|
1059
|
+
tool={this.tool}
|
|
1060
|
+
options={this.options}
|
|
1061
|
+
dnd={this.dnd}
|
|
1062
|
+
snaplineModel={this.snaplineModel}
|
|
1063
|
+
graphModel={this.graphModel}
|
|
1064
|
+
/>,
|
|
1065
|
+
this.container,
|
|
1066
|
+
)
|
|
1067
|
+
this.emit(EventType.GRAPH_RENDERED, {
|
|
1068
|
+
data: this.graphModel.modelToGraphData(),
|
|
1069
|
+
})
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* 渲染图
|
|
1074
|
+
* @example
|
|
1075
|
+
* lf.render({
|
|
1076
|
+
* nodes: [
|
|
1077
|
+
* {
|
|
1078
|
+
* id: 'node_1',
|
|
1079
|
+
* type: 'rect',
|
|
1080
|
+
* x: 100,
|
|
1081
|
+
* y: 100
|
|
1082
|
+
* },
|
|
1083
|
+
* {
|
|
1084
|
+
* id: 'node_2',
|
|
1085
|
+
* type: 'circle',
|
|
1086
|
+
* x: 300,
|
|
1087
|
+
* y: 200
|
|
1088
|
+
* }
|
|
1089
|
+
* ],
|
|
1090
|
+
* edges: [
|
|
1091
|
+
* {
|
|
1092
|
+
* sourceNodeId: 'node_1',
|
|
1093
|
+
* targetNodeId: 'node_2',
|
|
1094
|
+
* type: 'polyline'
|
|
1095
|
+
* }
|
|
1096
|
+
* ]
|
|
1097
|
+
* })
|
|
1098
|
+
* @param graphData 图数据
|
|
1099
|
+
*/
|
|
1100
|
+
render(graphData: GraphConfigData) {
|
|
1101
|
+
let graphRawData = cloneDeep(graphData)
|
|
1102
|
+
if (this.adapterIn) {
|
|
1103
|
+
graphRawData = this.adapterIn(graphRawData)
|
|
1104
|
+
}
|
|
1105
|
+
this.renderRawData(graphRawData)
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/*********************************************************
|
|
1109
|
+
* History/Resize 相关方法
|
|
1110
|
+
********************************************************/
|
|
1111
|
+
/**
|
|
1112
|
+
* 历史记录操作
|
|
1113
|
+
* 返回上一步
|
|
1114
|
+
*/
|
|
1115
|
+
undo() {
|
|
1116
|
+
if (!this.history.undoAble()) return
|
|
1117
|
+
// formatData兼容vue数据
|
|
1118
|
+
const graphData = formatData(this.history.undo()!)
|
|
1119
|
+
this.clearSelectElements()
|
|
1120
|
+
this.graphModel.graphDataToModel(graphData)
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* 历史记录操作
|
|
1125
|
+
* 恢复下一步
|
|
1126
|
+
*/
|
|
1127
|
+
redo() {
|
|
1128
|
+
if (!this.history.redoAble()) return
|
|
1129
|
+
// formatData兼容vue数据
|
|
1130
|
+
const graphData = formatData(this.history.redo()!)
|
|
1131
|
+
this.clearSelectElements()
|
|
1132
|
+
this.graphModel.graphDataToModel(graphData)
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* 放大缩小图形
|
|
1137
|
+
* @param zoomSize 放大缩小的值,支持传入0-n之间的数字。小于1表示缩小,大于1表示放大。也支持传入true和false按照内置的刻度放大缩小
|
|
1138
|
+
* @param point 缩放的原点
|
|
1139
|
+
* @returns {string} -放大缩小的比例
|
|
1140
|
+
*/
|
|
1141
|
+
zoom(zoomSize?: ZoomParamType, point?: PointTuple): string {
|
|
1142
|
+
const { transformModel } = this.graphModel
|
|
1143
|
+
return transformModel.zoom(zoomSize, point)
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* 重置图形的放大缩写比例为默认
|
|
1148
|
+
*/
|
|
1149
|
+
resetZoom(): void {
|
|
1150
|
+
const { transformModel } = this.graphModel
|
|
1151
|
+
transformModel.resetZoom()
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
/**
|
|
1155
|
+
* 设置图形缩小时,能缩放到的最小倍数。参数为0-1自己。默认0.2
|
|
1156
|
+
* @param size 图形缩小的最小值
|
|
1157
|
+
*/
|
|
1158
|
+
setZoomMiniSize(size: number): void {
|
|
1159
|
+
const { transformModel } = this.graphModel
|
|
1160
|
+
transformModel.setZoomMiniSize(size)
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* 设置图形放大时,能放大到的最大倍数,默认16
|
|
1165
|
+
* @param size 图形放大的最大值
|
|
1166
|
+
*/
|
|
1167
|
+
setZoomMaxSize(size: number): void {
|
|
1168
|
+
const { transformModel } = this.graphModel
|
|
1169
|
+
transformModel.setZoomMaxSize(size)
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* 获取缩放的值和平移的值。
|
|
1174
|
+
*/
|
|
1175
|
+
getTransform() {
|
|
1176
|
+
const {
|
|
1177
|
+
transformModel: { SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y },
|
|
1178
|
+
} = this.graphModel
|
|
1179
|
+
return {
|
|
1180
|
+
SCALE_X,
|
|
1181
|
+
SCALE_Y,
|
|
1182
|
+
TRANSLATE_X,
|
|
1183
|
+
TRANSLATE_Y,
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* 平移图
|
|
1189
|
+
* @param x 向x轴移动距离
|
|
1190
|
+
* @param y 向y轴移动距离
|
|
1191
|
+
*/
|
|
1192
|
+
translate(x: number, y: number): void {
|
|
1193
|
+
const { transformModel } = this.graphModel
|
|
1194
|
+
transformModel.translate(x, y)
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* 还原图形为初始位置
|
|
1199
|
+
*/
|
|
1200
|
+
resetTranslate(): void {
|
|
1201
|
+
const { transformModel } = this.graphModel
|
|
1202
|
+
const { TRANSLATE_X, TRANSLATE_Y } = transformModel
|
|
1203
|
+
this.translate(-TRANSLATE_X, -TRANSLATE_Y)
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* 图形画布居中显示
|
|
1208
|
+
*/
|
|
1209
|
+
translateCenter(): void {
|
|
1210
|
+
this.graphModel.translateCenter()
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* 图形适应屏幕大小
|
|
1215
|
+
* @param verticalOffset number 距离盒子上下的距离, 默认为20
|
|
1216
|
+
* @param horizontalOffset number 距离盒子左右的距离, 默认为20
|
|
1217
|
+
*/
|
|
1218
|
+
fitView(verticalOffset?: number, horizontalOffset?: number): void {
|
|
1219
|
+
if (horizontalOffset === undefined) {
|
|
1220
|
+
horizontalOffset = verticalOffset // 兼容以前的只传一个参数的情况
|
|
1221
|
+
}
|
|
1222
|
+
this.graphModel.fitView(verticalOffset, horizontalOffset)
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* 开启边的动画
|
|
1227
|
+
* @param edgeId string
|
|
1228
|
+
*/
|
|
1229
|
+
openEdgeAnimation(edgeId: string): void {
|
|
1230
|
+
this.graphModel.openEdgeAnimation(edgeId)
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* 关闭边的动画
|
|
1235
|
+
* @param edgeId string
|
|
1236
|
+
*/
|
|
1237
|
+
closeEdgeAnimation(edgeId: string): void {
|
|
1238
|
+
this.graphModel.closeEdgeAnimation(edgeId)
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
/*********************************************************
|
|
1242
|
+
* 事件系统方法
|
|
1243
|
+
********************************************************/
|
|
1244
|
+
/**
|
|
1245
|
+
* 监听事件
|
|
1246
|
+
* 事件详情见 @see todo
|
|
1247
|
+
* 支持同时监听多个事件
|
|
1248
|
+
* @example
|
|
1249
|
+
* lf.on('node:click,node:contextmenu', (data) => {
|
|
1250
|
+
* });
|
|
1251
|
+
*/
|
|
1252
|
+
on<T extends keyof EventArgs>(evt: T, callback: EventCallback<T>): void
|
|
1253
|
+
on<T extends string>(evt: T, callback: EventCallback<T>): void
|
|
1254
|
+
on(evt: string, callback: EventCallback) {
|
|
1255
|
+
this.graphModel.eventCenter.on(evt, callback)
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* 撤销监听事件
|
|
1260
|
+
*/
|
|
1261
|
+
off<T extends keyof EventArgs>(evt: T, callback: EventCallback<T>): void
|
|
1262
|
+
off<T extends string>(evt: T, callback: EventCallback<T>): void
|
|
1263
|
+
off(evt: string, callback: EventCallback) {
|
|
1264
|
+
this.graphModel.eventCenter.off(evt, callback)
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* 监听事件,只监听一次
|
|
1269
|
+
*/
|
|
1270
|
+
once<T extends keyof EventArgs>(evt: T, callback: EventCallback<T>): void
|
|
1271
|
+
once<T extends string>(evt: T, callback: EventCallback<T>): void
|
|
1272
|
+
once(evt: string, callback: EventCallback) {
|
|
1273
|
+
this.graphModel.eventCenter.once(evt, callback)
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* 触发监听事件
|
|
1278
|
+
*/
|
|
1279
|
+
emit<T extends keyof EventArgs>(evts: T, eventArgs: CallbackArgs<T>): void
|
|
1280
|
+
emit<T extends string>(evts: T, eventArgs: CallbackArgs<T>): void
|
|
1281
|
+
emit(evt: string, arg: EventArgs) {
|
|
1282
|
+
this.graphModel.eventCenter.emit(evt, arg)
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
/*********************************************************
|
|
1286
|
+
* 插件系统方法
|
|
1287
|
+
********************************************************/
|
|
1288
|
+
/**
|
|
1289
|
+
* 添加扩展, 待讨论,这里是不是静态方法好一些?
|
|
1290
|
+
* 重复添加插件的时候,把上一次添加的插件的销毁。
|
|
1291
|
+
* @param extension
|
|
1292
|
+
* @param props
|
|
1293
|
+
*/
|
|
1294
|
+
static use(
|
|
1295
|
+
extension: ExtensionConstructor,
|
|
1296
|
+
props?: Record<string, unknown>,
|
|
1297
|
+
): void {
|
|
1298
|
+
let { pluginName } = extension
|
|
1299
|
+
if (!pluginName) {
|
|
1300
|
+
console.warn(
|
|
1301
|
+
`请给插件${
|
|
1302
|
+
extension.name || extension.constructor.name
|
|
1303
|
+
}指定pluginName!`,
|
|
1304
|
+
)
|
|
1305
|
+
pluginName = extension.name // 兼容以前name的情况,1.0版本去掉。
|
|
1306
|
+
}
|
|
1307
|
+
// TODO: 应该在何时进行插件的销毁
|
|
1308
|
+
// const preExtension = this.extensions.get(pluginName)?.extension
|
|
1309
|
+
// preExtension?.destroy?.() // 该代码应该有问题,因为 preExtension 直接用的是 Constructor,没有实例化。无法访问实例方法 destroy
|
|
1310
|
+
|
|
1311
|
+
this.extensions.set(pluginName, {
|
|
1312
|
+
[pluginFlag]: pluginFlag,
|
|
1313
|
+
extension,
|
|
1314
|
+
props,
|
|
1315
|
+
})
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
private installPlugins(disabledPlugins: string[] = []) {
|
|
1319
|
+
// 安装插件,优先使用个性插件
|
|
1320
|
+
const extensions = this.plugins ?? LogicFlow.extensions
|
|
1321
|
+
extensions.forEach((ext: any) => {
|
|
1322
|
+
let extension: any
|
|
1323
|
+
let props = null
|
|
1324
|
+
if (ext[pluginFlag]) {
|
|
1325
|
+
extension = ext.extension
|
|
1326
|
+
props = ext.props
|
|
1327
|
+
} else {
|
|
1328
|
+
extension = ext
|
|
1329
|
+
}
|
|
1330
|
+
const pluginName = extension?.pluginName || extension?.name
|
|
1331
|
+
if (disabledPlugins.indexOf(pluginName) === -1) {
|
|
1332
|
+
this.installPlugin(extension, props)
|
|
1333
|
+
}
|
|
1334
|
+
})
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* 加载插件-内部方法
|
|
1339
|
+
*/
|
|
1340
|
+
private installPlugin(extension: Extension, props: any) {
|
|
1341
|
+
if (typeof extension === 'object') {
|
|
1342
|
+
const { pluginName, install, render: renderComponent } = extension
|
|
1343
|
+
if (pluginName) {
|
|
1344
|
+
install && install.call(extension, this, LogicFlow)
|
|
1345
|
+
renderComponent && this.components.push(renderComponent.bind(extension))
|
|
1346
|
+
this.extension[pluginName] = extension
|
|
1347
|
+
}
|
|
1348
|
+
return
|
|
1349
|
+
}
|
|
1350
|
+
const ExtensionCls = extension as ExtensionConstructor
|
|
1351
|
+
const extensionInstance = new ExtensionCls({
|
|
1352
|
+
lf: this,
|
|
1353
|
+
LogicFlow,
|
|
1354
|
+
options: this.options.pluginsOptions ?? {},
|
|
1355
|
+
props,
|
|
1356
|
+
})
|
|
1357
|
+
extensionInstance.render &&
|
|
1358
|
+
this.components.push(extensionInstance.render.bind(extensionInstance))
|
|
1359
|
+
this.extension[ExtensionCls.pluginName] = extensionInstance
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// Option
|
|
1364
|
+
export namespace LogicFlow {
|
|
1365
|
+
export interface Options extends LFOptions.Common {}
|
|
1366
|
+
|
|
1367
|
+
export type DomAttributes = {
|
|
1368
|
+
className?: string
|
|
1369
|
+
[key: string]: string | undefined
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
export type PropertiesType = {
|
|
1373
|
+
width?: number
|
|
1374
|
+
height?: number
|
|
1375
|
+
rx?: number
|
|
1376
|
+
ry?: number
|
|
1377
|
+
} & Record<string, any>
|
|
1378
|
+
export type AttributesType = Record<string, any>
|
|
1379
|
+
export type VectorData = {
|
|
1380
|
+
deltaX: number
|
|
1381
|
+
deltaY: number
|
|
1382
|
+
}
|
|
1383
|
+
export type OffsetData = {
|
|
1384
|
+
dx: number
|
|
1385
|
+
dy: number
|
|
1386
|
+
}
|
|
1387
|
+
export type Position = {
|
|
1388
|
+
x: number
|
|
1389
|
+
y: number
|
|
1390
|
+
}
|
|
1391
|
+
export type Point = {
|
|
1392
|
+
id?: string
|
|
1393
|
+
[key: string]: any
|
|
1394
|
+
} & Position
|
|
1395
|
+
export type PointTuple = [number, number]
|
|
1396
|
+
export type ClientPosition = {
|
|
1397
|
+
domOverlayPosition: Position
|
|
1398
|
+
canvasOverlayPosition: Position
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
export interface LineSegment {
|
|
1402
|
+
start: Point
|
|
1403
|
+
end: Point
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
export type Direction = SegmentDirection
|
|
1407
|
+
export type RadiusCircleInfo = {
|
|
1408
|
+
r: number
|
|
1409
|
+
} & Position
|
|
1410
|
+
export type Vector = {
|
|
1411
|
+
id?: string
|
|
1412
|
+
x: number
|
|
1413
|
+
y: number
|
|
1414
|
+
z: 0
|
|
1415
|
+
[key: string]: any
|
|
1416
|
+
}
|
|
1417
|
+
export type RectSize = {
|
|
1418
|
+
width: number
|
|
1419
|
+
height: number
|
|
1420
|
+
}
|
|
1421
|
+
export type TextConfig = {
|
|
1422
|
+
value: string
|
|
1423
|
+
editable?: boolean
|
|
1424
|
+
draggable?: boolean
|
|
1425
|
+
} & Point
|
|
1426
|
+
|
|
1427
|
+
export type AppendConfig = {
|
|
1428
|
+
startIndex: number
|
|
1429
|
+
endIndex: number
|
|
1430
|
+
direction: Direction
|
|
1431
|
+
draggable?: boolean
|
|
1432
|
+
} & LineSegment
|
|
1433
|
+
|
|
1434
|
+
export type ArrowConfig = {
|
|
1435
|
+
markerStart: string
|
|
1436
|
+
markerEnd: string
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
export type ArrowInfo = {
|
|
1440
|
+
start: Point
|
|
1441
|
+
end: Point
|
|
1442
|
+
hover: boolean
|
|
1443
|
+
isSelected: boolean
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
export interface GraphConfigData {
|
|
1447
|
+
nodes?: NodeConfig[]
|
|
1448
|
+
edges?: EdgeConfig[]
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
export interface GraphData {
|
|
1452
|
+
nodes: NodeData[]
|
|
1453
|
+
edges: EdgeData[]
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
export interface FakeNodeConfig {
|
|
1457
|
+
type: string
|
|
1458
|
+
text?: TextConfig | string
|
|
1459
|
+
properties?: PropertiesType
|
|
1460
|
+
|
|
1461
|
+
[key: string]: unknown
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// DnD 拖拽插件使用的 NodeConfig
|
|
1465
|
+
export type OnDragNodeConfig = {
|
|
1466
|
+
type: string
|
|
1467
|
+
text?: TextConfig | string
|
|
1468
|
+
properties?: Record<string, unknown>
|
|
1469
|
+
[key: string]: any
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
export interface NodeConfig {
|
|
1473
|
+
id?: string
|
|
1474
|
+
type: string
|
|
1475
|
+
x: number
|
|
1476
|
+
y: number
|
|
1477
|
+
text?: TextConfig | string
|
|
1478
|
+
zIndex?: number
|
|
1479
|
+
properties?: PropertiesType
|
|
1480
|
+
virtual?: boolean // 是否虚拟节点
|
|
1481
|
+
rotate?: number
|
|
1482
|
+
|
|
1483
|
+
[key: string]: any
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
export interface NodeData extends NodeConfig {
|
|
1487
|
+
id: string
|
|
1488
|
+
text?: TextConfig
|
|
1489
|
+
|
|
1490
|
+
[key: string]: unknown
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
export interface EdgeConfig {
|
|
1494
|
+
id?: string
|
|
1495
|
+
type?: string // TODO: 将所有类型选项列出来;LogicFlow 内部默认为 polyline
|
|
1496
|
+
|
|
1497
|
+
sourceNodeId: string
|
|
1498
|
+
sourceAnchorId?: string
|
|
1499
|
+
targetNodeId: string
|
|
1500
|
+
targetAnchorId?: string
|
|
1501
|
+
|
|
1502
|
+
startPoint?: Point
|
|
1503
|
+
endPoint?: Point
|
|
1504
|
+
text?: TextConfig | string
|
|
1505
|
+
pointsList?: Point[]
|
|
1506
|
+
zIndex?: number
|
|
1507
|
+
properties?: PropertiesType
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
export interface EdgeData extends EdgeConfig {
|
|
1511
|
+
id: string
|
|
1512
|
+
type: string
|
|
1513
|
+
text?: TextConfig
|
|
1514
|
+
startPoint: Point
|
|
1515
|
+
endPoint: Point
|
|
1516
|
+
|
|
1517
|
+
[key: string]: unknown
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
export interface MenuConfig {
|
|
1521
|
+
text?: string
|
|
1522
|
+
className?: string
|
|
1523
|
+
icon?: boolean
|
|
1524
|
+
callback: (id: string | number) => void
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
// Theme
|
|
1529
|
+
export namespace LogicFlow {
|
|
1530
|
+
export type NumberOrPercent = `${number}%` | number
|
|
1531
|
+
/**
|
|
1532
|
+
* 颜色 - CSS 属性用颜色
|
|
1533
|
+
* 如:#000000, rgba(0, 0, 0, 0), 如果是透明的,可以传 'none'
|
|
1534
|
+
*/
|
|
1535
|
+
export type Color = string | 'none'
|
|
1536
|
+
/**
|
|
1537
|
+
* svg虚线
|
|
1538
|
+
* 格式为逗号分割字符串,如
|
|
1539
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-dasharray
|
|
1540
|
+
*/
|
|
1541
|
+
export type DashArray = string
|
|
1542
|
+
export type CommonTheme = {
|
|
1543
|
+
fill?: Color // 填充颜色
|
|
1544
|
+
stroke?: Color // 边框颜色
|
|
1545
|
+
strokeWidth?: number // 边框宽度 TODO: svg 实际可赋值类型:NumberOrPercent
|
|
1546
|
+
/**
|
|
1547
|
+
* 其他属性 - 我们会把你自定义的所有属性最终传递到 DOM 上
|
|
1548
|
+
* 详情请参考 svg 属性规范:
|
|
1549
|
+
* https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute
|
|
1550
|
+
* 注意: 请不要在主题中设置“形状属性”,例如:x、y、width、height、radius、r、rx、ry
|
|
1551
|
+
* @see https://docs.logic-flow.cn/docs/#/zh/api/themeApi?id=%e5%bd%a2%e7%8a%b6%e5%b1%9e%e6%80%a7)
|
|
1552
|
+
*/
|
|
1553
|
+
radius?: number
|
|
1554
|
+
rx?: number
|
|
1555
|
+
ry?: number
|
|
1556
|
+
path?: string
|
|
1557
|
+
[key: string]: unknown
|
|
1558
|
+
}
|
|
1559
|
+
export type CommonThemePropTypes = CommonTheme[keyof CommonTheme]
|
|
1560
|
+
|
|
1561
|
+
export type AppendAttributes = {
|
|
1562
|
+
d: string
|
|
1563
|
+
fill: string
|
|
1564
|
+
stroke: Color
|
|
1565
|
+
strokeWidth: number
|
|
1566
|
+
strokeDasharray: DashArray
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
export type ContainerTheme = {
|
|
1570
|
+
width?: string
|
|
1571
|
+
height?: string
|
|
1572
|
+
}
|
|
1573
|
+
// 节点 Shape 类型
|
|
1574
|
+
/**
|
|
1575
|
+
* rect 节点主题
|
|
1576
|
+
* svg基础图形-矩形
|
|
1577
|
+
* https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/rect
|
|
1578
|
+
*/
|
|
1579
|
+
export type RectTheme = CommonTheme
|
|
1580
|
+
/**
|
|
1581
|
+
* circle 节点主题
|
|
1582
|
+
* svg基础图形-圆形
|
|
1583
|
+
* https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/circle
|
|
1584
|
+
*/
|
|
1585
|
+
export type CircleTheme = CommonTheme
|
|
1586
|
+
/**
|
|
1587
|
+
* polygon 节点主题
|
|
1588
|
+
* svg基础图形-多边形
|
|
1589
|
+
* https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/polygon
|
|
1590
|
+
*/
|
|
1591
|
+
export type PolygonTheme = CommonTheme
|
|
1592
|
+
/**
|
|
1593
|
+
* ellipse 节点主题
|
|
1594
|
+
* svg基础图形-椭圆
|
|
1595
|
+
* https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/ellipse
|
|
1596
|
+
*/
|
|
1597
|
+
export type EllipseTheme = CommonTheme
|
|
1598
|
+
// 锚点样式(svg 基础图形 - 圆)
|
|
1599
|
+
export type AnchorTheme = {
|
|
1600
|
+
r?: number
|
|
1601
|
+
hover?: {
|
|
1602
|
+
r?: number
|
|
1603
|
+
} & CommonTheme
|
|
1604
|
+
} & CommonTheme
|
|
1605
|
+
|
|
1606
|
+
// 文本样式
|
|
1607
|
+
export type TextTheme = {
|
|
1608
|
+
color?: Color
|
|
1609
|
+
fontSize: number
|
|
1610
|
+
textWidth?: number
|
|
1611
|
+
lineHeight?: number
|
|
1612
|
+
textAnchor?: 'start' | 'middle' | 'end'
|
|
1613
|
+
dominantBaseline?:
|
|
1614
|
+
| 'auto'
|
|
1615
|
+
| 'text-bottom'
|
|
1616
|
+
| 'alphabetic'
|
|
1617
|
+
| 'ideographic'
|
|
1618
|
+
| 'middle'
|
|
1619
|
+
| 'central'
|
|
1620
|
+
| 'mathematical'
|
|
1621
|
+
| 'hanging'
|
|
1622
|
+
| 'text-top'
|
|
1623
|
+
} & CommonTheme
|
|
1624
|
+
|
|
1625
|
+
// 文本节点样式
|
|
1626
|
+
export type TextNodeTheme = {
|
|
1627
|
+
background?: RectTheme
|
|
1628
|
+
} & TextTheme
|
|
1629
|
+
|
|
1630
|
+
// 节点上文本样式
|
|
1631
|
+
export type NodeTextTheme = {
|
|
1632
|
+
/**
|
|
1633
|
+
* 文本超出指定宽度处理方式
|
|
1634
|
+
* default: 不特殊处理,允许超出
|
|
1635
|
+
* autoWrap: 超出自动换行
|
|
1636
|
+
* ellipsis: 超出省略
|
|
1637
|
+
*/
|
|
1638
|
+
overflowMode?: 'default' | 'autoWrap' | 'ellipsis'
|
|
1639
|
+
background?: RectTheme
|
|
1640
|
+
/**
|
|
1641
|
+
* 背景区域 padding
|
|
1642
|
+
* wrapPadding: '5px,10px'
|
|
1643
|
+
*/
|
|
1644
|
+
wrapPadding?: string
|
|
1645
|
+
} & TextTheme
|
|
1646
|
+
// 边上文本样式
|
|
1647
|
+
export type EdgeTextTheme = {
|
|
1648
|
+
textWidth: number
|
|
1649
|
+
background?: {
|
|
1650
|
+
/**
|
|
1651
|
+
* 背景区域 padding
|
|
1652
|
+
* wrapPadding: '5px,10px'
|
|
1653
|
+
*/
|
|
1654
|
+
wrapPadding?: string
|
|
1655
|
+
} & RectTheme
|
|
1656
|
+
// hover状态下文本样式
|
|
1657
|
+
hover?: EdgeTextTheme
|
|
1658
|
+
} & NodeTextTheme &
|
|
1659
|
+
TextTheme
|
|
1660
|
+
|
|
1661
|
+
// 边 Edge 主题
|
|
1662
|
+
export type EdgeTheme = CommonTheme
|
|
1663
|
+
export type EdgeBezierTheme = {
|
|
1664
|
+
// 贝塞尔调整线主题
|
|
1665
|
+
adjustLine?: EdgeTheme
|
|
1666
|
+
// 贝塞尔调整锚点主题
|
|
1667
|
+
adjustAnchor?: CircleTheme
|
|
1668
|
+
} & EdgeTheme
|
|
1669
|
+
export type EdgePolylineTheme = EdgeTheme
|
|
1670
|
+
export type EdgeAnimation = {
|
|
1671
|
+
stroke?: Color
|
|
1672
|
+
strokeDasharray?: string
|
|
1673
|
+
strokeDashoffset?: NumberOrPercent
|
|
1674
|
+
animationName?: string
|
|
1675
|
+
animationDuration?: `${number}s` | `${number}ms`
|
|
1676
|
+
animationIterationCount?: 'infinite' | number
|
|
1677
|
+
animationTimingFunction?: string
|
|
1678
|
+
animationDirection?: string
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
export type OutlineTheme = {
|
|
1682
|
+
hover?: CommonTheme
|
|
1683
|
+
} & CommonTheme &
|
|
1684
|
+
EdgeAnimation
|
|
1685
|
+
|
|
1686
|
+
export type ArrowTheme = {
|
|
1687
|
+
/**
|
|
1688
|
+
* 箭头长度.
|
|
1689
|
+
* 以符号"->"为例, offset表示箭头大于号的宽度。
|
|
1690
|
+
*/
|
|
1691
|
+
offset: number
|
|
1692
|
+
/**
|
|
1693
|
+
* 箭头垂直于边的距离
|
|
1694
|
+
* 以符号"->"为例, verticalLength表示箭头大于号的高度
|
|
1695
|
+
*/
|
|
1696
|
+
refX?: number
|
|
1697
|
+
refY?: number
|
|
1698
|
+
verticalLength: number
|
|
1699
|
+
} & CommonTheme
|
|
1700
|
+
export type ArrowAttributesType = {
|
|
1701
|
+
d: string
|
|
1702
|
+
} & ArrowTheme
|
|
1703
|
+
|
|
1704
|
+
export type AnchorLineTheme = EdgeTheme & EdgeAnimation
|
|
1705
|
+
|
|
1706
|
+
export interface Theme {
|
|
1707
|
+
baseNode: CommonTheme // 所有节点的通用主题设置
|
|
1708
|
+
baseEdge: EdgeTheme // 所有边的通用主题设置
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* 基础图形节点相关主题
|
|
1712
|
+
*/
|
|
1713
|
+
rect: RectTheme // 矩形样式
|
|
1714
|
+
circle: CircleTheme // 圆形样式
|
|
1715
|
+
diamond: PolygonTheme // 菱形样式
|
|
1716
|
+
ellipse: EllipseTheme // 椭圆样式
|
|
1717
|
+
polygon: PolygonTheme // 多边形样式
|
|
1718
|
+
|
|
1719
|
+
/**
|
|
1720
|
+
* 基础图形线相关主题
|
|
1721
|
+
*/
|
|
1722
|
+
line: EdgeTheme // 直线样式
|
|
1723
|
+
polyline: EdgePolylineTheme // 折现样式
|
|
1724
|
+
bezier: EdgeBezierTheme // 贝塞尔曲线样式
|
|
1725
|
+
anchorLine: AnchorLineTheme // 从锚点拉出的边的样式
|
|
1726
|
+
|
|
1727
|
+
/**
|
|
1728
|
+
* 文本内容相关主题
|
|
1729
|
+
*/
|
|
1730
|
+
text: TextNodeTheme // 文本节点样式
|
|
1731
|
+
nodeText: NodeTextTheme // 节点文本样式
|
|
1732
|
+
edgeText: EdgeTextTheme // 边文本样式
|
|
1733
|
+
inputText?: CommonTheme
|
|
1734
|
+
|
|
1735
|
+
/**
|
|
1736
|
+
* 其他元素相关主题
|
|
1737
|
+
*/
|
|
1738
|
+
anchor: AnchorTheme // 锚点样式
|
|
1739
|
+
arrow: ArrowTheme // 边上箭头的样式
|
|
1740
|
+
snapline: EdgeTheme // 对齐线样式
|
|
1741
|
+
rotateControl: CommonTheme // 节点旋转控制点样式
|
|
1742
|
+
resizeControl: CommonTheme // 节点旋转控制点样式
|
|
1743
|
+
resizeOutline: CommonTheme // 节点调整大小时的外框样式
|
|
1744
|
+
|
|
1745
|
+
/**
|
|
1746
|
+
* REMIND: 当开启了跳转边的起点和终点(adjustEdgeStartAndEnd:true)后
|
|
1747
|
+
* 边的两端会出现调整按钮
|
|
1748
|
+
* 边连段的调整点样式
|
|
1749
|
+
*/
|
|
1750
|
+
edgeAdjust: CircleTheme
|
|
1751
|
+
outline: OutlineTheme // 节点选择状态下外侧的选框样式
|
|
1752
|
+
edgeAnimation: EdgeAnimation // 边动画样式
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
// Render or Functions
|
|
1757
|
+
export namespace LogicFlow {
|
|
1758
|
+
type FocusOnById = { id: string; coordinate?: never }
|
|
1759
|
+
type FocusOnByCoordinate = { id?: string; coordinate: Position }
|
|
1760
|
+
export type FocusOnArgsType = FocusOnById | FocusOnByCoordinate
|
|
1761
|
+
|
|
1762
|
+
export type BaseNodeModelCtor = typeof BaseNodeModel
|
|
1763
|
+
export type BaseEdgeModelCtor = typeof BaseEdgeModel
|
|
1764
|
+
|
|
1765
|
+
export type GraphElementCtor = BaseNodeModelCtor | BaseEdgeModelCtor
|
|
1766
|
+
export type GraphElement = BaseNodeModel | BaseEdgeModel
|
|
1767
|
+
export type GraphElements = {
|
|
1768
|
+
nodes: BaseNodeModel[]
|
|
1769
|
+
edges: BaseEdgeModel[]
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
export type RegisterConfig = {
|
|
1773
|
+
type: string
|
|
1774
|
+
// TODO: 确认 View 类型中 props 类型该如何动态获取真实组件的 props
|
|
1775
|
+
view: ComponentType<any> & {
|
|
1776
|
+
isObserved?: boolean
|
|
1777
|
+
}
|
|
1778
|
+
model: GraphElementCtor // TODO: 确认 model 的类型
|
|
1779
|
+
isObserverView?: boolean
|
|
1780
|
+
}
|
|
1781
|
+
export type RegisterElement = {
|
|
1782
|
+
view: any
|
|
1783
|
+
model: any
|
|
1784
|
+
}
|
|
1785
|
+
export type RegisterParam = {
|
|
1786
|
+
h: typeof h
|
|
1787
|
+
// 当前项目中定义的节点 or 连线的 View 或 Model
|
|
1788
|
+
// ...
|
|
1789
|
+
[key: string]: unknown
|
|
1790
|
+
}
|
|
1791
|
+
export type RegisterElementFunc = (params: RegisterParam) => RegisterElement
|
|
1792
|
+
|
|
1793
|
+
export interface LogicFlowConstructor {
|
|
1794
|
+
new (options: LFOptions.Definition): LogicFlow
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
export type RegisteredExtension = {
|
|
1798
|
+
[pluginFlag]: symbol
|
|
1799
|
+
extension: ExtensionConstructor
|
|
1800
|
+
props?: Record<string, unknown>
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
export type ExtensionProps = {
|
|
1804
|
+
lf: LogicFlow
|
|
1805
|
+
LogicFlow: LogicFlowConstructor
|
|
1806
|
+
options: Record<string, unknown>
|
|
1807
|
+
props?: Record<string, unknown>
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
export interface ExtensionConstructor {
|
|
1811
|
+
pluginName: string
|
|
1812
|
+
|
|
1813
|
+
new (props: ExtensionProps): Extension
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
export type ExtensionRender = (lf: LogicFlow, container: HTMLElement) => void
|
|
1817
|
+
|
|
1818
|
+
export interface Extension {
|
|
1819
|
+
readonly pluginName?: string // 插件名称,只用用于插件覆盖和细粒度控制加载哪些插件
|
|
1820
|
+
install?: (lf: LogicFlow, logicFlow: LogicFlowConstructor) => void
|
|
1821
|
+
render?: ExtensionRender
|
|
1822
|
+
destroy?: () => void
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
// toStringTag
|
|
1827
|
+
export namespace LogicFlow {
|
|
1828
|
+
export const toStringTag = `LF.${LogicFlow.name}`
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
export default LogicFlow
|