@likec4/diagram 1.17.1 → 1.19.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/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 +40 -31
- package/src/LikeC4Diagram.props.ts +21 -12
- package/src/LikeC4Diagram.tsx +8 -10
- package/src/LikeC4Search.css.ts +12 -0
- package/src/LikeC4Search.tsx +45 -93
- 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/useDiagramState.ts +8 -3
- package/src/hooks/useXYFlow.ts +9 -8
- package/src/index.ts +12 -6
- package/src/likec4model/index.ts +12 -2
- package/src/likec4model/useLikeC4ElementsTree.ts +6 -13
- package/src/likec4model/useLikeC4Model.ts +21 -11
- package/src/overlays/Overlays.tsx +96 -63
- package/src/overlays/edge-details/EdgeDetailsXYFlow.tsx +18 -10
- package/src/overlays/edge-details/_types.ts +13 -33
- package/src/overlays/edge-details/use-layouted-edge-details.ts +35 -26
- package/src/overlays/edge-details/xyflow/CompoundNode.tsx +3 -11
- package/src/overlays/edge-details/xyflow/ElementNode.tsx +8 -13
- package/src/overlays/edge-details/xyflow/RelationshipEdge.tsx +7 -7
- package/src/overlays/edge-details/xyflow/styles.css.ts +1 -59
- package/src/overlays/element-details/ElementDetailsCard.tsx +91 -78
- package/src/overlays/element-details/TabPanelDeployments.css.ts +69 -0
- package/src/overlays/element-details/TabPanelDeployments.tsx +217 -0
- package/src/overlays/element-details/TabPanelRelationships.tsx +8 -9
- package/src/overlays/element-details/TabPanelStructure.tsx +10 -10
- package/src/overlays/relationships-of/RelationshipsOverlay.tsx +1 -1
- package/src/overlays/relationships-of/RelationshipsXYFlow.tsx +26 -34
- package/src/overlays/relationships-of/SelectElement.tsx +2 -2
- package/src/overlays/relationships-of/_types.ts +20 -58
- package/src/overlays/relationships-of/use-layouted-relationships.ts +54 -59
- package/src/overlays/relationships-of/xyflow/CompoundNode.tsx +10 -16
- package/src/overlays/relationships-of/xyflow/ElementNode.tsx +24 -21
- package/src/overlays/relationships-of/xyflow/EmptyNode.tsx +4 -7
- package/src/overlays/relationships-of/xyflow/RelationshipEdge.tsx +16 -15
- 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 +63 -48
- package/src/theme-vars.css.ts +81 -0
- package/src/theme-vars.ts +8 -81
- package/src/ui/DiagramTitlePanel.tsx +7 -34
- package/src/ui/Link.tsx +40 -0
- package/src/ui/notation/NotationPanel.tsx +4 -2
- package/src/ui/top-left/ChangeAutoLayoutButton.tsx +2 -2
- package/src/ui/top-left/TopLeftPanel.tsx +5 -5
- 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 +26 -19
- package/src/xyflow/edges/RelationshipEdge.tsx +5 -3
- package/src/xyflow/edges/RelationshipsDropdownMenu.tsx +23 -10
- 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 +27 -75
- package/src/xyflow/nodes/compound/CompoundNode.tsx +82 -163
- package/src/xyflow/nodes/element/ElementLink.tsx +2 -3
- package/src/xyflow/nodes/element/ElementNode.tsx +73 -252
- package/src/xyflow/nodes/element/element.css.ts +40 -64
- package/src/xyflow/nodes/shared/ElementIcon.tsx +1 -1
- package/src/xyflow/nodes/shared/Toolbar.tsx +51 -35
- package/src/xyflow/types.ts +48 -51
- package/src/xyflow/useLayoutConstraints.ts +10 -10
- package/src/xyflow/useXYFlowEvents.ts +31 -35
- package/src/xyflow/utils.ts +2 -2
- package/src/ui/OptionsPanel.css.ts +0 -9
- package/src/ui/OptionsPanel.tsx +0 -70
- package/src/ui/options/EdgeOptions.tsx +0 -142
- package/src/ui/options/NodeOptions.tsx +0 -362
- package/src/xyflow/nodes/element/ElementDetails.css.ts +0 -101
- package/src/xyflow/nodes/element/ElementDetails.tsx +0 -393
- package/src/xyflow/nodes/use-animate-variants.tsx +0 -64
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isAncestor, delay } from "@likec4/core";
|
|
3
|
+
import { useId } from "@mantine/hooks";
|
|
4
|
+
import { useSyncedRef, useDebouncedCallback, useDeepCompareEffect } from "@react-hookz/web";
|
|
5
|
+
import { ReactFlowProvider, useReactFlow, useStoreApi, useStore, useOnViewportChange, getViewportForBounds, ReactFlow } from "@xyflow/react";
|
|
6
|
+
import { getNodeDimensions } from "@xyflow/system";
|
|
7
|
+
import { useRef, useState } from "react";
|
|
8
|
+
import { map, setPath, omit, isNullish } from "remeda";
|
|
9
|
+
import { centerXYInternalNode } from "../../xyflow/utils.js";
|
|
10
|
+
import { cssReactflowMarker } from "../Overlays.css.js";
|
|
11
|
+
import { ZIndexes } from "./use-layouted-relationships.js";
|
|
12
|
+
import { CompoundNode } from "./xyflow/CompoundNode.js";
|
|
13
|
+
import { ElementNode } from "./xyflow/ElementNode.js";
|
|
14
|
+
import { EmptyNode } from "./xyflow/EmptyNode.js";
|
|
15
|
+
import { RelationshipEdge } from "./xyflow/RelationshipEdge.js";
|
|
16
|
+
import { useUpdateEffect } from "../../hooks/useUpdateEffect.js";
|
|
17
|
+
const nodeTypes = {
|
|
18
|
+
element: ElementNode,
|
|
19
|
+
compound: CompoundNode,
|
|
20
|
+
empty: EmptyNode
|
|
21
|
+
};
|
|
22
|
+
const edgeTypes = {
|
|
23
|
+
relation: RelationshipEdge
|
|
24
|
+
};
|
|
25
|
+
const findRootSubject = (nodes) => nodes.find((n) => n.data.column === "subjects" && isNullish(n.parentId));
|
|
26
|
+
const resetDimmedAndHovered = (xyflow) => {
|
|
27
|
+
xyflow.setEdges(
|
|
28
|
+
(edges) => edges.map((edge) => ({
|
|
29
|
+
...edge,
|
|
30
|
+
data: {
|
|
31
|
+
...edge.data,
|
|
32
|
+
dimmed: false,
|
|
33
|
+
hovered: false
|
|
34
|
+
},
|
|
35
|
+
animated: false
|
|
36
|
+
}))
|
|
37
|
+
);
|
|
38
|
+
xyflow.setNodes(
|
|
39
|
+
(nodes) => nodes.map(
|
|
40
|
+
(n) => ({
|
|
41
|
+
...n,
|
|
42
|
+
data: {
|
|
43
|
+
...n.data,
|
|
44
|
+
dimmed: false,
|
|
45
|
+
hovered: false
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
const animateEdge = (node, animated = true) => (edges) => {
|
|
52
|
+
return edges.map((edge) => {
|
|
53
|
+
const isConnected = edge.source === node.id || edge.target === node.id || isAncestor(node.id, edge.source) || isAncestor(node.id, edge.target);
|
|
54
|
+
return {
|
|
55
|
+
...edge,
|
|
56
|
+
animated: animated && isConnected
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const selectContainerViewport = (s) => `${s.width}x${s.height}`;
|
|
61
|
+
function RelationshipsXYFlowWrapped({
|
|
62
|
+
subjectId,
|
|
63
|
+
view,
|
|
64
|
+
nodes,
|
|
65
|
+
edges,
|
|
66
|
+
bounds,
|
|
67
|
+
children,
|
|
68
|
+
maxZoom = 2,
|
|
69
|
+
minZoom = 0.05,
|
|
70
|
+
viewportPadding = 0.1,
|
|
71
|
+
...rest
|
|
72
|
+
}) {
|
|
73
|
+
const id = useId();
|
|
74
|
+
const lastClickedNodeRef = useRef(null);
|
|
75
|
+
const xyflow = useReactFlow();
|
|
76
|
+
const xystore = useStoreApi();
|
|
77
|
+
const [zoomOnDoubleClick, setZoomOnDoubleClick] = useState(true);
|
|
78
|
+
const containerviewport = useStore(selectContainerViewport);
|
|
79
|
+
useOnViewportChange({
|
|
80
|
+
onEnd: ({ x, y, zoom }) => {
|
|
81
|
+
const roundedX = Math.round(x), roundedY = Math.round(y);
|
|
82
|
+
if (x !== roundedX || y !== roundedY) {
|
|
83
|
+
xystore.setState({ transform: [roundedX, roundedY, zoom] });
|
|
84
|
+
}
|
|
85
|
+
setZoomOnDoubleClick(zoom < 0.7);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const initialFitviewFlagRef = useRef(false);
|
|
89
|
+
const viewBoundsRef = useSyncedRef(bounds);
|
|
90
|
+
const fitview = useDebouncedCallback(
|
|
91
|
+
() => {
|
|
92
|
+
const { width, height } = xystore.getState();
|
|
93
|
+
xyflow.setViewport(
|
|
94
|
+
getViewportForBounds(viewBoundsRef.current, width, height, minZoom, maxZoom, viewportPadding),
|
|
95
|
+
initialFitviewFlagRef.current ? { duration: 500 } : void 0
|
|
96
|
+
);
|
|
97
|
+
initialFitviewFlagRef.current = true;
|
|
98
|
+
},
|
|
99
|
+
[xyflow, minZoom, maxZoom, viewportPadding],
|
|
100
|
+
100
|
|
101
|
+
);
|
|
102
|
+
useUpdateEffect(() => {
|
|
103
|
+
fitview();
|
|
104
|
+
}, [containerviewport]);
|
|
105
|
+
useDeepCompareEffect(() => {
|
|
106
|
+
const {
|
|
107
|
+
nodes: _nodes,
|
|
108
|
+
edges: _edges,
|
|
109
|
+
setNodes,
|
|
110
|
+
setEdges,
|
|
111
|
+
width,
|
|
112
|
+
height
|
|
113
|
+
} = xystore.getState();
|
|
114
|
+
const nextSubjectNode = findRootSubject(nodes);
|
|
115
|
+
const currentSubjectNode = findRootSubject(_nodes);
|
|
116
|
+
if (currentSubjectNode && (nextSubjectNode == null ? void 0 : nextSubjectNode.data.fqn) === currentSubjectNode.data.fqn) {
|
|
117
|
+
setNodes(map(nodes, setPath(["data", "entering"], false)));
|
|
118
|
+
setEdges(edges);
|
|
119
|
+
fitview();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!nextSubjectNode) {
|
|
123
|
+
console.error("Subject node not found");
|
|
124
|
+
} else if (nextSubjectNode.data.fqn !== subjectId) {
|
|
125
|
+
console.error(`Subject node mismatch, expected: ${subjectId} got: ${nextSubjectNode.data.fqn}`);
|
|
126
|
+
}
|
|
127
|
+
const nextzoom = getViewportForBounds(bounds, width, height, minZoom, maxZoom, viewportPadding).zoom;
|
|
128
|
+
const nextSubjectCenter = nextSubjectNode && {
|
|
129
|
+
x: nextSubjectNode.position.x + (nextSubjectNode.width ?? 0) / 2,
|
|
130
|
+
y: nextSubjectNode.position.y + (nextSubjectNode.height ?? 0) / 2
|
|
131
|
+
};
|
|
132
|
+
const existingNode = lastClickedNodeRef.current ?? xyflow.getNodes().find((n) => n.type !== "empty" && n.data.column !== "subjects" && n.data.fqn === subjectId);
|
|
133
|
+
lastClickedNodeRef.current = null;
|
|
134
|
+
if (nextSubjectCenter && existingNode && currentSubjectNode) {
|
|
135
|
+
const currentSubjectInternalNode = xyflow.getInternalNode(currentSubjectNode.id);
|
|
136
|
+
const currentSubjectCenter = centerXYInternalNode(currentSubjectInternalNode);
|
|
137
|
+
const existingInternalNode = xyflow.getInternalNode(existingNode.id);
|
|
138
|
+
const existingDimensions = getNodeDimensions(existingInternalNode);
|
|
139
|
+
nextSubjectNode.data.layoutId = existingNode.id;
|
|
140
|
+
setNodes(_nodes.map((n) => {
|
|
141
|
+
if (n.id !== existingNode.id) {
|
|
142
|
+
return {
|
|
143
|
+
...n,
|
|
144
|
+
data: {
|
|
145
|
+
...n.data,
|
|
146
|
+
leaving: n.data.column === "subjects",
|
|
147
|
+
dimmed: n.data.column === "subjects" ? "immediate" : false
|
|
148
|
+
}
|
|
149
|
+
// hidden: n.data.column === 'subjects'
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
...omit(n, ["parentId"]),
|
|
154
|
+
position: {
|
|
155
|
+
x: currentSubjectCenter.x - existingDimensions.width / 2,
|
|
156
|
+
y: currentSubjectCenter.y - existingDimensions.height / 2
|
|
157
|
+
},
|
|
158
|
+
zIndex: ZIndexes.max,
|
|
159
|
+
data: {
|
|
160
|
+
...n.data,
|
|
161
|
+
leaving: false,
|
|
162
|
+
dimmed: false
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}));
|
|
166
|
+
setEdges(_edges.map((e) => ({
|
|
167
|
+
...e,
|
|
168
|
+
data: {
|
|
169
|
+
...e.data,
|
|
170
|
+
dimmed: "immediate"
|
|
171
|
+
},
|
|
172
|
+
hidden: e.source === existingNode.id || e.target === existingNode.id || isAncestor(existingNode.id, e.source) || isAncestor(existingNode.id, e.target)
|
|
173
|
+
})));
|
|
174
|
+
const zoom = Math.min(
|
|
175
|
+
xyflow.getViewport().zoom,
|
|
176
|
+
nextzoom
|
|
177
|
+
);
|
|
178
|
+
let isCancelled = false;
|
|
179
|
+
const layout = async () => {
|
|
180
|
+
await delay(150);
|
|
181
|
+
if (isCancelled) return;
|
|
182
|
+
await xyflow.setCenter(currentSubjectCenter.x, currentSubjectCenter.y, { zoom, duration: 250 });
|
|
183
|
+
requestAnimationFrame(() => {
|
|
184
|
+
if (isCancelled) return;
|
|
185
|
+
xyflow.setCenter(nextSubjectCenter.x, nextSubjectCenter.y, { zoom });
|
|
186
|
+
setNodes(nodes);
|
|
187
|
+
setEdges(edges);
|
|
188
|
+
fitview();
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
requestAnimationFrame(layout);
|
|
192
|
+
return () => {
|
|
193
|
+
isCancelled = true;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
setNodes(map(nodes, setPath(["data", "entering"], false)));
|
|
197
|
+
setEdges(edges);
|
|
198
|
+
fitview();
|
|
199
|
+
return void 0;
|
|
200
|
+
}, [nodes, edges, subjectId]);
|
|
201
|
+
return /* @__PURE__ */ jsx(
|
|
202
|
+
ReactFlow,
|
|
203
|
+
{
|
|
204
|
+
id,
|
|
205
|
+
defaultEdges: [],
|
|
206
|
+
defaultNodes: [],
|
|
207
|
+
nodeTypes,
|
|
208
|
+
edgeTypes,
|
|
209
|
+
defaultMarkerColor: "var(--likec4-relation-lineColor)",
|
|
210
|
+
className: cssReactflowMarker,
|
|
211
|
+
zoomOnPinch: true,
|
|
212
|
+
zoomOnScroll: false,
|
|
213
|
+
zoomOnDoubleClick,
|
|
214
|
+
maxZoom,
|
|
215
|
+
minZoom,
|
|
216
|
+
fitView: true,
|
|
217
|
+
fitViewOptions: {
|
|
218
|
+
padding: viewportPadding,
|
|
219
|
+
maxZoom,
|
|
220
|
+
minZoom,
|
|
221
|
+
includeHiddenNodes: true
|
|
222
|
+
},
|
|
223
|
+
preventScrolling: true,
|
|
224
|
+
noDragClassName: "nodrag",
|
|
225
|
+
noPanClassName: "nopan",
|
|
226
|
+
panOnScroll: true,
|
|
227
|
+
panOnDrag: true,
|
|
228
|
+
nodesFocusable: false,
|
|
229
|
+
edgesFocusable: false,
|
|
230
|
+
nodesDraggable: false,
|
|
231
|
+
onNodeMouseEnter: (_, node) => {
|
|
232
|
+
if (node.type === "empty") return;
|
|
233
|
+
xyflow.setEdges(animateEdge(node, true));
|
|
234
|
+
},
|
|
235
|
+
onNodeMouseLeave: () => {
|
|
236
|
+
resetDimmedAndHovered(xyflow);
|
|
237
|
+
},
|
|
238
|
+
onEdgeMouseEnter: (_, edge) => {
|
|
239
|
+
xyflow.setEdges(
|
|
240
|
+
(edges2) => edges2.map((e) => ({
|
|
241
|
+
...e,
|
|
242
|
+
data: {
|
|
243
|
+
...e.data,
|
|
244
|
+
dimmed: e.id !== edge.id,
|
|
245
|
+
hovered: e.id === edge.id
|
|
246
|
+
},
|
|
247
|
+
zIndex: e.id === edge.id ? ZIndexes.max : ZIndexes.edge,
|
|
248
|
+
animated: e.id === edge.id
|
|
249
|
+
}))
|
|
250
|
+
);
|
|
251
|
+
xyflow.setNodes(
|
|
252
|
+
(nodes2) => nodes2.map((n) => ({
|
|
253
|
+
...n,
|
|
254
|
+
data: {
|
|
255
|
+
...n.data,
|
|
256
|
+
dimmed: n.id !== edge.source && n.id !== edge.target
|
|
257
|
+
}
|
|
258
|
+
}))
|
|
259
|
+
);
|
|
260
|
+
},
|
|
261
|
+
onEdgeMouseLeave: () => {
|
|
262
|
+
resetDimmedAndHovered(xyflow);
|
|
263
|
+
},
|
|
264
|
+
onNodeDoubleClick: (e) => {
|
|
265
|
+
e.stopPropagation();
|
|
266
|
+
},
|
|
267
|
+
...!zoomOnDoubleClick && {
|
|
268
|
+
onDoubleClick: (e) => {
|
|
269
|
+
e.stopPropagation();
|
|
270
|
+
fitview();
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
...rest,
|
|
274
|
+
children
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
function RelationshipsXYFlow(props) {
|
|
279
|
+
return /* @__PURE__ */ jsx(
|
|
280
|
+
ReactFlowProvider,
|
|
281
|
+
{
|
|
282
|
+
defaultNodes: [],
|
|
283
|
+
defaultEdges: [],
|
|
284
|
+
children: /* @__PURE__ */ jsx(RelationshipsXYFlowWrapped, { ...props })
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
export {
|
|
289
|
+
RelationshipsXYFlow
|
|
290
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Element, Fqn, ViewId } from '@likec4/core';
|
|
2
|
+
export declare const SelectElement: ({ subject, viewId, scope, onSelect }: {
|
|
3
|
+
subject: Element;
|
|
4
|
+
viewId: ViewId;
|
|
5
|
+
scope: "global" | "view";
|
|
6
|
+
onSelect: (id: Fqn) => void;
|
|
7
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ancestorsFqn } from "@likec4/core";
|
|
3
|
+
import { useTree, useComputedColorScheme, Popover, PopoverTarget, Button, PopoverDropdown, ScrollAreaAutosize, Tree, Group, ActionIcon, Box, Text } from "@mantine/core";
|
|
4
|
+
import { IconSelector, IconChevronRight } from "@tabler/icons-react";
|
|
5
|
+
import { useRef, useEffect } from "react";
|
|
6
|
+
import * as SelectElement_css from "./SelectElement.css.js";
|
|
7
|
+
import { useLikeC4ElementsTree } from "../../likec4model/useLikeC4ElementsTree.js";
|
|
8
|
+
const SelectElement = ({
|
|
9
|
+
subject,
|
|
10
|
+
viewId,
|
|
11
|
+
scope,
|
|
12
|
+
onSelect
|
|
13
|
+
}) => {
|
|
14
|
+
const viewport = useRef(null);
|
|
15
|
+
const data = useLikeC4ElementsTree(scope === "view" ? viewId : void 0);
|
|
16
|
+
const tree = useTree({
|
|
17
|
+
multiple: false
|
|
18
|
+
});
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
ancestorsFqn(subject.id).reverse().forEach((id) => {
|
|
21
|
+
tree.expand(id);
|
|
22
|
+
});
|
|
23
|
+
tree.select(subject.id);
|
|
24
|
+
}, [subject.id]);
|
|
25
|
+
const theme = useComputedColorScheme();
|
|
26
|
+
return /* @__PURE__ */ jsxs(
|
|
27
|
+
Popover,
|
|
28
|
+
{
|
|
29
|
+
position: "bottom",
|
|
30
|
+
shadow: "md",
|
|
31
|
+
keepMounted: true,
|
|
32
|
+
withinPortal: false,
|
|
33
|
+
closeOnClickOutside: true,
|
|
34
|
+
clickOutsideEvents: ["pointerdown", "mousedown", "click"],
|
|
35
|
+
onOpen: () => {
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
var _a;
|
|
38
|
+
const item = (_a = viewport.current) == null ? void 0 : _a.querySelector(`[data-value="${subject.id}"]`);
|
|
39
|
+
console.log("item", item);
|
|
40
|
+
item == null ? void 0 : item.scrollIntoView({ behavior: "instant", block: "nearest" });
|
|
41
|
+
}, 100);
|
|
42
|
+
},
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsx(PopoverTarget, { children: /* @__PURE__ */ jsx(
|
|
45
|
+
Button,
|
|
46
|
+
{
|
|
47
|
+
size: "xs",
|
|
48
|
+
variant: "light",
|
|
49
|
+
color: theme === "light" ? "dark" : "gray",
|
|
50
|
+
fw: "500",
|
|
51
|
+
maw: 250,
|
|
52
|
+
style: { padding: "0.25rem 0.75rem" },
|
|
53
|
+
rightSection: /* @__PURE__ */ jsx(IconSelector, { size: 16 }),
|
|
54
|
+
children: subject.title
|
|
55
|
+
}
|
|
56
|
+
) }),
|
|
57
|
+
/* @__PURE__ */ jsx(PopoverDropdown, { p: 0, miw: 250, maw: 400, children: /* @__PURE__ */ jsx(ScrollAreaAutosize, { mah: "70vh", scrollbars: "y", type: "never", viewportRef: viewport, children: /* @__PURE__ */ jsx(
|
|
58
|
+
Tree,
|
|
59
|
+
{
|
|
60
|
+
allowRangeSelection: false,
|
|
61
|
+
selectOnClick: false,
|
|
62
|
+
tree,
|
|
63
|
+
data,
|
|
64
|
+
classNames: SelectElement_css,
|
|
65
|
+
levelOffset: 8,
|
|
66
|
+
styles: {
|
|
67
|
+
label: {
|
|
68
|
+
paddingTop: 5,
|
|
69
|
+
paddingBottom: 6
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
renderNode: ({ node, selected, expanded, elementProps, hasChildren }) => /* @__PURE__ */ jsxs(Group, { gap: 2, wrap: "nowrap", ...elementProps, py: "3", children: [
|
|
73
|
+
/* @__PURE__ */ jsx(
|
|
74
|
+
ActionIcon,
|
|
75
|
+
{
|
|
76
|
+
variant: "subtle",
|
|
77
|
+
size: 18,
|
|
78
|
+
c: "dimmed",
|
|
79
|
+
style: {
|
|
80
|
+
visibility: hasChildren ? "visible" : "hidden"
|
|
81
|
+
},
|
|
82
|
+
children: /* @__PURE__ */ jsx(
|
|
83
|
+
IconChevronRight,
|
|
84
|
+
{
|
|
85
|
+
stroke: 3.5,
|
|
86
|
+
style: {
|
|
87
|
+
transition: "transform 150ms ease",
|
|
88
|
+
transform: `rotate(${expanded ? "90deg" : "0"})`,
|
|
89
|
+
width: "80%"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
/* @__PURE__ */ jsx(
|
|
96
|
+
Box,
|
|
97
|
+
{
|
|
98
|
+
flex: "1 1 100%",
|
|
99
|
+
w: "100%",
|
|
100
|
+
onClick: (e) => {
|
|
101
|
+
e.stopPropagation();
|
|
102
|
+
onSelect(node.value);
|
|
103
|
+
tree.select(node.value);
|
|
104
|
+
tree.expand(node.value);
|
|
105
|
+
},
|
|
106
|
+
children: /* @__PURE__ */ jsx(
|
|
107
|
+
Text,
|
|
108
|
+
{
|
|
109
|
+
fz: "sm",
|
|
110
|
+
fw: selected ? "600" : "400",
|
|
111
|
+
truncate: "end",
|
|
112
|
+
children: node.label
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
] })
|
|
118
|
+
}
|
|
119
|
+
) }) })
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
export {
|
|
125
|
+
SelectElement
|
|
126
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AddEdgeData, AddNodeData } from '../../utils/types';
|
|
2
|
+
import { SharedFlowTypes } from '../shared/xyflow/_types';
|
|
3
|
+
export declare namespace RelationshipsOfFlowTypes {
|
|
4
|
+
/**
|
|
5
|
+
* Data that is exclusive to the relationships-of overlay. It will be merged into the node types
|
|
6
|
+
* provided by SharedFlowTypes.
|
|
7
|
+
*/
|
|
8
|
+
type RelationshipsOfNodeData = {
|
|
9
|
+
depth?: number;
|
|
10
|
+
column: 'incomers' | 'subjects' | 'outgoers';
|
|
11
|
+
existsInCurrentView: boolean;
|
|
12
|
+
layoutId?: string;
|
|
13
|
+
};
|
|
14
|
+
export type ElementNode = AddNodeData<SharedFlowTypes.ElementNode, RelationshipsOfNodeData>;
|
|
15
|
+
export type CompoundNode = AddNodeData<SharedFlowTypes.CompoundNode, RelationshipsOfNodeData>;
|
|
16
|
+
export type NonEmptyNode = ElementNode | CompoundNode;
|
|
17
|
+
export type EmptyNode = AddNodeData<SharedFlowTypes.EmptyNode, RelationshipsOfNodeData>;
|
|
18
|
+
export type Node = NonEmptyNode | EmptyNode;
|
|
19
|
+
/**
|
|
20
|
+
* Data that is exclusive to the relationships-of overlay. It will be merged into the edge types
|
|
21
|
+
* provided by SharedFlowTypes.
|
|
22
|
+
*/
|
|
23
|
+
type RelationshipsOfEdgeData = {
|
|
24
|
+
existsInCurrentView: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type Edge = AddEdgeData<SharedFlowTypes.Edge, RelationshipsOfEdgeData>;
|
|
27
|
+
export {};
|
|
28
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DiagramView, Fqn, LikeC4Model } from '@likec4/core';
|
|
2
|
+
import { RelationshipsOfFlowTypes } from './_types';
|
|
3
|
+
export declare const ZIndexes: {
|
|
4
|
+
empty: number;
|
|
5
|
+
compound: number;
|
|
6
|
+
edge: number;
|
|
7
|
+
element: number;
|
|
8
|
+
max: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function useLayoutedRelationships(subjectId: Fqn, view: DiagramView, scope: 'global' | 'view'): {
|
|
11
|
+
viewIncludesSubject: boolean;
|
|
12
|
+
notIncludedRelations: number;
|
|
13
|
+
subject: LikeC4Model.Element;
|
|
14
|
+
nodes: RelationshipsOfFlowTypes.Node[];
|
|
15
|
+
edges: RelationshipsOfFlowTypes.Edge[];
|
|
16
|
+
bounds: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
};
|
|
22
|
+
};
|