@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
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type BorderStyle,
|
|
3
|
-
defaultTheme,
|
|
4
3
|
type Element,
|
|
5
|
-
ElementShapes,
|
|
6
4
|
type Fqn,
|
|
7
5
|
type NonEmptyArray,
|
|
8
6
|
type ThemeColor,
|
|
9
|
-
type ViewChange
|
|
7
|
+
type ViewChange,
|
|
8
|
+
defaultTheme,
|
|
9
|
+
DiagramNode,
|
|
10
|
+
ElementShapes,
|
|
10
11
|
} from '@likec4/core'
|
|
11
12
|
import {
|
|
13
|
+
type PopoverProps,
|
|
12
14
|
ActionIcon,
|
|
13
15
|
Box,
|
|
14
16
|
Button,
|
|
@@ -25,7 +27,6 @@ import {
|
|
|
25
27
|
Paper,
|
|
26
28
|
Popover,
|
|
27
29
|
PopoverDropdown,
|
|
28
|
-
type PopoverProps,
|
|
29
30
|
PopoverTarget,
|
|
30
31
|
rem,
|
|
31
32
|
SegmentedControl,
|
|
@@ -34,12 +35,13 @@ import {
|
|
|
34
35
|
Stack,
|
|
35
36
|
Text,
|
|
36
37
|
Tooltip as MantineTooltip,
|
|
37
|
-
TooltipGroup
|
|
38
|
+
TooltipGroup,
|
|
38
39
|
} from '@mantine/core'
|
|
39
40
|
import { IconCheck, IconFileSymlink, IconSelector, IconTransform } from '@tabler/icons-react'
|
|
40
|
-
import {
|
|
41
|
+
import { type NodeToolbarProps, NodeToolbar } from '@xyflow/react'
|
|
41
42
|
import clsx from 'clsx'
|
|
42
43
|
import { useEffect, useState } from 'react'
|
|
44
|
+
import type { MergeExclusive } from 'type-fest'
|
|
43
45
|
import { useDiagramState, useDiagramStoreApi, useMantinePortalProps, useUpdateEffect } from '../../../hooks'
|
|
44
46
|
import { stopPropagation } from '../../utils'
|
|
45
47
|
|
|
@@ -53,12 +55,12 @@ const {
|
|
|
53
55
|
const themedColors = [
|
|
54
56
|
{ key: 'primary', value: primary.fill },
|
|
55
57
|
{ key: 'secondary', value: secondary.fill },
|
|
56
|
-
{ key: 'muted', value: muted.fill }
|
|
58
|
+
{ key: 'muted', value: muted.fill },
|
|
57
59
|
] satisfies Array<{ key: ThemeColor; value: string }>
|
|
58
60
|
|
|
59
61
|
const colors = keys(otherColors).map(key => ({
|
|
60
62
|
key,
|
|
61
|
-
value: defaultTheme.elements[key].fill
|
|
63
|
+
value: defaultTheme.elements[key].fill,
|
|
62
64
|
}))
|
|
63
65
|
|
|
64
66
|
type ThemeColorKey = typeof themedColors[0]['key']
|
|
@@ -71,11 +73,11 @@ const Tooltip = MantineTooltip.withProps({
|
|
|
71
73
|
closeDelay: 150,
|
|
72
74
|
label: '',
|
|
73
75
|
children: null,
|
|
74
|
-
offset: 4
|
|
76
|
+
offset: 4,
|
|
75
77
|
})
|
|
76
78
|
|
|
77
79
|
type ToolbarProps = NodeToolbarProps & {
|
|
78
|
-
element:
|
|
80
|
+
element: DiagramNode
|
|
79
81
|
onColorPreview: (color: ThemeColor | null) => void
|
|
80
82
|
}
|
|
81
83
|
|
|
@@ -86,21 +88,23 @@ export function CompoundToolbar({
|
|
|
86
88
|
onColorPreview,
|
|
87
89
|
...props
|
|
88
90
|
}: ToolbarProps) {
|
|
91
|
+
const modelRef = DiagramNode.modelRef(element)
|
|
92
|
+
const deploymentRef = DiagramNode.deploymentRef(element)
|
|
89
93
|
const targets = [element.id] as NonEmptyArray<Fqn>
|
|
90
94
|
const diagramApi = useDiagramStoreApi()
|
|
91
95
|
const {
|
|
92
96
|
hasGoToSource,
|
|
93
|
-
enableRelationshipBrowser
|
|
97
|
+
enableRelationshipBrowser,
|
|
94
98
|
} = useDiagramState(s => ({
|
|
95
|
-
hasGoToSource: !!s.
|
|
96
|
-
enableRelationshipBrowser: s.enableRelationshipBrowser
|
|
99
|
+
hasGoToSource: !!s.onOpenSource,
|
|
100
|
+
enableRelationshipBrowser: s.enableRelationshipBrowser,
|
|
97
101
|
}))
|
|
98
102
|
|
|
99
103
|
const onChange: OnStyleChange = (style) => {
|
|
100
104
|
diagramApi.getState().triggerChangeElementStyle({
|
|
101
105
|
op: 'change-element-style',
|
|
102
106
|
style,
|
|
103
|
-
targets
|
|
107
|
+
targets,
|
|
104
108
|
})
|
|
105
109
|
}
|
|
106
110
|
|
|
@@ -117,8 +121,9 @@ export function CompoundToolbar({
|
|
|
117
121
|
elementBorderStyle={element.style?.border}
|
|
118
122
|
onChange={onChange}
|
|
119
123
|
/>
|
|
120
|
-
{hasGoToSource && <GoToSourceButton elementId={
|
|
121
|
-
{
|
|
124
|
+
{hasGoToSource && modelRef && <GoToSourceButton elementId={modelRef} />}
|
|
125
|
+
{hasGoToSource && !modelRef && deploymentRef && <GoToSourceButton deploymentId={deploymentRef} />}
|
|
126
|
+
{enableRelationshipBrowser && !!modelRef && <BrowseRelationshipsButton elementId={modelRef} />}
|
|
122
127
|
</Toolbar>
|
|
123
128
|
)
|
|
124
129
|
}
|
|
@@ -156,14 +161,16 @@ export function ElementToolbar({
|
|
|
156
161
|
onColorPreview,
|
|
157
162
|
...props
|
|
158
163
|
}: ToolbarProps) {
|
|
164
|
+
const modelRef = DiagramNode.modelRef(element)
|
|
165
|
+
const deploymentRef = DiagramNode.deploymentRef(element)
|
|
159
166
|
const targets = [element.id] as NonEmptyArray<Fqn>
|
|
160
167
|
const diagramApi = useDiagramStoreApi()
|
|
161
168
|
const {
|
|
162
169
|
hasGoToSource,
|
|
163
|
-
enableRelationshipBrowser
|
|
170
|
+
enableRelationshipBrowser,
|
|
164
171
|
} = useDiagramState(s => ({
|
|
165
|
-
hasGoToSource: !!s.
|
|
166
|
-
enableRelationshipBrowser: s.enableRelationshipBrowser
|
|
172
|
+
hasGoToSource: !!s.onOpenSource,
|
|
173
|
+
enableRelationshipBrowser: s.enableRelationshipBrowser,
|
|
167
174
|
}))
|
|
168
175
|
const portalProps = useMantinePortalProps()
|
|
169
176
|
|
|
@@ -171,7 +178,7 @@ export function ElementToolbar({
|
|
|
171
178
|
diagramApi.getState().triggerChangeElementStyle({
|
|
172
179
|
op: 'change-element-style',
|
|
173
180
|
style,
|
|
174
|
-
targets
|
|
181
|
+
targets,
|
|
175
182
|
})
|
|
176
183
|
}
|
|
177
184
|
|
|
@@ -189,8 +196,8 @@ export function ElementToolbar({
|
|
|
189
196
|
offset={2}
|
|
190
197
|
styles={{
|
|
191
198
|
item: {
|
|
192
|
-
padding: 'calc(var(--mantine-spacing-xs) / 1.5) var(--mantine-spacing-xs)'
|
|
193
|
-
}
|
|
199
|
+
padding: 'calc(var(--mantine-spacing-xs) / 1.5) var(--mantine-spacing-xs)',
|
|
200
|
+
},
|
|
194
201
|
}}
|
|
195
202
|
{...portalProps}
|
|
196
203
|
>
|
|
@@ -234,20 +241,21 @@ export function ElementToolbar({
|
|
|
234
241
|
onChange={onChange}
|
|
235
242
|
position="right-end"
|
|
236
243
|
/>
|
|
237
|
-
{hasGoToSource && <GoToSourceButton elementId={
|
|
238
|
-
{
|
|
244
|
+
{hasGoToSource && modelRef && <GoToSourceButton elementId={modelRef} />}
|
|
245
|
+
{hasGoToSource && !modelRef && deploymentRef && <GoToSourceButton deploymentId={deploymentRef} />}
|
|
246
|
+
{enableRelationshipBrowser && !!modelRef && <BrowseRelationshipsButton elementId={modelRef} />}
|
|
239
247
|
</Toolbar>
|
|
240
248
|
)
|
|
241
249
|
}
|
|
242
250
|
|
|
243
251
|
type ColorButtonProps = Omit<PopoverProps, 'onChange'> & {
|
|
244
|
-
element:
|
|
252
|
+
element: DiagramNode
|
|
245
253
|
isOpacityEditable?: boolean
|
|
246
254
|
onColorPreview: (color: ThemeColor | null) => void
|
|
247
255
|
onChange: OnStyleChange
|
|
248
256
|
}
|
|
249
257
|
|
|
250
|
-
function GoToSourceButton({ elementId }
|
|
258
|
+
function GoToSourceButton(props: MergeExclusive<{ elementId: Fqn }, { deploymentId: Fqn }>) {
|
|
251
259
|
const diagramApi = useDiagramStoreApi()
|
|
252
260
|
const portalProps = useMantinePortalProps()
|
|
253
261
|
return (
|
|
@@ -258,7 +266,15 @@ function GoToSourceButton({ elementId }: { elementId: Fqn }) {
|
|
|
258
266
|
color="gray"
|
|
259
267
|
onClick={e => {
|
|
260
268
|
e.stopPropagation()
|
|
261
|
-
|
|
269
|
+
if (props.elementId) {
|
|
270
|
+
diagramApi.getState().onOpenSource?.({
|
|
271
|
+
element: props.elementId,
|
|
272
|
+
})
|
|
273
|
+
} else if (props.deploymentId) {
|
|
274
|
+
diagramApi.getState().onOpenSource?.({
|
|
275
|
+
deployment: props.deploymentId,
|
|
276
|
+
})
|
|
277
|
+
}
|
|
262
278
|
}}>
|
|
263
279
|
<IconFileSymlink stroke={1.8} style={{ width: '70%' }} />
|
|
264
280
|
</ActionIcon>
|
|
@@ -317,7 +333,7 @@ function ColorButton({
|
|
|
317
333
|
function ColorSwatches({
|
|
318
334
|
elementColor,
|
|
319
335
|
onColorPreview,
|
|
320
|
-
onChange
|
|
336
|
+
onChange,
|
|
321
337
|
}: {
|
|
322
338
|
elementColor: ThemeColor
|
|
323
339
|
onColorPreview: (color: ThemeColor | null) => void
|
|
@@ -392,7 +408,7 @@ function ColorSwatches({
|
|
|
392
408
|
|
|
393
409
|
function BorderStyleOption({
|
|
394
410
|
elementBorderStyle = 'dashed',
|
|
395
|
-
onChange
|
|
411
|
+
onChange,
|
|
396
412
|
}: {
|
|
397
413
|
elementBorderStyle: BorderStyle | undefined
|
|
398
414
|
onChange: OnStyleChange
|
|
@@ -417,14 +433,14 @@ function BorderStyleOption({
|
|
|
417
433
|
styles={{
|
|
418
434
|
label: {
|
|
419
435
|
paddingTop: 2,
|
|
420
|
-
paddingBottom: 2
|
|
421
|
-
}
|
|
436
|
+
paddingBottom: 2,
|
|
437
|
+
},
|
|
422
438
|
}}
|
|
423
439
|
data={[
|
|
424
440
|
{ label: 'Solid', value: 'solid' },
|
|
425
441
|
{ label: 'Dashed', value: 'dashed' },
|
|
426
442
|
{ label: 'Dotted', value: 'dotted' },
|
|
427
|
-
{ label: 'None', value: 'none' }
|
|
443
|
+
{ label: 'None', value: 'none' },
|
|
428
444
|
]}
|
|
429
445
|
/>
|
|
430
446
|
</Box>
|
|
@@ -433,7 +449,7 @@ function BorderStyleOption({
|
|
|
433
449
|
|
|
434
450
|
function OpacityOption({
|
|
435
451
|
elementOpacity = 100,
|
|
436
|
-
onOpacityChange
|
|
452
|
+
onOpacityChange,
|
|
437
453
|
}: {
|
|
438
454
|
elementOpacity: number | undefined
|
|
439
455
|
onOpacityChange: (opacity: number) => void
|
|
@@ -465,14 +481,14 @@ function BrowseRelationshipsButton({ elementId }: { elementId: Fqn }) {
|
|
|
465
481
|
onClick={e => {
|
|
466
482
|
e.stopPropagation()
|
|
467
483
|
diagramApi.getState().openOverlay({
|
|
468
|
-
relationshipsOf: elementId
|
|
484
|
+
relationshipsOf: elementId,
|
|
469
485
|
})
|
|
470
486
|
}}>
|
|
471
487
|
<IconTransform
|
|
472
488
|
stroke={2}
|
|
473
489
|
style={{
|
|
474
490
|
width: '72%',
|
|
475
|
-
height: '72%'
|
|
491
|
+
height: '72%',
|
|
476
492
|
}} />
|
|
477
493
|
</ActionIcon>
|
|
478
494
|
</Tooltip>
|
package/src/xyflow/types.ts
CHANGED
|
@@ -1,60 +1,57 @@
|
|
|
1
|
-
import type { BBox, DiagramEdge, DiagramNode,
|
|
2
|
-
import type { Edge, InternalNode, Node, ReactFlowInstance, ReactFlowState } from '@xyflow/react'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
fqn: Fqn
|
|
14
|
-
isViewGroup: boolean
|
|
15
|
-
element: DiagramNode
|
|
16
|
-
}, 'compound'>
|
|
17
|
-
|
|
18
|
-
export type XYFlowNode = ElementXYFlowNode | CompoundXYFlowNode
|
|
19
|
-
|
|
20
|
-
export type InternalXYFlowNode = InternalNode<XYFlowNode>
|
|
21
|
-
|
|
22
|
-
export namespace XYFlowNode {
|
|
23
|
-
export function isCompound(node: unknown): node is CompoundXYFlowNode {
|
|
24
|
-
return isNode(node) && node.type === 'compound'
|
|
1
|
+
import type { BBox, DiagramEdge, DiagramNode, XYPoint } from '@likec4/core'
|
|
2
|
+
import type { Edge as ReactFlowEdge, InternalNode as ReactFlowInternalNode, Node as ReactFlowNode, ReactFlowInstance, ReactFlowState } from '@xyflow/react'
|
|
3
|
+
import type { SetRequired, Simplify } from 'type-fest'
|
|
4
|
+
import type { SharedFlowTypes } from '../overlays/shared/xyflow/_types'
|
|
5
|
+
|
|
6
|
+
export namespace DiagramFlowTypes {
|
|
7
|
+
|
|
8
|
+
export type NodeData = {
|
|
9
|
+
/**
|
|
10
|
+
* The DiagramNode backing this node.
|
|
11
|
+
*/
|
|
12
|
+
element: DiagramNode
|
|
25
13
|
}
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
|
|
15
|
+
export type CompoundNodeData = NodeData & {
|
|
16
|
+
/**
|
|
17
|
+
* Whether this node is a view group.
|
|
18
|
+
*/
|
|
19
|
+
isViewGroup: boolean
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
export
|
|
31
|
-
|
|
22
|
+
export type ElementNode = SetRequired<ReactFlowNode<
|
|
23
|
+
SharedFlowTypes.NonEmptyNodeData & NodeData,
|
|
24
|
+
'element'>,
|
|
25
|
+
'type'>
|
|
32
26
|
|
|
33
|
-
export type
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
label: null | {
|
|
38
|
-
bbox: BBox
|
|
39
|
-
text: string
|
|
40
|
-
}
|
|
41
|
-
}
|
|
27
|
+
export type CompoundNode = SetRequired<ReactFlowNode<
|
|
28
|
+
SharedFlowTypes.NonEmptyNodeData & CompoundNodeData,
|
|
29
|
+
'compound'>,
|
|
30
|
+
'type'>
|
|
42
31
|
|
|
43
|
-
export type
|
|
44
|
-
Edge<RelationshipData, 'relationship'> & {
|
|
45
|
-
type: 'relationship'
|
|
46
|
-
// Make field required
|
|
47
|
-
data: RelationshipData
|
|
48
|
-
}
|
|
49
|
-
>
|
|
32
|
+
export type Node = ElementNode | CompoundNode
|
|
50
33
|
|
|
51
|
-
export type
|
|
34
|
+
export type InternalNode = ReactFlowInternalNode<Node>
|
|
52
35
|
|
|
53
|
-
export
|
|
54
|
-
export type Data = RelationshipData
|
|
36
|
+
export type XYFlowInstance = ReactFlowInstance<Node, Edge>
|
|
55
37
|
|
|
56
|
-
export
|
|
57
|
-
|
|
38
|
+
export type XYFlowState = ReactFlowState<Node, Edge>
|
|
39
|
+
|
|
40
|
+
export type DiagramEdgeData = {
|
|
41
|
+
edge: DiagramEdge
|
|
42
|
+
// if set - edge was changed by user
|
|
43
|
+
controlPoints: XYPoint[] | null
|
|
44
|
+
label: null | {
|
|
45
|
+
bbox: BBox
|
|
46
|
+
text: string
|
|
47
|
+
}
|
|
48
|
+
}
|
|
58
49
|
|
|
59
|
-
export type
|
|
60
|
-
|
|
50
|
+
export type Edge = Simplify<
|
|
51
|
+
ReactFlowEdge<DiagramEdgeData, 'relationship'> & {
|
|
52
|
+
type: 'relationship'
|
|
53
|
+
// Make field required
|
|
54
|
+
data: DiagramEdgeData
|
|
55
|
+
}
|
|
56
|
+
>
|
|
57
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import { type NodeId, type NonEmptyArray, nonNullable } from '@likec4/core'
|
|
2
|
+
import type { NodeChange, ReactFlowProps, XYPosition } from '@xyflow/react'
|
|
3
3
|
import { getNodeDimensions } from '@xyflow/system'
|
|
4
4
|
import { useMemo, useRef } from 'react'
|
|
5
5
|
import { filter, hasAtLeast, isNullish, map, pipe } from 'remeda'
|
|
6
6
|
import { useDiagramStoreApi } from '../hooks'
|
|
7
7
|
import { type XYStoreApi } from '../hooks/useXYFlow'
|
|
8
|
-
import type {
|
|
8
|
+
import type { DiagramFlowTypes } from './types'
|
|
9
9
|
|
|
10
10
|
abstract class Rect {
|
|
11
11
|
static readonly LeftPadding = 40
|
|
@@ -60,7 +60,7 @@ class Compound extends Rect {
|
|
|
60
60
|
public readonly children = [] as Rect[]
|
|
61
61
|
|
|
62
62
|
constructor(
|
|
63
|
-
xynode: InternalNode
|
|
63
|
+
xynode: DiagramFlowTypes.InternalNode,
|
|
64
64
|
protected readonly parent: Compound | null = null
|
|
65
65
|
) {
|
|
66
66
|
super()
|
|
@@ -74,7 +74,7 @@ class Compound extends Rect {
|
|
|
74
74
|
|
|
75
75
|
class Leaf extends Rect {
|
|
76
76
|
constructor(
|
|
77
|
-
xynode: InternalNode
|
|
77
|
+
xynode: DiagramFlowTypes.InternalNode,
|
|
78
78
|
public readonly parent: Compound | null = null
|
|
79
79
|
) {
|
|
80
80
|
super()
|
|
@@ -94,7 +94,7 @@ class Leaf extends Rect {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
type NodePositionUpdater = (
|
|
97
|
-
nodes: Array<{ rect: Rect | Compound; node: InternalNode
|
|
97
|
+
nodes: Array<{ rect: Rect | Compound; node: DiagramFlowTypes.InternalNode }>
|
|
98
98
|
) => void
|
|
99
99
|
|
|
100
100
|
export function createLayoutConstraints(
|
|
@@ -108,7 +108,7 @@ export function createLayoutConstraints(
|
|
|
108
108
|
const ancestors = [] as string[]
|
|
109
109
|
const xynode = nodeLookup.get(nodeId)
|
|
110
110
|
let parent = xynode?.parentId
|
|
111
|
-
let parentNode: InternalNode
|
|
111
|
+
let parentNode: DiagramFlowTypes.InternalNode | undefined
|
|
112
112
|
while (parent && (parentNode = nodeLookup.get(parent))) {
|
|
113
113
|
ancestors.push(parentNode.id as NodeId)
|
|
114
114
|
parent = parentNode.parentId
|
|
@@ -120,7 +120,7 @@ export function createLayoutConstraints(
|
|
|
120
120
|
editingNodeIds.flatMap(ancestorsOf)
|
|
121
121
|
)
|
|
122
122
|
|
|
123
|
-
const traverse = new Array<{ xynode: InternalNode
|
|
123
|
+
const traverse = new Array<{ xynode: DiagramFlowTypes.InternalNode; parent: Compound | null }>()
|
|
124
124
|
|
|
125
125
|
for (const [, xynode] of nodeLookup) {
|
|
126
126
|
if (isNullish(xynode.parentId)) {
|
|
@@ -200,7 +200,7 @@ export function createLayoutConstraints(
|
|
|
200
200
|
})
|
|
201
201
|
}
|
|
202
202
|
return acc
|
|
203
|
-
}, [] as NodeChange<
|
|
203
|
+
}, [] as NodeChange<DiagramFlowTypes.Node>[])
|
|
204
204
|
)
|
|
205
205
|
}
|
|
206
206
|
|
|
@@ -234,7 +234,7 @@ export function createLayoutConstraints(
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
type LayoutConstraints = Required<Pick<ReactFlowProps<
|
|
237
|
+
type LayoutConstraints = Required<Pick<ReactFlowProps<DiagramFlowTypes.Node>, 'onNodeDragStart' | 'onNodeDrag' | 'onNodeDragStop'>>
|
|
238
238
|
/**
|
|
239
239
|
* Keeps the layout constraints (parent nodes and children) when dragging a node
|
|
240
240
|
*/
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { DiagramNode } from '@likec4/core'
|
|
1
2
|
import type { ReactFlowProps } from '@xyflow/react'
|
|
2
3
|
import { useMemo, useRef } from 'react'
|
|
3
|
-
import { isNonNullish, isTruthy } from 'remeda'
|
|
4
|
+
import { first, isNonNullish, isTruthy } from 'remeda'
|
|
4
5
|
import type { Simplify } from 'type-fest'
|
|
5
6
|
import { useDiagramStoreApi } from '../hooks/useDiagramState'
|
|
6
|
-
import type {
|
|
7
|
+
import type { DiagramFlowTypes } from './types'
|
|
7
8
|
|
|
8
9
|
export type XYFlowEventHandlers = Simplify<
|
|
9
10
|
Required<
|
|
10
11
|
Pick<
|
|
11
|
-
ReactFlowProps<
|
|
12
|
+
ReactFlowProps<DiagramFlowTypes.Node, DiagramFlowTypes.Edge>,
|
|
12
13
|
| 'onDoubleClick'
|
|
13
14
|
| 'onPaneClick'
|
|
14
15
|
| 'onNodeClick'
|
|
@@ -19,8 +20,6 @@ export type XYFlowEventHandlers = Simplify<
|
|
|
19
20
|
| 'onNodeContextMenu'
|
|
20
21
|
| 'onEdgeContextMenu'
|
|
21
22
|
| 'onPaneContextMenu'
|
|
22
|
-
| 'onNodeMouseEnter'
|
|
23
|
-
| 'onNodeMouseLeave'
|
|
24
23
|
| 'onEdgeMouseEnter'
|
|
25
24
|
| 'onEdgeMouseLeave'
|
|
26
25
|
>
|
|
@@ -34,10 +33,6 @@ export function useXYFlowEvents() {
|
|
|
34
33
|
|
|
35
34
|
const dblclickTimeout = useRef<number>()
|
|
36
35
|
|
|
37
|
-
// If we are in focused mode, on edge enter we want to "highlight" the other node
|
|
38
|
-
// This ref contains the id of this node
|
|
39
|
-
const hoveredNodeFromOnEdgeEnterRef = useRef('')
|
|
40
|
-
|
|
41
36
|
return useMemo(() => {
|
|
42
37
|
const dbclickLock = () => {
|
|
43
38
|
if (dblclickTimeout.current !== undefined) {
|
|
@@ -123,9 +118,11 @@ export function useXYFlowEvents() {
|
|
|
123
118
|
nodesSelectable,
|
|
124
119
|
enableElementDetails,
|
|
125
120
|
setLastClickedNode,
|
|
126
|
-
|
|
121
|
+
onOpenSource,
|
|
127
122
|
openOverlay
|
|
128
123
|
} = diagramApi.getState()
|
|
124
|
+
const modelRef = DiagramNode.modelRef(xynode.data.element)
|
|
125
|
+
const deploymentRef = DiagramNode.deploymentRef(xynode.data.element)
|
|
129
126
|
setLastClickedNode(xynode.id)
|
|
130
127
|
// if we focused on a node, and clicked on another node - focus on the clicked node
|
|
131
128
|
const shallChangeFocus = !!focusedNodeId && focusedNodeId !== xynode.id
|
|
@@ -134,8 +131,16 @@ export function useXYFlowEvents() {
|
|
|
134
131
|
|
|
135
132
|
let stopPropagation = false
|
|
136
133
|
|
|
137
|
-
if (clickedRecently && !!
|
|
138
|
-
|
|
134
|
+
if (clickedRecently && !!onOpenSource && (modelRef || deploymentRef)) {
|
|
135
|
+
if (modelRef) {
|
|
136
|
+
onOpenSource({
|
|
137
|
+
element: modelRef
|
|
138
|
+
})
|
|
139
|
+
} else if (deploymentRef) {
|
|
140
|
+
onOpenSource({
|
|
141
|
+
deployment: deploymentRef
|
|
142
|
+
})
|
|
143
|
+
}
|
|
139
144
|
stopPropagation = true
|
|
140
145
|
}
|
|
141
146
|
|
|
@@ -152,7 +157,7 @@ export function useXYFlowEvents() {
|
|
|
152
157
|
stopPropagation = true
|
|
153
158
|
break
|
|
154
159
|
}
|
|
155
|
-
case !clickedRecently && focusedNodeId === xynode.id && enableElementDetails: {
|
|
160
|
+
case !clickedRecently && modelRef && focusedNodeId === xynode.id && enableElementDetails: {
|
|
156
161
|
openOverlay({
|
|
157
162
|
elementDetails: xynode.data.element.id
|
|
158
163
|
})
|
|
@@ -160,7 +165,9 @@ export function useXYFlowEvents() {
|
|
|
160
165
|
break
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
|
-
} else if (
|
|
168
|
+
} else if (
|
|
169
|
+
enableElementDetails && modelRef && (clickedRecently || focusedNodeId === xynode.id) && !onNodeClick
|
|
170
|
+
) {
|
|
164
171
|
openOverlay({
|
|
165
172
|
elementDetails: xynode.data.element.id
|
|
166
173
|
})
|
|
@@ -198,6 +205,7 @@ export function useXYFlowEvents() {
|
|
|
198
205
|
focusedNodeId,
|
|
199
206
|
xystore,
|
|
200
207
|
nodesSelectable,
|
|
208
|
+
onOpenSource,
|
|
201
209
|
focusOnNode,
|
|
202
210
|
onEdgeClick,
|
|
203
211
|
setLastClickedEdge
|
|
@@ -231,6 +239,12 @@ export function useXYFlowEvents() {
|
|
|
231
239
|
event.stopPropagation()
|
|
232
240
|
return
|
|
233
241
|
}
|
|
242
|
+
} else if (onOpenSource && !onEdgeClick) {
|
|
243
|
+
onOpenSource({
|
|
244
|
+
relation: first(xyedge.data.edge.relations)!
|
|
245
|
+
})
|
|
246
|
+
event.stopPropagation()
|
|
247
|
+
return
|
|
234
248
|
} else if (nodesSelectable) {
|
|
235
249
|
xystore.getState().addSelectedEdges([xyedge.id])
|
|
236
250
|
if (!onEdgeClick) {
|
|
@@ -286,33 +300,15 @@ export function useXYFlowEvents() {
|
|
|
286
300
|
diagramApi.setState({ viewportChanged }, false, `viewport-changed: ${viewportChanged}`)
|
|
287
301
|
}
|
|
288
302
|
},
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
diagramApi.getState().setHoveredNode(xynode.id)
|
|
292
|
-
},
|
|
293
|
-
onNodeMouseLeave: (_event, xynode) => {
|
|
294
|
-
const { hoveredNodeId, setHoveredNode } = diagramApi.getState()
|
|
295
|
-
if (hoveredNodeId === xynode.id) {
|
|
296
|
-
setHoveredNode(null)
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
onEdgeMouseEnter: (_event, { id, source, target }) => {
|
|
300
|
-
const { hoveredNodeId, focusedNodeId, setHoveredEdge, setHoveredNode } = diagramApi.getState()
|
|
303
|
+
onEdgeMouseEnter: (_event, { id }) => {
|
|
304
|
+
const { setHoveredEdge } = diagramApi.getState()
|
|
301
305
|
setHoveredEdge(id)
|
|
302
|
-
if ((focusedNodeId === source || focusedNodeId === target) && focusedNodeId !== hoveredNodeId) {
|
|
303
|
-
const next = hoveredNodeFromOnEdgeEnterRef.current = source === focusedNodeId ? target : source
|
|
304
|
-
setHoveredNode(next)
|
|
305
|
-
}
|
|
306
306
|
},
|
|
307
307
|
onEdgeMouseLeave: (_event, xyedge) => {
|
|
308
|
-
const { hoveredEdgeId, setHoveredEdge
|
|
308
|
+
const { hoveredEdgeId, setHoveredEdge } = diagramApi.getState()
|
|
309
309
|
if (hoveredEdgeId === xyedge.id) {
|
|
310
310
|
setHoveredEdge(null)
|
|
311
311
|
}
|
|
312
|
-
if (hoveredNodeId === hoveredNodeFromOnEdgeEnterRef.current) {
|
|
313
|
-
setHoveredNode(null)
|
|
314
|
-
}
|
|
315
|
-
hoveredNodeFromOnEdgeEnterRef.current = ''
|
|
316
312
|
}
|
|
317
313
|
}) satisfies XYFlowEventHandlers
|
|
318
314
|
}, [diagramApi])
|
package/src/xyflow/utils.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { InternalNode, Rect, XYPosition } from '@xyflow/react'
|
|
|
4
4
|
import { getNodeDimensions } from '@xyflow/system'
|
|
5
5
|
import { Bezier } from 'bezier-js'
|
|
6
6
|
import { isArray } from 'remeda'
|
|
7
|
-
import type {
|
|
7
|
+
import type { DiagramFlowTypes } from './types'
|
|
8
8
|
|
|
9
9
|
export function toDomPrecision(v: number | null) {
|
|
10
10
|
if (v === null) {
|
|
@@ -17,7 +17,7 @@ export function distance(a: XYPosition, b: XYPosition) {
|
|
|
17
17
|
return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2))
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export const nodeToRect = (nd:
|
|
20
|
+
export const nodeToRect = (nd: DiagramFlowTypes.InternalNode): Rect => ({
|
|
21
21
|
x: nd.internals.positionAbsolute.x,
|
|
22
22
|
y: nd.internals.positionAbsolute.y,
|
|
23
23
|
width: nd.measured.width ?? nd.width ?? nd.data.element.width,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { fallbackVar, style } from '@vanilla-extract/css'
|
|
2
|
-
import { mantine, vars } from '../theme-vars'
|
|
3
|
-
|
|
4
|
-
export const panel = style({
|
|
5
|
-
top: fallbackVar(vars.optionsPanel.top, '1rem'),
|
|
6
|
-
right: fallbackVar(vars.optionsPanel.right, '1rem'),
|
|
7
|
-
margin: 0,
|
|
8
|
-
boxShadow: mantine.shadows.xl
|
|
9
|
-
})
|
package/src/ui/OptionsPanel.tsx
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Card } from '@mantine/core'
|
|
2
|
-
import { useOnSelectionChange } from '@xyflow/react'
|
|
3
|
-
import clsx from 'clsx'
|
|
4
|
-
import { deepEqual as eq } from 'fast-equals'
|
|
5
|
-
import { AnimatePresence, m } from 'framer-motion'
|
|
6
|
-
import { useState } from 'react'
|
|
7
|
-
import { useDiagramState } from '../hooks/useDiagramState'
|
|
8
|
-
import { NodeOptions } from './options/NodeOptions'
|
|
9
|
-
import * as styles from './OptionsPanel.css'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated
|
|
13
|
-
*/
|
|
14
|
-
export function OptionsPanel() {
|
|
15
|
-
const { isFocused, viewId } = useDiagramState(s => ({
|
|
16
|
-
viewId: s.view.id,
|
|
17
|
-
isFocused: s.focusedNodeId !== null || s.activeWalkthrough !== null
|
|
18
|
-
}))
|
|
19
|
-
const [selected, setSelected] = useState<{
|
|
20
|
-
nodes: string[]
|
|
21
|
-
edges: string[]
|
|
22
|
-
}>({
|
|
23
|
-
nodes: [],
|
|
24
|
-
edges: []
|
|
25
|
-
})
|
|
26
|
-
useOnSelectionChange({
|
|
27
|
-
onChange: ({ nodes, edges }) => {
|
|
28
|
-
const newSelected = {
|
|
29
|
-
nodes: nodes.map(n => n.id).sort(),
|
|
30
|
-
edges: edges.map(e => e.id).sort()
|
|
31
|
-
}
|
|
32
|
-
if (!eq(selected, newSelected)) {
|
|
33
|
-
setSelected(newSelected)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
const { nodes } = selected
|
|
38
|
-
// const hasAnySelection = !isFocused && (nodes.length > 0 || edges.length > 0)
|
|
39
|
-
const hasAnySelection = !isFocused && nodes.length > 0
|
|
40
|
-
return (
|
|
41
|
-
<AnimatePresence mode="wait">
|
|
42
|
-
{hasAnySelection && (
|
|
43
|
-
<m.div
|
|
44
|
-
key={viewId}
|
|
45
|
-
initial={{ opacity: 0, scale: 0.85 }}
|
|
46
|
-
animate={{ opacity: 1, scale: 1 }}
|
|
47
|
-
exit={{
|
|
48
|
-
opacity: 0,
|
|
49
|
-
scale: 0.85
|
|
50
|
-
}}
|
|
51
|
-
transition={{ duration: 0.14 }}
|
|
52
|
-
className={clsx('react-flow__panel', styles.panel)}
|
|
53
|
-
style={{
|
|
54
|
-
transformOrigin: 'center right',
|
|
55
|
-
maxWidth: '320px'
|
|
56
|
-
}}
|
|
57
|
-
>
|
|
58
|
-
<Card shadow="md">
|
|
59
|
-
{nodes.length > 0 && <NodeOptions selectedNodeIds={nodes} />}
|
|
60
|
-
{
|
|
61
|
-
/* nodes.length === 0 && edges.length > 0 && (
|
|
62
|
-
<EdgeOptions selectedEdgeIds={edges} />
|
|
63
|
-
) */
|
|
64
|
-
}
|
|
65
|
-
</Card>
|
|
66
|
-
</m.div>
|
|
67
|
-
)}
|
|
68
|
-
</AnimatePresence>
|
|
69
|
-
)
|
|
70
|
-
}
|