@likec4/diagram 1.18.0 → 1.19.1
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/LICENSE +1 -1
- package/dist/LikeC4CustomColors.d.ts +7 -0
- package/dist/LikeC4CustomColors.js +30 -0
- package/dist/LikeC4Diagram.css.d.ts +5 -0
- package/dist/LikeC4Diagram.css.js +13 -0
- package/dist/LikeC4Diagram.d.ts +6 -0
- package/dist/LikeC4Diagram.js +194 -0
- package/dist/LikeC4Diagram.props.d.ts +166 -0
- package/dist/LikeC4ModelProvider.d.ts +9 -0
- package/dist/LikeC4ModelProvider.js +12 -0
- package/dist/LikeC4Search.css.d.ts +1 -0
- package/dist/LikeC4Search.css.js +5 -0
- package/dist/LikeC4Search.d.ts +2 -0
- package/dist/LikeC4Search.js +96 -0
- package/dist/StaticLikeC4Diagram.d.ts +3 -0
- package/dist/StaticLikeC4Diagram.js +41 -0
- package/dist/_virtual/_commonjsHelpers.js +6 -0
- package/dist/controls/Text.d.ts +2 -0
- package/dist/controls/Text.js +7 -0
- package/dist/controls/action-button-bar/ActionButtonBar.css.d.ts +1 -0
- package/dist/controls/action-button-bar/ActionButtonBar.css.js +5 -0
- package/dist/controls/action-button-bar/ActionButtonBar.d.ts +9 -0
- package/dist/controls/action-button-bar/ActionButtonBar.js +100 -0
- package/dist/controls/action-button-bar/useActionButtonBarCtx.d.ts +10 -0
- package/dist/controls/action-button-bar/useActionButtonBarCtx.js +9 -0
- package/dist/controls/action-buttons/ActionButton.css.d.ts +1 -0
- package/dist/controls/action-buttons/ActionButton.css.js +5 -0
- package/dist/controls/action-buttons/ActionButton.d.ts +9 -0
- package/dist/controls/action-buttons/ActionButton.js +66 -0
- package/dist/controls/action-buttons/ActionButtons.d.ts +12 -0
- package/dist/controls/action-buttons/ActionButtons.js +99 -0
- package/dist/globals.css.d.ts +1 -0
- package/dist/globals.css.js +92 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useDiagramState.d.ts +6 -0
- package/dist/hooks/useDiagramState.js +27 -0
- package/dist/hooks/useMantinePortalProps.d.ts +9 -0
- package/dist/hooks/useMantinePortalProps.js +9 -0
- package/dist/hooks/useSetState.d.ts +2 -0
- package/dist/hooks/useSetState.js +19 -0
- package/dist/hooks/useUpdateEffect.d.ts +4 -0
- package/dist/hooks/useUpdateEffect.js +32 -0
- package/dist/hooks/useXYFlow.d.ts +270 -0
- package/dist/hooks/useXYFlow.js +20 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +25 -0
- package/dist/likec4model/LikeC4ModelContext.d.ts +3 -0
- package/dist/likec4model/LikeC4ModelContext.js +5 -0
- package/dist/likec4model/index.d.ts +2 -0
- package/dist/likec4model/useLikeC4ElementsTree.d.ts +12 -0
- package/dist/likec4model/useLikeC4ElementsTree.js +25 -0
- package/dist/likec4model/useLikeC4Model.d.ts +20 -0
- package/dist/likec4model/useLikeC4Model.js +55 -0
- package/dist/overlays/OverlayContext.d.ts +10 -0
- package/dist/overlays/OverlayContext.js +9 -0
- package/dist/overlays/Overlays.css.d.ts +3 -0
- package/dist/overlays/Overlays.css.js +7 -0
- package/dist/overlays/Overlays.d.ts +2 -0
- package/dist/overlays/Overlays.js +137 -0
- package/dist/overlays/edge-details/EdgeDetailsXYFlow.d.ts +5 -0
- package/dist/overlays/edge-details/EdgeDetailsXYFlow.js +185 -0
- package/dist/overlays/edge-details/SelectEdge.css.d.ts +7 -0
- package/dist/overlays/edge-details/SelectEdge.css.js +17 -0
- package/dist/overlays/edge-details/SelectEdge.d.ts +5 -0
- package/dist/overlays/edge-details/SelectEdge.js +129 -0
- package/dist/overlays/edge-details/_types.d.ts +14 -0
- package/dist/overlays/edge-details/use-layouted-edge-details.d.ts +21 -0
- package/dist/overlays/edge-details/use-layouted-edge-details.js +270 -0
- package/dist/overlays/edge-details/xyflow/CompoundNode.d.ts +5 -0
- package/dist/overlays/edge-details/xyflow/CompoundNode.js +76 -0
- package/dist/overlays/edge-details/xyflow/ElementNode.d.ts +5 -0
- package/dist/overlays/edge-details/xyflow/ElementNode.js +159 -0
- package/dist/overlays/edge-details/xyflow/RelationshipEdge.d.ts +3 -0
- package/dist/overlays/edge-details/xyflow/RelationshipEdge.js +84 -0
- package/dist/overlays/edge-details/xyflow/styles.css.d.ts +9 -0
- package/dist/overlays/edge-details/xyflow/styles.css.js +21 -0
- package/dist/overlays/element-details/ElementDetailsCard.css.d.ts +16 -0
- package/dist/overlays/element-details/ElementDetailsCard.css.js +33 -0
- package/dist/overlays/element-details/ElementDetailsCard.d.ts +7 -0
- package/dist/overlays/element-details/ElementDetailsCard.js +484 -0
- package/dist/overlays/element-details/TabPanelDeployments.css.d.ts +4 -0
- package/dist/overlays/element-details/TabPanelDeployments.css.js +11 -0
- package/dist/overlays/element-details/TabPanelDeployments.d.ts +7 -0
- package/dist/overlays/element-details/TabPanelDeployments.js +173 -0
- package/dist/overlays/element-details/TabPanelRelationships.css.d.ts +5 -0
- package/dist/overlays/element-details/TabPanelRelationships.css.js +11 -0
- package/dist/overlays/element-details/TabPanelRelationships.d.ts +8 -0
- package/dist/overlays/element-details/TabPanelRelationships.js +157 -0
- package/dist/overlays/element-details/TabPanelStructure.css.d.ts +2 -0
- package/dist/overlays/element-details/TabPanelStructure.css.js +7 -0
- package/dist/overlays/element-details/TabPanelStructure.d.ts +25 -0
- package/dist/overlays/element-details/TabPanelStructure.js +91 -0
- package/dist/overlays/index.d.ts +1 -0
- package/dist/overlays/relationships-of/RelationshipsOverlay.d.ts +5 -0
- package/dist/overlays/relationships-of/RelationshipsOverlay.js +193 -0
- package/dist/overlays/relationships-of/RelationshipsXYFlow.d.ts +19 -0
- package/dist/overlays/relationships-of/RelationshipsXYFlow.js +290 -0
- package/dist/overlays/relationships-of/SelectElement.css.d.ts +2 -0
- package/dist/overlays/relationships-of/SelectElement.css.js +7 -0
- package/dist/overlays/relationships-of/SelectElement.d.ts +7 -0
- package/dist/overlays/relationships-of/SelectElement.js +126 -0
- package/dist/overlays/relationships-of/_types.d.ts +28 -0
- package/dist/overlays/relationships-of/use-layouted-relationships.d.ts +22 -0
- package/dist/overlays/relationships-of/use-layouted-relationships.js +496 -0
- package/dist/overlays/relationships-of/xyflow/CompoundNode.d.ts +6 -0
- package/dist/overlays/relationships-of/xyflow/CompoundNode.js +120 -0
- package/dist/overlays/relationships-of/xyflow/ElementNode.d.ts +6 -0
- package/dist/overlays/relationships-of/xyflow/ElementNode.js +194 -0
- package/dist/overlays/relationships-of/xyflow/EmptyNode.d.ts +5 -0
- package/dist/overlays/relationships-of/xyflow/EmptyNode.js +18 -0
- package/dist/overlays/relationships-of/xyflow/RelationshipEdge.d.ts +3 -0
- package/dist/overlays/relationships-of/xyflow/RelationshipEdge.js +123 -0
- package/dist/overlays/relationships-of/xyflow/styles.css.d.ts +14 -0
- package/dist/overlays/relationships-of/xyflow/styles.css.js +24 -0
- package/dist/overlays/shared/xyflow/RelationshipEdge.css.d.ts +4 -0
- package/dist/overlays/shared/xyflow/RelationshipEdge.css.js +12 -0
- package/dist/overlays/shared/xyflow/_types.d.ts +77 -0
- package/dist/state/DiagramContext.d.ts +1609 -0
- package/dist/state/DiagramContext.js +101 -0
- package/dist/state/aligners.d.ts +42 -0
- package/dist/state/aligners.js +349 -0
- package/dist/state/diagram-to-xyflow.d.ts +11 -0
- package/dist/state/diagram-to-xyflow.js +113 -0
- package/dist/state/diagramStore.d.ts +1705 -0
- package/dist/state/diagramStore.js +808 -0
- package/dist/state/diagramStore.layout.d.ts +4 -0
- package/dist/state/diagramStore.layout.js +56 -0
- package/dist/style.css +1 -0
- package/dist/theme-vars.css.d.ts +72 -0
- package/dist/theme-vars.css.js +6 -0
- package/dist/theme-vars.css.ts.vanilla.css.js +1 -0
- package/dist/theme-vars.d.ts +3 -0
- package/dist/theme-vars.js +5 -0
- package/dist/ui/DiagramTitlePanel.css.d.ts +4 -0
- package/dist/ui/DiagramTitlePanel.css.js +11 -0
- package/dist/ui/DiagramTitlePanel.d.ts +1 -0
- package/dist/ui/DiagramTitlePanel.js +159 -0
- package/dist/ui/DynamicViewWalkthrough.css.d.ts +4 -0
- package/dist/ui/DynamicViewWalkthrough.css.js +11 -0
- package/dist/ui/DynamicViewWalkthrough.d.ts +1 -0
- package/dist/ui/DynamicViewWalkthrough.js +156 -0
- package/dist/ui/EnsureMantine.d.ts +7 -0
- package/dist/ui/EnsureMantine.js +14 -0
- package/dist/ui/FramerMotionConfig.d.ts +2 -0
- package/dist/ui/FramerMotionConfig.js +14 -0
- package/dist/ui/Link.d.ts +4 -0
- package/dist/ui/Link.js +36 -0
- package/dist/ui/notation/NotationPanel.css.d.ts +6 -0
- package/dist/ui/notation/NotationPanel.css.js +16 -0
- package/dist/ui/notation/NotationPanel.d.ts +1 -0
- package/dist/ui/notation/NotationPanel.js +250 -0
- package/dist/ui/notation/index.d.ts +1 -0
- package/dist/ui/top-left/ChangeAutoLayoutButton.d.ts +2 -0
- package/dist/ui/top-left/ChangeAutoLayoutButton.js +159 -0
- package/dist/ui/top-left/ManualLayoutToolsButton.d.ts +2 -0
- package/dist/ui/top-left/ManualLayoutToolsButton.js +137 -0
- package/dist/ui/top-left/TopLeftPanel.d.ts +4 -0
- package/dist/ui/top-left/TopLeftPanel.js +211 -0
- package/dist/ui/top-left/_shared.d.ts +7 -0
- package/dist/ui/top-left/_shared.js +22 -0
- package/dist/ui/top-left/styles.css.d.ts +8 -0
- package/dist/ui/top-left/styles.css.js +17 -0
- package/dist/utils/types.d.ts +8 -0
- package/dist/utils/vector.d.ts +24 -0
- package/dist/utils/vector.js +55 -0
- package/dist/xyflow/EdgeMarkers.d.ts +12 -0
- package/dist/xyflow/EdgeMarkers.js +192 -0
- package/dist/xyflow/FitviewOnDiagramChange.d.ts +4 -0
- package/dist/xyflow/FitviewOnDiagramChange.js +72 -0
- package/dist/xyflow/SelectEdgesOnNodeFocus.d.ts +1 -0
- package/dist/xyflow/SelectEdgesOnNodeFocus.js +96 -0
- package/dist/xyflow/XYFlow.d.ts +8 -0
- package/dist/xyflow/XYFlow.js +145 -0
- package/dist/xyflow/XYFlowBackground.d.ts +10 -0
- package/dist/xyflow/XYFlowBackground.js +25 -0
- package/dist/xyflow/XYFlowInner.d.ts +8 -0
- package/dist/xyflow/XYFlowInner.js +41 -0
- package/dist/xyflow/const.d.ts +7 -0
- package/dist/xyflow/const.js +12 -0
- package/dist/xyflow/edges/EdgeLabel.d.ts +7 -0
- package/dist/xyflow/edges/EdgeLabel.js +160 -0
- package/dist/xyflow/edges/RelationshipEdge.d.ts +6 -0
- package/dist/xyflow/edges/RelationshipEdge.js +443 -0
- package/dist/xyflow/edges/RelationshipsDropdownMenu.css.d.ts +4 -0
- package/dist/xyflow/edges/RelationshipsDropdownMenu.css.js +11 -0
- package/dist/xyflow/edges/RelationshipsDropdownMenu.d.ts +13 -0
- package/dist/xyflow/edges/RelationshipsDropdownMenu.js +211 -0
- package/dist/xyflow/edges/edges.css.d.ts +17 -0
- package/dist/xyflow/edges/edges.css.js +37 -0
- package/dist/xyflow/edges/utils.d.ts +16 -0
- package/dist/xyflow/edges/utils.js +24 -0
- package/dist/xyflow/nodes/AnimateVariants.d.ts +1313 -0
- package/dist/xyflow/nodes/AnimateVariants.js +123 -0
- package/dist/xyflow/nodes/Node.css.d.ts +3 -0
- package/dist/xyflow/nodes/Node.css.js +9 -0
- package/dist/xyflow/nodes/compound/CompoundNode.css.d.ts +14 -0
- package/dist/xyflow/nodes/compound/CompoundNode.css.js +27 -0
- package/dist/xyflow/nodes/compound/CompoundNode.d.ts +6 -0
- package/dist/xyflow/nodes/compound/CompoundNode.js +216 -0
- package/dist/xyflow/nodes/compound/index.d.ts +1 -0
- package/dist/xyflow/nodes/element/ElementLink.css.d.ts +3 -0
- package/dist/xyflow/nodes/element/ElementLink.d.ts +6 -0
- package/dist/xyflow/nodes/element/ElementNode.d.ts +6 -0
- package/dist/xyflow/nodes/element/ElementNode.js +190 -0
- package/dist/xyflow/nodes/element/ElementShapeSvg.d.ts +17 -0
- package/dist/xyflow/nodes/element/ElementShapeSvg.js +175 -0
- package/dist/xyflow/nodes/element/element.css.d.ts +18 -0
- package/dist/xyflow/nodes/element/element.css.js +31 -0
- package/dist/xyflow/nodes/element/index.d.ts +1 -0
- package/dist/xyflow/nodes/shared/ElementIcon.d.ts +8 -0
- package/dist/xyflow/nodes/shared/ElementIcon.js +38 -0
- package/dist/xyflow/nodes/shared/Toolbar.d.ts +9 -0
- package/dist/xyflow/nodes/shared/Toolbar.js +436 -0
- package/dist/xyflow/types.d.ts +36 -0
- package/dist/xyflow/useLayoutConstraints.d.ts +42 -0
- package/dist/xyflow/useLayoutConstraints.js +226 -0
- package/dist/xyflow/useXYFlowEvents.d.ts +160 -0
- package/dist/xyflow/useXYFlowEvents.js +275 -0
- package/dist/xyflow/utils.d.ts +22 -0
- package/dist/xyflow/utils.js +72 -0
- package/package.json +34 -27
- package/src/LikeC4Diagram.tsx +4 -4
- package/src/LikeC4Search.css.ts +12 -0
- package/src/LikeC4Search.tsx +39 -90
- package/src/controls/Text.ts +5 -0
- package/src/controls/action-button-bar/ActionButtonBar.css.ts +13 -0
- package/src/controls/action-button-bar/ActionButtonBar.tsx +138 -0
- package/src/controls/action-button-bar/useActionButtonBarCtx.ts +13 -0
- package/src/controls/action-buttons/ActionButton.css.ts +29 -0
- package/src/controls/action-buttons/ActionButton.tsx +66 -0
- package/src/controls/action-buttons/ActionButtons.tsx +138 -0
- package/src/hooks/useXYFlow.ts +8 -8
- package/src/index.ts +12 -6
- package/src/likec4model/index.ts +12 -2
- package/src/overlays/edge-details/EdgeDetailsXYFlow.tsx +18 -12
- package/src/overlays/edge-details/_types.ts +13 -37
- package/src/overlays/edge-details/use-layouted-edge-details.ts +16 -14
- package/src/overlays/edge-details/xyflow/CompoundNode.tsx +3 -11
- package/src/overlays/edge-details/xyflow/ElementNode.tsx +4 -11
- package/src/overlays/edge-details/xyflow/RelationshipEdge.tsx +3 -3
- package/src/overlays/edge-details/xyflow/styles.css.ts +1 -59
- package/src/overlays/relationships-of/RelationshipsXYFlow.tsx +23 -23
- package/src/overlays/relationships-of/_types.ts +20 -58
- package/src/overlays/relationships-of/use-layouted-relationships.ts +36 -40
- package/src/overlays/relationships-of/xyflow/CompoundNode.tsx +9 -13
- package/src/overlays/relationships-of/xyflow/ElementNode.tsx +12 -15
- package/src/overlays/relationships-of/xyflow/EmptyNode.tsx +4 -7
- package/src/overlays/relationships-of/xyflow/RelationshipEdge.tsx +16 -14
- package/src/overlays/shared/xyflow/RelationshipEdge.css.ts +60 -0
- package/src/overlays/shared/xyflow/_types.ts +87 -0
- package/src/state/diagram-to-xyflow.ts +6 -7
- package/src/state/diagramStore.layout.ts +3 -4
- package/src/state/diagramStore.ts +35 -37
- package/src/theme-vars.css.ts +81 -0
- package/src/theme-vars.ts +8 -81
- package/src/ui/DiagramTitlePanel.tsx +6 -6
- package/src/utils/types.ts +6 -0
- package/src/xyflow/SelectEdgesOnNodeFocus.tsx +3 -3
- package/src/xyflow/XYFlow.tsx +2 -2
- package/src/xyflow/edges/EdgeLabel.tsx +25 -18
- package/src/xyflow/edges/RelationshipEdge.tsx +5 -3
- package/src/xyflow/edges/RelationshipsDropdownMenu.tsx +3 -3
- package/src/xyflow/edges/edges.css.ts +68 -74
- package/src/xyflow/edges/utils.ts +6 -6
- package/src/xyflow/nodes/AnimateVariants.ts +143 -0
- package/src/xyflow/nodes/Node.css.ts +44 -0
- package/src/xyflow/nodes/compound/CompoundNode.css.ts +1 -64
- package/src/xyflow/nodes/compound/CompoundNode.tsx +69 -182
- package/src/xyflow/nodes/element/ElementLink.tsx +2 -3
- package/src/xyflow/nodes/element/ElementNode.tsx +64 -266
- package/src/xyflow/nodes/element/element.css.ts +0 -57
- package/src/xyflow/nodes/shared/Toolbar.tsx +30 -30
- package/src/xyflow/types.ts +48 -51
- package/src/xyflow/useLayoutConstraints.ts +9 -9
- package/src/xyflow/useXYFlowEvents.ts +13 -30
- package/src/xyflow/utils.ts +2 -2
- package/src/xyflow/nodes/use-animate-variants.tsx +0 -64
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { nonNullable } from "@likec4/core";
|
|
5
|
+
import { getNodeDimensions } from "@xyflow/system";
|
|
6
|
+
import { useRef, useMemo } from "react";
|
|
7
|
+
import { pipe, filter, map, hasAtLeast, isNullish } from "remeda";
|
|
8
|
+
import { useDiagramStoreApi } from "../hooks/useDiagramState.js";
|
|
9
|
+
class Rect {
|
|
10
|
+
constructor() {
|
|
11
|
+
__publicField(this, "id");
|
|
12
|
+
__publicField(this, "minX", Infinity);
|
|
13
|
+
__publicField(this, "minY", Infinity);
|
|
14
|
+
__publicField(this, "maxX", -Infinity);
|
|
15
|
+
__publicField(this, "maxY", -Infinity);
|
|
16
|
+
}
|
|
17
|
+
get positionAbsolute() {
|
|
18
|
+
return {
|
|
19
|
+
x: this.minX,
|
|
20
|
+
y: this.minY
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
set positionAbsolute(pos) {
|
|
24
|
+
this.maxX += pos.x - this.minX;
|
|
25
|
+
this.maxY += pos.y - this.minY;
|
|
26
|
+
this.minX = pos.x;
|
|
27
|
+
this.minY = pos.y;
|
|
28
|
+
}
|
|
29
|
+
get dimensions() {
|
|
30
|
+
return {
|
|
31
|
+
width: this.maxX - this.minX,
|
|
32
|
+
height: this.maxY - this.minY
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Position relative to parent
|
|
36
|
+
get position() {
|
|
37
|
+
const positionAbsolute = this.positionAbsolute;
|
|
38
|
+
if (!this.parent) {
|
|
39
|
+
return positionAbsolute;
|
|
40
|
+
}
|
|
41
|
+
const parentPosition = this.parent.positionAbsolute;
|
|
42
|
+
return {
|
|
43
|
+
x: positionAbsolute.x - parentPosition.x,
|
|
44
|
+
y: positionAbsolute.y - parentPosition.y
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
__publicField(Rect, "LeftPadding", 40);
|
|
49
|
+
__publicField(Rect, "RightPadding", 40);
|
|
50
|
+
__publicField(Rect, "TopPadding", 55);
|
|
51
|
+
__publicField(Rect, "BottomPadding", 40);
|
|
52
|
+
class Compound extends Rect {
|
|
53
|
+
constructor(xynode, parent = null) {
|
|
54
|
+
super();
|
|
55
|
+
__publicField(this, "children", []);
|
|
56
|
+
this.parent = parent;
|
|
57
|
+
this.id = xynode.id;
|
|
58
|
+
if (parent) {
|
|
59
|
+
parent.children.push(this);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class Leaf extends Rect {
|
|
64
|
+
constructor(xynode, parent = null) {
|
|
65
|
+
super();
|
|
66
|
+
this.parent = parent;
|
|
67
|
+
this.id = xynode.id;
|
|
68
|
+
this.positionAbsolute = xynode.internals.positionAbsolute;
|
|
69
|
+
const { width, height } = getNodeDimensions(xynode);
|
|
70
|
+
this.maxX = this.minX + Math.ceil(width);
|
|
71
|
+
this.maxY = this.minY + Math.ceil(height);
|
|
72
|
+
if (parent) {
|
|
73
|
+
parent.children.push(this);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function createLayoutConstraints(xyflowApi, editingNodeIds) {
|
|
78
|
+
var _a;
|
|
79
|
+
const { parentLookup, nodeLookup } = xyflowApi.getState();
|
|
80
|
+
const rects = /* @__PURE__ */ new Map();
|
|
81
|
+
const ancestorsOf = (nodeId) => {
|
|
82
|
+
const ancestors = [];
|
|
83
|
+
const xynode = nodeLookup.get(nodeId);
|
|
84
|
+
let parent = xynode == null ? void 0 : xynode.parentId;
|
|
85
|
+
let parentNode;
|
|
86
|
+
while (parent && (parentNode = nodeLookup.get(parent))) {
|
|
87
|
+
ancestors.push(parentNode.id);
|
|
88
|
+
parent = parentNode.parentId;
|
|
89
|
+
}
|
|
90
|
+
return ancestors;
|
|
91
|
+
};
|
|
92
|
+
const ancestorsOfDraggingNodes = new Set(
|
|
93
|
+
editingNodeIds.flatMap(ancestorsOf)
|
|
94
|
+
);
|
|
95
|
+
const traverse = new Array();
|
|
96
|
+
for (const [, xynode] of nodeLookup) {
|
|
97
|
+
if (isNullish(xynode.parentId)) {
|
|
98
|
+
traverse.push({
|
|
99
|
+
xynode,
|
|
100
|
+
parent: null
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
while (traverse.length > 0) {
|
|
105
|
+
const { xynode, parent } = traverse.shift();
|
|
106
|
+
const isEditing = editingNodeIds.includes(xynode.id);
|
|
107
|
+
const shouldTraverse = !isEditing && xynode.type === "compound" && ancestorsOfDraggingNodes.has(xynode.id);
|
|
108
|
+
const rect = shouldTraverse ? new Compound(xynode, parent) : new Leaf(xynode, parent);
|
|
109
|
+
rects.set(xynode.id, rect);
|
|
110
|
+
if (shouldTraverse) {
|
|
111
|
+
(_a = parentLookup.get(xynode.id)) == null ? void 0 : _a.forEach((child) => {
|
|
112
|
+
traverse.push({
|
|
113
|
+
xynode: child,
|
|
114
|
+
parent: rect
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const rectsToUpdate = [...rects.values()];
|
|
120
|
+
applyConstraints(rectsToUpdate);
|
|
121
|
+
function applyConstraints(targets) {
|
|
122
|
+
targets.filter((x) => x instanceof Compound).forEach((r) => {
|
|
123
|
+
applyConstraints(r.children);
|
|
124
|
+
const childrenBB = r.children.reduce((acc, r2) => ({
|
|
125
|
+
minX: Math.min(acc.minX, r2.minX),
|
|
126
|
+
minY: Math.min(acc.minY, r2.minY),
|
|
127
|
+
maxX: Math.max(acc.maxX, r2.maxX),
|
|
128
|
+
maxY: Math.max(acc.maxY, r2.maxY)
|
|
129
|
+
}), {
|
|
130
|
+
minX: Infinity,
|
|
131
|
+
minY: Infinity,
|
|
132
|
+
maxX: -Infinity,
|
|
133
|
+
maxY: -Infinity
|
|
134
|
+
});
|
|
135
|
+
r.minX = childrenBB.minX - Rect.LeftPadding;
|
|
136
|
+
r.minY = childrenBB.minY - Rect.TopPadding;
|
|
137
|
+
r.maxX = childrenBB.maxX + Rect.RightPadding;
|
|
138
|
+
r.maxY = childrenBB.maxY + Rect.BottomPadding;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function updateXYFlowNodes() {
|
|
142
|
+
applyConstraints(rectsToUpdate);
|
|
143
|
+
xyflowApi.getState().triggerNodeChanges(
|
|
144
|
+
rectsToUpdate.reduce((acc, r) => {
|
|
145
|
+
acc.push({
|
|
146
|
+
id: r.id,
|
|
147
|
+
type: "position",
|
|
148
|
+
dragging: false,
|
|
149
|
+
position: r.position,
|
|
150
|
+
positionAbsolute: r.positionAbsolute
|
|
151
|
+
});
|
|
152
|
+
if (r instanceof Compound) {
|
|
153
|
+
acc.push({
|
|
154
|
+
id: r.id,
|
|
155
|
+
type: "dimensions",
|
|
156
|
+
setAttributes: true,
|
|
157
|
+
dimensions: r.dimensions
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return acc;
|
|
161
|
+
}, [])
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
let animationFrameId = null;
|
|
165
|
+
function onMove(updater) {
|
|
166
|
+
if (rectsToUpdate.length === 0) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
animationFrameId ?? (animationFrameId = requestAnimationFrame(() => {
|
|
170
|
+
animationFrameId = null;
|
|
171
|
+
updater(
|
|
172
|
+
pipe(
|
|
173
|
+
editingNodeIds,
|
|
174
|
+
filter((id) => rects.has(id) && nodeLookup.has(id)),
|
|
175
|
+
map((id) => ({
|
|
176
|
+
rect: nonNullable(rects.get(id)),
|
|
177
|
+
node: nonNullable(nodeLookup.get(id))
|
|
178
|
+
}))
|
|
179
|
+
)
|
|
180
|
+
);
|
|
181
|
+
updateXYFlowNodes();
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
updateXYFlowNodes,
|
|
186
|
+
onMove
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function useLayoutConstraints() {
|
|
190
|
+
const diagramApi = useDiagramStoreApi();
|
|
191
|
+
const solverRef = useRef();
|
|
192
|
+
return useMemo(() => ({
|
|
193
|
+
onNodeDragStart: (_event, xynode) => {
|
|
194
|
+
const { cancelSaveManualLayout, xystore } = diagramApi.getState();
|
|
195
|
+
const { nodeLookup } = xystore.getState();
|
|
196
|
+
cancelSaveManualLayout();
|
|
197
|
+
const draggingNodes = pipe(
|
|
198
|
+
Array.from(nodeLookup.values()),
|
|
199
|
+
filter((n) => n.dragging === true || n.id === xynode.id || n.selected === true),
|
|
200
|
+
filter((n) => n.draggable !== false),
|
|
201
|
+
map((x) => x.id)
|
|
202
|
+
);
|
|
203
|
+
if (hasAtLeast(draggingNodes, 1)) {
|
|
204
|
+
solverRef.current = createLayoutConstraints(xystore, draggingNodes);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
onNodeDrag: () => {
|
|
208
|
+
var _a;
|
|
209
|
+
(_a = solverRef.current) == null ? void 0 : _a.onMove((nodes) => {
|
|
210
|
+
nodes.forEach(({ rect, node }) => {
|
|
211
|
+
rect.positionAbsolute = node.internals.positionAbsolute;
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
onNodeDragStop: () => {
|
|
216
|
+
var _a;
|
|
217
|
+
(_a = solverRef.current) == null ? void 0 : _a.updateXYFlowNodes();
|
|
218
|
+
diagramApi.getState().scheduleSaveManualLayout();
|
|
219
|
+
solverRef.current = void 0;
|
|
220
|
+
}
|
|
221
|
+
}), [diagramApi]);
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
createLayoutConstraints,
|
|
225
|
+
useLayoutConstraints
|
|
226
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { ReactFlowProps } from '@xyflow/react';
|
|
2
|
+
import { Simplify } from 'type-fest';
|
|
3
|
+
import { DiagramFlowTypes } from './types';
|
|
4
|
+
import { MouseEvent, ReactNode, CSSProperties } from 'react';
|
|
5
|
+
import { EdgeMarkerType, HandleType, Viewport } from '@xyflow/system';
|
|
6
|
+
export type XYFlowEventHandlers = Simplify<Required<Pick<ReactFlowProps<DiagramFlowTypes.Node, DiagramFlowTypes.Edge>, 'onDoubleClick' | 'onPaneClick' | 'onNodeClick' | 'onNodeDoubleClick' | 'onEdgeClick' | 'onEdgeDoubleClick' | 'onMoveEnd' | 'onNodeContextMenu' | 'onEdgeContextMenu' | 'onPaneContextMenu' | 'onEdgeMouseEnter' | 'onEdgeMouseLeave'>>>;
|
|
7
|
+
export declare function useXYFlowEvents(): {
|
|
8
|
+
onDoubleClick: (event: MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
9
|
+
onPaneClick: (event: MouseEvent<Element, MouseEvent>) => void;
|
|
10
|
+
onNodeContextMenu: (event: MouseEvent<Element, MouseEvent>, xynode: DiagramFlowTypes.Node) => void;
|
|
11
|
+
onPaneContextMenu: (event: MouseEvent | MouseEvent<Element, MouseEvent>) => void;
|
|
12
|
+
onEdgeContextMenu: (event: MouseEvent<Element, MouseEvent>, xyedge: {
|
|
13
|
+
id: string;
|
|
14
|
+
type: "relationship";
|
|
15
|
+
source: string;
|
|
16
|
+
target: string;
|
|
17
|
+
sourceHandle?: string | null;
|
|
18
|
+
targetHandle?: string | null;
|
|
19
|
+
animated?: boolean;
|
|
20
|
+
hidden?: boolean;
|
|
21
|
+
deletable?: boolean;
|
|
22
|
+
selectable?: boolean;
|
|
23
|
+
data: DiagramFlowTypes.DiagramEdgeData;
|
|
24
|
+
selected?: boolean;
|
|
25
|
+
markerStart?: EdgeMarkerType;
|
|
26
|
+
markerEnd?: EdgeMarkerType;
|
|
27
|
+
zIndex?: number;
|
|
28
|
+
ariaLabel?: string;
|
|
29
|
+
interactionWidth?: number;
|
|
30
|
+
label?: ReactNode;
|
|
31
|
+
labelStyle?: CSSProperties;
|
|
32
|
+
labelShowBg?: boolean;
|
|
33
|
+
labelBgStyle?: CSSProperties;
|
|
34
|
+
labelBgPadding?: [number, number];
|
|
35
|
+
labelBgBorderRadius?: number;
|
|
36
|
+
style?: CSSProperties;
|
|
37
|
+
className?: string;
|
|
38
|
+
reconnectable?: boolean | HandleType;
|
|
39
|
+
focusable?: boolean;
|
|
40
|
+
}) => void;
|
|
41
|
+
onNodeClick: (event: MouseEvent<Element, MouseEvent>, xynode: DiagramFlowTypes.Node) => void;
|
|
42
|
+
onNodeDoubleClick: (event: MouseEvent<Element, MouseEvent>, xynode: DiagramFlowTypes.Node) => void;
|
|
43
|
+
onEdgeClick: (event: MouseEvent<Element, MouseEvent>, xyedge: {
|
|
44
|
+
id: string;
|
|
45
|
+
type: "relationship";
|
|
46
|
+
source: string;
|
|
47
|
+
target: string;
|
|
48
|
+
sourceHandle?: string | null;
|
|
49
|
+
targetHandle?: string | null;
|
|
50
|
+
animated?: boolean;
|
|
51
|
+
hidden?: boolean;
|
|
52
|
+
deletable?: boolean;
|
|
53
|
+
selectable?: boolean;
|
|
54
|
+
data: DiagramFlowTypes.DiagramEdgeData;
|
|
55
|
+
selected?: boolean;
|
|
56
|
+
markerStart?: EdgeMarkerType;
|
|
57
|
+
markerEnd?: EdgeMarkerType;
|
|
58
|
+
zIndex?: number;
|
|
59
|
+
ariaLabel?: string;
|
|
60
|
+
interactionWidth?: number;
|
|
61
|
+
label?: ReactNode;
|
|
62
|
+
labelStyle?: CSSProperties;
|
|
63
|
+
labelShowBg?: boolean;
|
|
64
|
+
labelBgStyle?: CSSProperties;
|
|
65
|
+
labelBgPadding?: [number, number];
|
|
66
|
+
labelBgBorderRadius?: number;
|
|
67
|
+
style?: CSSProperties;
|
|
68
|
+
className?: string;
|
|
69
|
+
reconnectable?: boolean | HandleType;
|
|
70
|
+
focusable?: boolean;
|
|
71
|
+
}) => void;
|
|
72
|
+
onEdgeDoubleClick: (event: MouseEvent<Element, MouseEvent>, xyedge: {
|
|
73
|
+
id: string;
|
|
74
|
+
type: "relationship";
|
|
75
|
+
source: string;
|
|
76
|
+
target: string;
|
|
77
|
+
sourceHandle?: string | null;
|
|
78
|
+
targetHandle?: string | null;
|
|
79
|
+
animated?: boolean;
|
|
80
|
+
hidden?: boolean;
|
|
81
|
+
deletable?: boolean;
|
|
82
|
+
selectable?: boolean;
|
|
83
|
+
data: DiagramFlowTypes.DiagramEdgeData;
|
|
84
|
+
selected?: boolean;
|
|
85
|
+
markerStart?: EdgeMarkerType;
|
|
86
|
+
markerEnd?: EdgeMarkerType;
|
|
87
|
+
zIndex?: number;
|
|
88
|
+
ariaLabel?: string;
|
|
89
|
+
interactionWidth?: number;
|
|
90
|
+
label?: ReactNode;
|
|
91
|
+
labelStyle?: CSSProperties;
|
|
92
|
+
labelShowBg?: boolean;
|
|
93
|
+
labelBgStyle?: CSSProperties;
|
|
94
|
+
labelBgPadding?: [number, number];
|
|
95
|
+
labelBgBorderRadius?: number;
|
|
96
|
+
style?: CSSProperties;
|
|
97
|
+
className?: string;
|
|
98
|
+
reconnectable?: boolean | HandleType;
|
|
99
|
+
focusable?: boolean;
|
|
100
|
+
}) => void;
|
|
101
|
+
onMoveEnd: (event: MouseEvent | TouchEvent | null, _viewport: Viewport) => void;
|
|
102
|
+
onEdgeMouseEnter: (_event: MouseEvent<Element, MouseEvent>, { id }: {
|
|
103
|
+
id: string;
|
|
104
|
+
type: "relationship";
|
|
105
|
+
source: string;
|
|
106
|
+
target: string;
|
|
107
|
+
sourceHandle?: string | null;
|
|
108
|
+
targetHandle?: string | null;
|
|
109
|
+
animated?: boolean;
|
|
110
|
+
hidden?: boolean;
|
|
111
|
+
deletable?: boolean;
|
|
112
|
+
selectable?: boolean;
|
|
113
|
+
data: DiagramFlowTypes.DiagramEdgeData;
|
|
114
|
+
selected?: boolean;
|
|
115
|
+
markerStart?: EdgeMarkerType;
|
|
116
|
+
markerEnd?: EdgeMarkerType;
|
|
117
|
+
zIndex?: number;
|
|
118
|
+
ariaLabel?: string;
|
|
119
|
+
interactionWidth?: number;
|
|
120
|
+
label?: ReactNode;
|
|
121
|
+
labelStyle?: CSSProperties;
|
|
122
|
+
labelShowBg?: boolean;
|
|
123
|
+
labelBgStyle?: CSSProperties;
|
|
124
|
+
labelBgPadding?: [number, number];
|
|
125
|
+
labelBgBorderRadius?: number;
|
|
126
|
+
style?: CSSProperties;
|
|
127
|
+
className?: string;
|
|
128
|
+
reconnectable?: boolean | HandleType;
|
|
129
|
+
focusable?: boolean;
|
|
130
|
+
}) => void;
|
|
131
|
+
onEdgeMouseLeave: (_event: MouseEvent<Element, MouseEvent>, xyedge: {
|
|
132
|
+
id: string;
|
|
133
|
+
type: "relationship";
|
|
134
|
+
source: string;
|
|
135
|
+
target: string;
|
|
136
|
+
sourceHandle?: string | null;
|
|
137
|
+
targetHandle?: string | null;
|
|
138
|
+
animated?: boolean;
|
|
139
|
+
hidden?: boolean;
|
|
140
|
+
deletable?: boolean;
|
|
141
|
+
selectable?: boolean;
|
|
142
|
+
data: DiagramFlowTypes.DiagramEdgeData;
|
|
143
|
+
selected?: boolean;
|
|
144
|
+
markerStart?: EdgeMarkerType;
|
|
145
|
+
markerEnd?: EdgeMarkerType;
|
|
146
|
+
zIndex?: number;
|
|
147
|
+
ariaLabel?: string;
|
|
148
|
+
interactionWidth?: number;
|
|
149
|
+
label?: ReactNode;
|
|
150
|
+
labelStyle?: CSSProperties;
|
|
151
|
+
labelShowBg?: boolean;
|
|
152
|
+
labelBgStyle?: CSSProperties;
|
|
153
|
+
labelBgPadding?: [number, number];
|
|
154
|
+
labelBgBorderRadius?: number;
|
|
155
|
+
style?: CSSProperties;
|
|
156
|
+
className?: string;
|
|
157
|
+
reconnectable?: boolean | HandleType;
|
|
158
|
+
focusable?: boolean;
|
|
159
|
+
}) => void;
|
|
160
|
+
};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { DiagramNode } from "@likec4/core";
|
|
2
|
+
import { useRef, useMemo } from "react";
|
|
3
|
+
import { isTruthy, isNonNullish, first } from "remeda";
|
|
4
|
+
import { useDiagramStoreApi } from "../hooks/useDiagramState.js";
|
|
5
|
+
function useXYFlowEvents() {
|
|
6
|
+
const diagramApi = useDiagramStoreApi();
|
|
7
|
+
const lastClickTimestamp = useRef();
|
|
8
|
+
const dblclickTimeout = useRef();
|
|
9
|
+
return useMemo(() => {
|
|
10
|
+
const dbclickLock = () => {
|
|
11
|
+
if (dblclickTimeout.current !== void 0) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
dblclickTimeout.current = window.setTimeout(() => {
|
|
15
|
+
dblclickTimeout.current = void 0;
|
|
16
|
+
}, 300);
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
const lastClickWasRecent = (ms = 2e3) => {
|
|
20
|
+
const prevTimestamp = lastClickTimestamp.current ?? 0;
|
|
21
|
+
const now = lastClickTimestamp.current = Date.now();
|
|
22
|
+
return prevTimestamp + ms > now;
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
onDoubleClick: (event) => {
|
|
26
|
+
const {
|
|
27
|
+
onCanvasDblClick,
|
|
28
|
+
zoomable,
|
|
29
|
+
viewportChanged,
|
|
30
|
+
fitDiagram,
|
|
31
|
+
resetFocusAndLastClicked
|
|
32
|
+
} = diagramApi.getState();
|
|
33
|
+
resetFocusAndLastClicked();
|
|
34
|
+
if (zoomable && viewportChanged) {
|
|
35
|
+
fitDiagram();
|
|
36
|
+
}
|
|
37
|
+
if (!onCanvasDblClick) {
|
|
38
|
+
event.stopPropagation();
|
|
39
|
+
}
|
|
40
|
+
onCanvasDblClick == null ? void 0 : onCanvasDblClick(event);
|
|
41
|
+
},
|
|
42
|
+
onPaneClick: (event) => {
|
|
43
|
+
if (dbclickLock()) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const {
|
|
47
|
+
focusedNodeId,
|
|
48
|
+
activeWalkthrough,
|
|
49
|
+
fitDiagram,
|
|
50
|
+
onCanvasClick,
|
|
51
|
+
resetFocusAndLastClicked
|
|
52
|
+
} = diagramApi.getState();
|
|
53
|
+
if ((focusedNodeId ?? activeWalkthrough) !== null) {
|
|
54
|
+
fitDiagram();
|
|
55
|
+
if (!onCanvasClick) {
|
|
56
|
+
event.stopPropagation();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
resetFocusAndLastClicked();
|
|
60
|
+
onCanvasClick == null ? void 0 : onCanvasClick(event);
|
|
61
|
+
},
|
|
62
|
+
onNodeContextMenu: (event, xynode) => {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
diagramApi.getState().setLastClickedNode(xynode.id);
|
|
65
|
+
(_b = (_a = diagramApi.getState()).onNodeContextMenu) == null ? void 0 : _b.call(
|
|
66
|
+
_a,
|
|
67
|
+
xynode.data.element,
|
|
68
|
+
event
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
onPaneContextMenu: (event) => {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
diagramApi.getState().resetFocusAndLastClicked();
|
|
74
|
+
(_b = (_a = diagramApi.getState()).onCanvasContextMenu) == null ? void 0 : _b.call(_a, event);
|
|
75
|
+
},
|
|
76
|
+
onEdgeContextMenu: (event, xyedge) => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
diagramApi.getState().setLastClickedEdge(xyedge.id);
|
|
79
|
+
(_b = (_a = diagramApi.getState()).onEdgeContextMenu) == null ? void 0 : _b.call(
|
|
80
|
+
_a,
|
|
81
|
+
xyedge.data.edge,
|
|
82
|
+
event
|
|
83
|
+
);
|
|
84
|
+
},
|
|
85
|
+
onNodeClick: (event, xynode) => {
|
|
86
|
+
const {
|
|
87
|
+
focusedNodeId,
|
|
88
|
+
fitDiagram,
|
|
89
|
+
focusOnNode,
|
|
90
|
+
onNodeClick,
|
|
91
|
+
xystore,
|
|
92
|
+
enableFocusMode,
|
|
93
|
+
lastClickedNodeId,
|
|
94
|
+
nodesSelectable,
|
|
95
|
+
enableElementDetails,
|
|
96
|
+
setLastClickedNode,
|
|
97
|
+
onOpenSource,
|
|
98
|
+
openOverlay
|
|
99
|
+
} = diagramApi.getState();
|
|
100
|
+
const modelRef = DiagramNode.modelRef(xynode.data.element);
|
|
101
|
+
const deploymentRef = DiagramNode.deploymentRef(xynode.data.element);
|
|
102
|
+
setLastClickedNode(xynode.id);
|
|
103
|
+
const shallChangeFocus = !!focusedNodeId && focusedNodeId !== xynode.id;
|
|
104
|
+
const clickedRecently = lastClickWasRecent() && lastClickedNodeId === xynode.id;
|
|
105
|
+
let stopPropagation = false;
|
|
106
|
+
if (clickedRecently && !!onOpenSource && (modelRef || deploymentRef)) {
|
|
107
|
+
if (modelRef) {
|
|
108
|
+
onOpenSource({
|
|
109
|
+
element: modelRef
|
|
110
|
+
});
|
|
111
|
+
} else if (deploymentRef) {
|
|
112
|
+
onOpenSource({
|
|
113
|
+
deployment: deploymentRef
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
stopPropagation = true;
|
|
117
|
+
}
|
|
118
|
+
if (enableFocusMode) {
|
|
119
|
+
switch (true) {
|
|
120
|
+
case (shallChangeFocus || clickedRecently && !focusedNodeId): {
|
|
121
|
+
focusOnNode(xynode.id);
|
|
122
|
+
stopPropagation = true;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case (clickedRecently && focusedNodeId === xynode.id): {
|
|
126
|
+
focusOnNode(false);
|
|
127
|
+
fitDiagram();
|
|
128
|
+
stopPropagation = true;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case (!clickedRecently && modelRef && focusedNodeId === xynode.id && enableElementDetails): {
|
|
132
|
+
openOverlay({
|
|
133
|
+
elementDetails: xynode.data.element.id
|
|
134
|
+
});
|
|
135
|
+
stopPropagation = true;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else if (enableElementDetails && modelRef && (clickedRecently || focusedNodeId === xynode.id) && !onNodeClick) {
|
|
140
|
+
openOverlay({
|
|
141
|
+
elementDetails: xynode.data.element.id
|
|
142
|
+
});
|
|
143
|
+
stopPropagation = true;
|
|
144
|
+
} else if (nodesSelectable) {
|
|
145
|
+
xystore.getState().addSelectedNodes([xynode.id]);
|
|
146
|
+
stopPropagation = true;
|
|
147
|
+
}
|
|
148
|
+
if (!onNodeClick && stopPropagation) {
|
|
149
|
+
event.stopPropagation();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
onNodeClick == null ? void 0 : onNodeClick(
|
|
153
|
+
xynode.data.element,
|
|
154
|
+
event
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
onNodeDoubleClick: (event, xynode) => {
|
|
158
|
+
const {
|
|
159
|
+
setLastClickedNode
|
|
160
|
+
} = diagramApi.getState();
|
|
161
|
+
setLastClickedNode(xynode.id);
|
|
162
|
+
lastClickWasRecent();
|
|
163
|
+
event.stopPropagation();
|
|
164
|
+
},
|
|
165
|
+
onEdgeClick: (event, xyedge) => {
|
|
166
|
+
const {
|
|
167
|
+
lastClickedEdgeId,
|
|
168
|
+
isDynamicView,
|
|
169
|
+
enableDynamicViewWalkthrough,
|
|
170
|
+
activateWalkthrough,
|
|
171
|
+
activeWalkthrough,
|
|
172
|
+
focusedNodeId,
|
|
173
|
+
xystore,
|
|
174
|
+
nodesSelectable,
|
|
175
|
+
onOpenSource,
|
|
176
|
+
focusOnNode,
|
|
177
|
+
onEdgeClick,
|
|
178
|
+
setLastClickedEdge
|
|
179
|
+
} = diagramApi.getState();
|
|
180
|
+
if (lastClickedEdgeId !== xyedge.id) {
|
|
181
|
+
setLastClickedEdge(xyedge.id);
|
|
182
|
+
}
|
|
183
|
+
const isNotAFirstClick = lastClickedEdgeId === xyedge.id;
|
|
184
|
+
const connectedToFocusedNode = isTruthy(focusedNodeId) && (focusedNodeId === xyedge.source || focusedNodeId === xyedge.target);
|
|
185
|
+
if (isDynamicView && enableDynamicViewWalkthrough && (connectedToFocusedNode || isNotAFirstClick || isNonNullish(activeWalkthrough))) {
|
|
186
|
+
const nextStep = xyedge.data.edge.id;
|
|
187
|
+
if ((activeWalkthrough == null ? void 0 : activeWalkthrough.stepId) !== nextStep) {
|
|
188
|
+
activateWalkthrough(nextStep);
|
|
189
|
+
event.stopPropagation();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (isTruthy(focusedNodeId)) {
|
|
194
|
+
if (connectedToFocusedNode) {
|
|
195
|
+
focusOnNode(focusedNodeId === xyedge.source ? xyedge.target : xyedge.source);
|
|
196
|
+
} else {
|
|
197
|
+
focusOnNode(xyedge.source);
|
|
198
|
+
}
|
|
199
|
+
if (!onEdgeClick) {
|
|
200
|
+
event.stopPropagation();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
} else if (onOpenSource && !onEdgeClick) {
|
|
204
|
+
onOpenSource({
|
|
205
|
+
relation: first(xyedge.data.edge.relations)
|
|
206
|
+
});
|
|
207
|
+
event.stopPropagation();
|
|
208
|
+
return;
|
|
209
|
+
} else if (nodesSelectable) {
|
|
210
|
+
xystore.getState().addSelectedEdges([xyedge.id]);
|
|
211
|
+
if (!onEdgeClick) {
|
|
212
|
+
event.stopPropagation();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
onEdgeClick == null ? void 0 : onEdgeClick(
|
|
217
|
+
xyedge.data.edge,
|
|
218
|
+
event
|
|
219
|
+
);
|
|
220
|
+
},
|
|
221
|
+
onEdgeDoubleClick: (event, xyedge) => {
|
|
222
|
+
diagramApi.getState().setLastClickedEdge(xyedge.id);
|
|
223
|
+
const {
|
|
224
|
+
enableFocusMode,
|
|
225
|
+
isDynamicView,
|
|
226
|
+
enableDynamicViewWalkthrough,
|
|
227
|
+
focusOnNode,
|
|
228
|
+
activeWalkthrough,
|
|
229
|
+
activateWalkthrough,
|
|
230
|
+
openOverlay,
|
|
231
|
+
enableRelationshipDetails
|
|
232
|
+
} = diagramApi.getState();
|
|
233
|
+
if (isDynamicView && enableDynamicViewWalkthrough) {
|
|
234
|
+
const nextStep = xyedge.data.edge.id;
|
|
235
|
+
if ((activeWalkthrough == null ? void 0 : activeWalkthrough.stepId) !== nextStep) {
|
|
236
|
+
activateWalkthrough(nextStep);
|
|
237
|
+
event.stopPropagation();
|
|
238
|
+
}
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (enableRelationshipDetails) {
|
|
242
|
+
openOverlay({
|
|
243
|
+
edgeDetails: xyedge.data.edge.id
|
|
244
|
+
});
|
|
245
|
+
event.stopPropagation();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (enableFocusMode) {
|
|
249
|
+
focusOnNode(xyedge.source);
|
|
250
|
+
event.stopPropagation();
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
onMoveEnd: (event, _viewport) => {
|
|
255
|
+
const viewportChanged = !!event;
|
|
256
|
+
if (viewportChanged !== diagramApi.getState().viewportChanged) {
|
|
257
|
+
diagramApi.setState({ viewportChanged }, false, `viewport-changed: ${viewportChanged}`);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
onEdgeMouseEnter: (_event, { id }) => {
|
|
261
|
+
const { setHoveredEdge } = diagramApi.getState();
|
|
262
|
+
setHoveredEdge(id);
|
|
263
|
+
},
|
|
264
|
+
onEdgeMouseLeave: (_event, xyedge) => {
|
|
265
|
+
const { hoveredEdgeId, setHoveredEdge } = diagramApi.getState();
|
|
266
|
+
if (hoveredEdgeId === xyedge.id) {
|
|
267
|
+
setHoveredEdge(null);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}, [diagramApi]);
|
|
272
|
+
}
|
|
273
|
+
export {
|
|
274
|
+
useXYFlowEvents
|
|
275
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DiagramEdge, Point } from '@likec4/core';
|
|
2
|
+
import { InternalNode, Rect, XYPosition } from '@xyflow/react';
|
|
3
|
+
import { DiagramFlowTypes } from './types';
|
|
4
|
+
export declare function toDomPrecision(v: number | null): number;
|
|
5
|
+
export declare function distance(a: XYPosition, b: XYPosition): number;
|
|
6
|
+
export declare const nodeToRect: (nd: DiagramFlowTypes.InternalNode) => Rect;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a rectangle is completely inside another rectangle.
|
|
9
|
+
*
|
|
10
|
+
* @param test - The rectangle to test.
|
|
11
|
+
* @param target - The target rectangle.
|
|
12
|
+
* @returns `true` if the `test` rectangle is completely inside the `target` rectangle, otherwise `false`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isInside: (test: Rect, target: Rect) => boolean;
|
|
15
|
+
export declare function bezierControlPoints(diagramEdge: DiagramEdge): XYPosition[];
|
|
16
|
+
export declare function isSamePoint(a: XYPosition | Point, b: XYPosition | Point): boolean;
|
|
17
|
+
export declare function distanceBetweenPoints(a: XYPosition, b: XYPosition): number;
|
|
18
|
+
export declare function stopPropagation(e: React.MouseEvent): void;
|
|
19
|
+
export declare function centerXYInternalNode<N extends InternalNode>(nd: N): {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
};
|