@likec4/diagram 1.18.0 → 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 +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
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type BorderStyle,
|
|
3
|
-
defaultTheme,
|
|
4
|
-
DiagramNode,
|
|
5
3
|
type Element,
|
|
6
|
-
ElementShapes,
|
|
7
4
|
type Fqn,
|
|
8
5
|
type NonEmptyArray,
|
|
9
6
|
type ThemeColor,
|
|
10
|
-
type ViewChange
|
|
7
|
+
type ViewChange,
|
|
8
|
+
defaultTheme,
|
|
9
|
+
DiagramNode,
|
|
10
|
+
ElementShapes,
|
|
11
11
|
} from '@likec4/core'
|
|
12
12
|
import {
|
|
13
|
+
type PopoverProps,
|
|
13
14
|
ActionIcon,
|
|
14
15
|
Box,
|
|
15
16
|
Button,
|
|
@@ -26,7 +27,6 @@ import {
|
|
|
26
27
|
Paper,
|
|
27
28
|
Popover,
|
|
28
29
|
PopoverDropdown,
|
|
29
|
-
type PopoverProps,
|
|
30
30
|
PopoverTarget,
|
|
31
31
|
rem,
|
|
32
32
|
SegmentedControl,
|
|
@@ -35,10 +35,10 @@ import {
|
|
|
35
35
|
Stack,
|
|
36
36
|
Text,
|
|
37
37
|
Tooltip as MantineTooltip,
|
|
38
|
-
TooltipGroup
|
|
38
|
+
TooltipGroup,
|
|
39
39
|
} from '@mantine/core'
|
|
40
40
|
import { IconCheck, IconFileSymlink, IconSelector, IconTransform } from '@tabler/icons-react'
|
|
41
|
-
import {
|
|
41
|
+
import { type NodeToolbarProps, NodeToolbar } from '@xyflow/react'
|
|
42
42
|
import clsx from 'clsx'
|
|
43
43
|
import { useEffect, useState } from 'react'
|
|
44
44
|
import type { MergeExclusive } from 'type-fest'
|
|
@@ -55,12 +55,12 @@ const {
|
|
|
55
55
|
const themedColors = [
|
|
56
56
|
{ key: 'primary', value: primary.fill },
|
|
57
57
|
{ key: 'secondary', value: secondary.fill },
|
|
58
|
-
{ key: 'muted', value: muted.fill }
|
|
58
|
+
{ key: 'muted', value: muted.fill },
|
|
59
59
|
] satisfies Array<{ key: ThemeColor; value: string }>
|
|
60
60
|
|
|
61
61
|
const colors = keys(otherColors).map(key => ({
|
|
62
62
|
key,
|
|
63
|
-
value: defaultTheme.elements[key].fill
|
|
63
|
+
value: defaultTheme.elements[key].fill,
|
|
64
64
|
}))
|
|
65
65
|
|
|
66
66
|
type ThemeColorKey = typeof themedColors[0]['key']
|
|
@@ -73,7 +73,7 @@ const Tooltip = MantineTooltip.withProps({
|
|
|
73
73
|
closeDelay: 150,
|
|
74
74
|
label: '',
|
|
75
75
|
children: null,
|
|
76
|
-
offset: 4
|
|
76
|
+
offset: 4,
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
type ToolbarProps = NodeToolbarProps & {
|
|
@@ -94,17 +94,17 @@ export function CompoundToolbar({
|
|
|
94
94
|
const diagramApi = useDiagramStoreApi()
|
|
95
95
|
const {
|
|
96
96
|
hasGoToSource,
|
|
97
|
-
enableRelationshipBrowser
|
|
97
|
+
enableRelationshipBrowser,
|
|
98
98
|
} = useDiagramState(s => ({
|
|
99
99
|
hasGoToSource: !!s.onOpenSource,
|
|
100
|
-
enableRelationshipBrowser: s.enableRelationshipBrowser
|
|
100
|
+
enableRelationshipBrowser: s.enableRelationshipBrowser,
|
|
101
101
|
}))
|
|
102
102
|
|
|
103
103
|
const onChange: OnStyleChange = (style) => {
|
|
104
104
|
diagramApi.getState().triggerChangeElementStyle({
|
|
105
105
|
op: 'change-element-style',
|
|
106
106
|
style,
|
|
107
|
-
targets
|
|
107
|
+
targets,
|
|
108
108
|
})
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -123,7 +123,7 @@ export function CompoundToolbar({
|
|
|
123
123
|
/>
|
|
124
124
|
{hasGoToSource && modelRef && <GoToSourceButton elementId={modelRef} />}
|
|
125
125
|
{hasGoToSource && !modelRef && deploymentRef && <GoToSourceButton deploymentId={deploymentRef} />}
|
|
126
|
-
{enableRelationshipBrowser && <BrowseRelationshipsButton elementId={
|
|
126
|
+
{enableRelationshipBrowser && !!modelRef && <BrowseRelationshipsButton elementId={modelRef} />}
|
|
127
127
|
</Toolbar>
|
|
128
128
|
)
|
|
129
129
|
}
|
|
@@ -167,10 +167,10 @@ export function ElementToolbar({
|
|
|
167
167
|
const diagramApi = useDiagramStoreApi()
|
|
168
168
|
const {
|
|
169
169
|
hasGoToSource,
|
|
170
|
-
enableRelationshipBrowser
|
|
170
|
+
enableRelationshipBrowser,
|
|
171
171
|
} = useDiagramState(s => ({
|
|
172
172
|
hasGoToSource: !!s.onOpenSource,
|
|
173
|
-
enableRelationshipBrowser: s.enableRelationshipBrowser
|
|
173
|
+
enableRelationshipBrowser: s.enableRelationshipBrowser,
|
|
174
174
|
}))
|
|
175
175
|
const portalProps = useMantinePortalProps()
|
|
176
176
|
|
|
@@ -178,7 +178,7 @@ export function ElementToolbar({
|
|
|
178
178
|
diagramApi.getState().triggerChangeElementStyle({
|
|
179
179
|
op: 'change-element-style',
|
|
180
180
|
style,
|
|
181
|
-
targets
|
|
181
|
+
targets,
|
|
182
182
|
})
|
|
183
183
|
}
|
|
184
184
|
|
|
@@ -196,8 +196,8 @@ export function ElementToolbar({
|
|
|
196
196
|
offset={2}
|
|
197
197
|
styles={{
|
|
198
198
|
item: {
|
|
199
|
-
padding: 'calc(var(--mantine-spacing-xs) / 1.5) var(--mantine-spacing-xs)'
|
|
200
|
-
}
|
|
199
|
+
padding: 'calc(var(--mantine-spacing-xs) / 1.5) var(--mantine-spacing-xs)',
|
|
200
|
+
},
|
|
201
201
|
}}
|
|
202
202
|
{...portalProps}
|
|
203
203
|
>
|
|
@@ -243,7 +243,7 @@ export function ElementToolbar({
|
|
|
243
243
|
/>
|
|
244
244
|
{hasGoToSource && modelRef && <GoToSourceButton elementId={modelRef} />}
|
|
245
245
|
{hasGoToSource && !modelRef && deploymentRef && <GoToSourceButton deploymentId={deploymentRef} />}
|
|
246
|
-
{enableRelationshipBrowser && <BrowseRelationshipsButton elementId={
|
|
246
|
+
{enableRelationshipBrowser && !!modelRef && <BrowseRelationshipsButton elementId={modelRef} />}
|
|
247
247
|
</Toolbar>
|
|
248
248
|
)
|
|
249
249
|
}
|
|
@@ -268,11 +268,11 @@ function GoToSourceButton(props: MergeExclusive<{ elementId: Fqn }, { deployment
|
|
|
268
268
|
e.stopPropagation()
|
|
269
269
|
if (props.elementId) {
|
|
270
270
|
diagramApi.getState().onOpenSource?.({
|
|
271
|
-
element: props.elementId
|
|
271
|
+
element: props.elementId,
|
|
272
272
|
})
|
|
273
273
|
} else if (props.deploymentId) {
|
|
274
274
|
diagramApi.getState().onOpenSource?.({
|
|
275
|
-
deployment: props.deploymentId
|
|
275
|
+
deployment: props.deploymentId,
|
|
276
276
|
})
|
|
277
277
|
}
|
|
278
278
|
}}>
|
|
@@ -333,7 +333,7 @@ function ColorButton({
|
|
|
333
333
|
function ColorSwatches({
|
|
334
334
|
elementColor,
|
|
335
335
|
onColorPreview,
|
|
336
|
-
onChange
|
|
336
|
+
onChange,
|
|
337
337
|
}: {
|
|
338
338
|
elementColor: ThemeColor
|
|
339
339
|
onColorPreview: (color: ThemeColor | null) => void
|
|
@@ -408,7 +408,7 @@ function ColorSwatches({
|
|
|
408
408
|
|
|
409
409
|
function BorderStyleOption({
|
|
410
410
|
elementBorderStyle = 'dashed',
|
|
411
|
-
onChange
|
|
411
|
+
onChange,
|
|
412
412
|
}: {
|
|
413
413
|
elementBorderStyle: BorderStyle | undefined
|
|
414
414
|
onChange: OnStyleChange
|
|
@@ -433,14 +433,14 @@ function BorderStyleOption({
|
|
|
433
433
|
styles={{
|
|
434
434
|
label: {
|
|
435
435
|
paddingTop: 2,
|
|
436
|
-
paddingBottom: 2
|
|
437
|
-
}
|
|
436
|
+
paddingBottom: 2,
|
|
437
|
+
},
|
|
438
438
|
}}
|
|
439
439
|
data={[
|
|
440
440
|
{ label: 'Solid', value: 'solid' },
|
|
441
441
|
{ label: 'Dashed', value: 'dashed' },
|
|
442
442
|
{ label: 'Dotted', value: 'dotted' },
|
|
443
|
-
{ label: 'None', value: 'none' }
|
|
443
|
+
{ label: 'None', value: 'none' },
|
|
444
444
|
]}
|
|
445
445
|
/>
|
|
446
446
|
</Box>
|
|
@@ -449,7 +449,7 @@ function BorderStyleOption({
|
|
|
449
449
|
|
|
450
450
|
function OpacityOption({
|
|
451
451
|
elementOpacity = 100,
|
|
452
|
-
onOpacityChange
|
|
452
|
+
onOpacityChange,
|
|
453
453
|
}: {
|
|
454
454
|
elementOpacity: number | undefined
|
|
455
455
|
onOpacityChange: (opacity: number) => void
|
|
@@ -481,14 +481,14 @@ function BrowseRelationshipsButton({ elementId }: { elementId: Fqn }) {
|
|
|
481
481
|
onClick={e => {
|
|
482
482
|
e.stopPropagation()
|
|
483
483
|
diagramApi.getState().openOverlay({
|
|
484
|
-
relationshipsOf: elementId
|
|
484
|
+
relationshipsOf: elementId,
|
|
485
485
|
})
|
|
486
486
|
}}>
|
|
487
487
|
<IconTransform
|
|
488
488
|
stroke={2}
|
|
489
489
|
style={{
|
|
490
490
|
width: '72%',
|
|
491
|
-
height: '72%'
|
|
491
|
+
height: '72%',
|
|
492
492
|
}} />
|
|
493
493
|
</ActionIcon>
|
|
494
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
1
|
import { type NodeId, type NonEmptyArray, nonNullable } from '@likec4/core'
|
|
2
|
-
import type {
|
|
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,15 +1,15 @@
|
|
|
1
1
|
import { DiagramNode } from '@likec4/core'
|
|
2
2
|
import type { ReactFlowProps } from '@xyflow/react'
|
|
3
3
|
import { useMemo, useRef } from 'react'
|
|
4
|
-
import { isNonNullish, isTruthy } from 'remeda'
|
|
4
|
+
import { first, isNonNullish, isTruthy } from 'remeda'
|
|
5
5
|
import type { Simplify } from 'type-fest'
|
|
6
6
|
import { useDiagramStoreApi } from '../hooks/useDiagramState'
|
|
7
|
-
import type {
|
|
7
|
+
import type { DiagramFlowTypes } from './types'
|
|
8
8
|
|
|
9
9
|
export type XYFlowEventHandlers = Simplify<
|
|
10
10
|
Required<
|
|
11
11
|
Pick<
|
|
12
|
-
ReactFlowProps<
|
|
12
|
+
ReactFlowProps<DiagramFlowTypes.Node, DiagramFlowTypes.Edge>,
|
|
13
13
|
| 'onDoubleClick'
|
|
14
14
|
| 'onPaneClick'
|
|
15
15
|
| 'onNodeClick'
|
|
@@ -20,8 +20,6 @@ export type XYFlowEventHandlers = Simplify<
|
|
|
20
20
|
| 'onNodeContextMenu'
|
|
21
21
|
| 'onEdgeContextMenu'
|
|
22
22
|
| 'onPaneContextMenu'
|
|
23
|
-
| 'onNodeMouseEnter'
|
|
24
|
-
| 'onNodeMouseLeave'
|
|
25
23
|
| 'onEdgeMouseEnter'
|
|
26
24
|
| 'onEdgeMouseLeave'
|
|
27
25
|
>
|
|
@@ -35,10 +33,6 @@ export function useXYFlowEvents() {
|
|
|
35
33
|
|
|
36
34
|
const dblclickTimeout = useRef<number>()
|
|
37
35
|
|
|
38
|
-
// If we are in focused mode, on edge enter we want to "highlight" the other node
|
|
39
|
-
// This ref contains the id of this node
|
|
40
|
-
const hoveredNodeFromOnEdgeEnterRef = useRef('')
|
|
41
|
-
|
|
42
36
|
return useMemo(() => {
|
|
43
37
|
const dbclickLock = () => {
|
|
44
38
|
if (dblclickTimeout.current !== undefined) {
|
|
@@ -211,6 +205,7 @@ export function useXYFlowEvents() {
|
|
|
211
205
|
focusedNodeId,
|
|
212
206
|
xystore,
|
|
213
207
|
nodesSelectable,
|
|
208
|
+
onOpenSource,
|
|
214
209
|
focusOnNode,
|
|
215
210
|
onEdgeClick,
|
|
216
211
|
setLastClickedEdge
|
|
@@ -244,6 +239,12 @@ export function useXYFlowEvents() {
|
|
|
244
239
|
event.stopPropagation()
|
|
245
240
|
return
|
|
246
241
|
}
|
|
242
|
+
} else if (onOpenSource && !onEdgeClick) {
|
|
243
|
+
onOpenSource({
|
|
244
|
+
relation: first(xyedge.data.edge.relations)!
|
|
245
|
+
})
|
|
246
|
+
event.stopPropagation()
|
|
247
|
+
return
|
|
247
248
|
} else if (nodesSelectable) {
|
|
248
249
|
xystore.getState().addSelectedEdges([xyedge.id])
|
|
249
250
|
if (!onEdgeClick) {
|
|
@@ -299,33 +300,15 @@ export function useXYFlowEvents() {
|
|
|
299
300
|
diagramApi.setState({ viewportChanged }, false, `viewport-changed: ${viewportChanged}`)
|
|
300
301
|
}
|
|
301
302
|
},
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
diagramApi.getState().setHoveredNode(xynode.id)
|
|
305
|
-
},
|
|
306
|
-
onNodeMouseLeave: (_event, xynode) => {
|
|
307
|
-
const { hoveredNodeId, setHoveredNode } = diagramApi.getState()
|
|
308
|
-
if (hoveredNodeId === xynode.id) {
|
|
309
|
-
setHoveredNode(null)
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
onEdgeMouseEnter: (_event, { id, source, target }) => {
|
|
313
|
-
const { hoveredNodeId, focusedNodeId, setHoveredEdge, setHoveredNode } = diagramApi.getState()
|
|
303
|
+
onEdgeMouseEnter: (_event, { id }) => {
|
|
304
|
+
const { setHoveredEdge } = diagramApi.getState()
|
|
314
305
|
setHoveredEdge(id)
|
|
315
|
-
if ((focusedNodeId === source || focusedNodeId === target) && focusedNodeId !== hoveredNodeId) {
|
|
316
|
-
const next = hoveredNodeFromOnEdgeEnterRef.current = source === focusedNodeId ? target : source
|
|
317
|
-
setHoveredNode(next)
|
|
318
|
-
}
|
|
319
306
|
},
|
|
320
307
|
onEdgeMouseLeave: (_event, xyedge) => {
|
|
321
|
-
const { hoveredEdgeId, setHoveredEdge
|
|
308
|
+
const { hoveredEdgeId, setHoveredEdge } = diagramApi.getState()
|
|
322
309
|
if (hoveredEdgeId === xyedge.id) {
|
|
323
310
|
setHoveredEdge(null)
|
|
324
311
|
}
|
|
325
|
-
if (hoveredNodeId === hoveredNodeFromOnEdgeEnterRef.current) {
|
|
326
|
-
setHoveredNode(null)
|
|
327
|
-
}
|
|
328
|
-
hoveredNodeFromOnEdgeEnterRef.current = ''
|
|
329
312
|
}
|
|
330
313
|
}) satisfies XYFlowEventHandlers
|
|
331
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,64 +0,0 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react'
|
|
2
|
-
import { isEmpty, isString } from 'remeda'
|
|
3
|
-
|
|
4
|
-
export function useFramerAnimateVariants() {
|
|
5
|
-
const [variants, setVariants] = useState<string[] | null>(null)
|
|
6
|
-
|
|
7
|
-
const handlers = useMemo(() => {
|
|
8
|
-
const getTarget = (e: MouseEvent | undefined) => {
|
|
9
|
-
try {
|
|
10
|
-
// 🤔 Sometimes target is null
|
|
11
|
-
return (e?.target as HTMLElement | null)?.closest('[data-animate-target]')?.getAttribute('data-animate-target')
|
|
12
|
-
?? null
|
|
13
|
-
} catch (_e) {
|
|
14
|
-
console.warn(`Failed to get animate target`, _e)
|
|
15
|
-
// noop
|
|
16
|
-
return null
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const onHoverStart = (e: MouseEvent) => {
|
|
21
|
-
e?.stopPropagation()
|
|
22
|
-
const hoverTarget = getTarget(e)
|
|
23
|
-
if (!isString(hoverTarget) || isEmpty(hoverTarget)) {
|
|
24
|
-
setVariants(null)
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
setVariants(['hovered', `hovered:${hoverTarget}`])
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const resetVariants = (e: MouseEvent) => {
|
|
31
|
-
e?.stopPropagation()
|
|
32
|
-
setVariants(null)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return ({
|
|
36
|
-
onTapStart: (e: MouseEvent) => {
|
|
37
|
-
e?.stopPropagation()
|
|
38
|
-
const tapTarget = getTarget(e)
|
|
39
|
-
if (!isString(tapTarget)) {
|
|
40
|
-
setVariants(null)
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
if (isEmpty(tapTarget)) {
|
|
44
|
-
setVariants([
|
|
45
|
-
'hovered',
|
|
46
|
-
'tap'
|
|
47
|
-
])
|
|
48
|
-
} else {
|
|
49
|
-
setVariants([
|
|
50
|
-
'hovered',
|
|
51
|
-
`hovered:${tapTarget}`,
|
|
52
|
-
`tap:${tapTarget}`
|
|
53
|
-
])
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
onHoverStart,
|
|
57
|
-
onHoverEnd: resetVariants,
|
|
58
|
-
onTapCancel: resetVariants,
|
|
59
|
-
onTap: onHoverStart
|
|
60
|
-
})
|
|
61
|
-
}, [setVariants])
|
|
62
|
-
|
|
63
|
-
return [variants, handlers] as const
|
|
64
|
-
}
|