@likec4/diagram 1.27.0 → 1.27.2
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/bundle/index.js +2343 -6880
- package/dist/LikeC4Diagram.js +3 -9
- package/dist/LikeC4Diagram.props.d.ts +5 -3
- package/dist/StaticLikeC4Diagram.js +1 -1
- package/dist/_virtual/set.js +5 -0
- package/dist/_virtual/set2.js +3 -0
- package/dist/base/BaseXYFlow.d.ts +2 -1
- package/dist/base/primitives/compound/CompoundNodeContainer.d.ts +1 -1
- package/dist/base/primitives/compound/CompoundNodeContainer.js +1 -2
- package/dist/base/primitives/edge/EdgeLabel.css.js +1 -4
- package/dist/base/primitives/edge/EdgeLabelContainer.js +1 -1
- package/dist/base/primitives/edge/EdgePath.js +0 -3
- package/dist/base/primitives/edge/edge.css.js +2 -0
- package/dist/base/primitives/element/ElementActionButtons.js +5 -10
- package/dist/base/primitives/element/ElementNodeContainer.css.js +5 -4
- package/dist/base/primitives/element/ElementShape.css.js +1 -12
- package/dist/base/primitives/element/ElementTitle.css.js +3 -2
- package/dist/base/types.js +2 -2
- package/dist/base/updateEdges.js +1 -9
- package/dist/base/updateNodes.js +1 -12
- package/dist/bundle/LikeC4View.js +2 -2
- package/dist/bundle/LikeC4View.props.d.ts +7 -7
- package/dist/components/Link.js +1 -1
- package/dist/hooks/useCurrentViewId.js +8 -2
- package/dist/hooks/useDiagram.d.ts +2659 -1996
- package/dist/hooks/useDiagram.js +16 -8
- package/dist/likec4diagram/DiagramXYFlow.js +10 -9
- package/dist/likec4diagram/custom/edges/RelationshipEdge.js +30 -41
- package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.js +1 -1
- package/dist/likec4diagram/custom/nodes/toolbar/styles.css.js +6 -1
- package/dist/likec4diagram/ui/controls/LayoutDriftNotification.js +13 -5
- package/dist/likec4diagram/ui/notation/NotationPanel.css.js +3 -3
- package/dist/likec4diagram/ui/notation/NotationPanel.js +10 -4
- package/dist/likec4diagram/useLayoutConstraints.d.ts +11 -10
- package/dist/likec4diagram/useLayoutConstraints.js +64 -61
- package/dist/node_modules/.pnpm/mnemonist@0.40.3_patch_hash_5c12abb43fcff6fd81e53021b89075d53249640d165a2556cc1e58d71201a13a/node_modules/mnemonist/set.js +369 -0
- package/dist/overlays/Overlays.js +5 -3
- package/dist/overlays/element-details/actor.d.ts +2769 -173
- package/dist/overlays/overlay/Overlay.css.d.ts +26 -2
- package/dist/overlays/overlay/Overlay.css.js +83 -16
- package/dist/overlays/overlay/Overlay.d.ts +7 -6
- package/dist/overlays/overlay/Overlay.js +39 -32
- package/dist/overlays/overlaysActor.js +2 -2
- package/dist/overlays/relationship-details/RelationshipDetails.js +113 -70
- package/dist/overlays/relationship-details/SelectEdge.d.ts +1 -1
- package/dist/overlays/relationship-details/SelectEdge.js +15 -9
- package/dist/overlays/relationship-details/_types.d.ts +4 -1
- package/dist/overlays/relationship-details/actor.d.ts +415 -128
- package/dist/overlays/relationship-details/actor.js +162 -53
- package/dist/overlays/relationship-details/compute.d.ts +12 -0
- package/dist/overlays/relationship-details/compute.js +139 -0
- package/dist/overlays/relationship-details/custom/ElementActions.js +27 -5
- package/dist/overlays/relationship-details/custom/edgeTypes.js +1 -1
- package/dist/overlays/relationship-details/custom/nodeTypes.d.ts +2 -1
- package/dist/overlays/relationship-details/hooks.d.ts +336 -6
- package/dist/overlays/relationship-details/hooks.js +9 -7
- package/dist/overlays/relationship-details/layout-to-xyflow.d.ts +12 -0
- package/dist/overlays/relationship-details/layout-to-xyflow.js +149 -0
- package/dist/overlays/relationship-details/layout.d.ts +22 -0
- package/dist/overlays/relationship-details/layout.js +314 -0
- package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +3 -1
- package/dist/overlays/relationships-browser/RelationshipsBrowser.js +2 -2
- package/dist/overlays/relationships-browser/SelectElement.js +4 -4
- package/dist/overlays/relationships-browser/_types.d.ts +2 -0
- package/dist/overlays/relationships-browser/actor.d.ts +130 -14
- package/dist/overlays/relationships-browser/actor.js +30 -16
- package/dist/overlays/relationships-browser/custom/ElementActions.js +5 -3
- package/dist/overlays/relationships-browser/custom/edgeTypes.d.ts +3 -1
- package/dist/overlays/relationships-browser/custom/edgeTypes.js +1 -1
- package/dist/overlays/relationships-browser/hooks.d.ts +3 -1
- package/dist/overlays/relationships-browser/hooks.js +1 -1
- package/dist/overlays/relationships-browser/{-useRelationshipsView.d.ts → layout.d.ts} +2 -0
- package/dist/overlays/relationships-browser/{-useRelationshipsView.js → layout.js} +19 -2
- package/dist/overlays/relationships-browser/useViewToNodesEdges.d.ts +1 -1
- package/dist/overlays/relationships-browser/useViewToNodesEdges.js +3 -1
- package/dist/packages/core/src/compute-view/relationships-view/compute.js +1 -1
- package/dist/packages/core/src/model/connection/model/ConnectionModel.js +121 -0
- package/dist/packages/core/src/model/connection/model/find.js +39 -0
- package/dist/packages/core/src/model/connection/ops.js +7 -0
- package/dist/packages/core/src/utils/const.js +3 -0
- package/dist/packages/core/src/utils/fqn.js +9 -1
- package/dist/packages/core/src/utils/iterable/find.js +21 -0
- package/dist/packages/core/src/utils/iterable/some.js +21 -0
- package/dist/packages/core/src/utils/set.js +48 -0
- package/dist/packages/core/src/utils/string-hash.js +13 -0
- package/dist/state/DiagramActorProvider.d.ts +4 -2
- package/dist/state/DiagramActorProvider.js +30 -37
- package/dist/state/assign.js +2 -2
- package/dist/state/diagram-machine.d.ts +1731 -1040
- package/dist/state/diagram-machine.js +126 -60
- package/dist/state/syncManualLayoutActor.d.ts +1 -1
- package/dist/styles.css.js +1 -1
- package/package.json +11 -11
- package/src/LikeC4Diagram.props.ts +7 -3
- package/src/LikeC4Diagram.tsx +2 -8
- package/src/StaticLikeC4Diagram.tsx +1 -1
- package/src/base/BaseXYFlow.tsx +2 -1
- package/src/base/primitives/compound/CompoundNodeContainer.tsx +1 -3
- package/src/base/primitives/edge/EdgeLabel.css.ts +1 -4
- package/src/base/primitives/edge/EdgeLabelContainer.tsx +1 -1
- package/src/base/primitives/edge/EdgePath.tsx +0 -3
- package/src/base/primitives/edge/edge.css.ts +2 -0
- package/src/base/primitives/element/ElementActionButtons.tsx +6 -7
- package/src/base/primitives/element/ElementNodeContainer.css.ts +5 -4
- package/src/base/primitives/element/ElementShape.css.ts +1 -12
- package/src/base/primitives/element/ElementTitle.css.ts +3 -2
- package/src/base/types.ts +2 -7
- package/src/base/updateEdges.ts +8 -8
- package/src/base/updateNodes.ts +11 -11
- package/src/bundle/LikeC4View.props.ts +7 -7
- package/src/bundle/LikeC4View.tsx +2 -2
- package/src/components/Link.tsx +3 -1
- package/src/hooks/useCurrentViewId.ts +4 -2
- package/src/hooks/useDiagram.ts +18 -9
- package/src/likec4diagram/DiagramXYFlow.tsx +11 -9
- package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +39 -48
- package/src/likec4diagram/custom/nodes/toolbar/Toolbar.tsx +2 -2
- package/src/likec4diagram/custom/nodes/toolbar/styles.css.ts +5 -0
- package/src/likec4diagram/ui/controls/LayoutDriftNotification.tsx +8 -4
- package/src/likec4diagram/ui/notation/NotationPanel.css.ts +2 -2
- package/src/likec4diagram/ui/notation/NotationPanel.tsx +8 -6
- package/src/likec4diagram/useLayoutConstraints.ts +84 -89
- package/src/overlays/Overlays.tsx +5 -3
- package/src/overlays/overlay/Overlay.css.ts +83 -15
- package/src/overlays/overlay/Overlay.tsx +52 -41
- package/src/overlays/overlaysActor.ts +1 -1
- package/src/overlays/relationship-details/RelationshipDetails.tsx +131 -68
- package/src/overlays/relationship-details/SelectEdge.tsx +19 -12
- package/src/overlays/relationship-details/_types.ts +3 -1
- package/src/overlays/relationship-details/actor.ts +217 -68
- package/src/overlays/relationship-details/compute.ts +186 -0
- package/src/overlays/relationship-details/custom/ElementActions.tsx +27 -18
- package/src/overlays/relationship-details/custom/edgeTypes.tsx +1 -1
- package/src/overlays/relationship-details/hooks.ts +10 -8
- package/src/overlays/relationship-details/layout-to-xyflow.ts +195 -0
- package/src/overlays/relationship-details/layout.ts +470 -0
- package/src/overlays/relationships-browser/RelationshipsBrowser.tsx +2 -2
- package/src/overlays/relationships-browser/SelectElement.tsx +5 -5
- package/src/overlays/relationships-browser/_types.ts +2 -0
- package/src/overlays/relationships-browser/actor.ts +39 -14
- package/src/overlays/relationships-browser/custom/ElementActions.tsx +5 -3
- package/src/overlays/relationships-browser/custom/edgeTypes.tsx +1 -1
- package/src/overlays/relationships-browser/hooks.ts +2 -2
- package/src/overlays/relationships-browser/{-useRelationshipsView.ts → layout.ts} +23 -13
- package/src/overlays/relationships-browser/useViewToNodesEdges.ts +3 -1
- package/src/state/DiagramActorProvider.tsx +40 -50
- package/src/state/assign.ts +2 -2
- package/src/state/diagram-machine.ts +151 -75
- package/dist/overlays/relationship-details/useLayoutedDetails.d.ts +0 -19
- package/dist/overlays/relationship-details/useLayoutedDetails.js +0 -267
- package/src/overlays/relationship-details/useLayoutedDetails.ts +0 -376
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { css } from '@likec4/styles/css'
|
|
1
|
+
import { css, sva } from '@likec4/styles/css'
|
|
2
2
|
|
|
3
3
|
export const backdropBlur = '--_blur'
|
|
4
4
|
export const backdropOpacity = '--_opacity'
|
|
5
|
-
const backdropColor = '--backdrop-color'
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
export const level = '--_level'
|
|
7
|
+
const offset = '--_offset'
|
|
8
|
+
const inset = '--_inset'
|
|
9
|
+
|
|
10
|
+
const borderRadius = '--_border-radius'
|
|
11
|
+
const dialog = css.raw({
|
|
9
12
|
boxSizing: 'border-box',
|
|
10
13
|
margin: 0,
|
|
11
14
|
position: 'fixed',
|
|
12
|
-
inset: '3rem',
|
|
13
15
|
width: 'auto',
|
|
14
16
|
height: 'auto',
|
|
15
17
|
maxWidth: '100vw',
|
|
@@ -18,9 +20,11 @@ export const dialog = css({
|
|
|
18
20
|
shadow: 'xl',
|
|
19
21
|
border: 'transparent',
|
|
20
22
|
outline: 'none',
|
|
21
|
-
borderRadius: borderRadius
|
|
22
|
-
padding: '6px',
|
|
23
|
+
borderRadius: `var(${borderRadius})`,
|
|
23
24
|
[backdropBlur]: '0px',
|
|
25
|
+
[level]: '0',
|
|
26
|
+
[offset]: '0px',
|
|
27
|
+
[inset]: 'calc((1 + var(--_level) * 0.5) * var(--_offset))',
|
|
24
28
|
[backdropOpacity]: '0%',
|
|
25
29
|
_backdrop: {
|
|
26
30
|
cursor: 'zoom-out',
|
|
@@ -30,29 +34,93 @@ export const dialog = css({
|
|
|
30
34
|
_light: `[rgb(15 15 15/ var(${backdropOpacity}))]`,
|
|
31
35
|
},
|
|
32
36
|
},
|
|
33
|
-
mdDown: {
|
|
34
|
-
borderRadius: 'sm',
|
|
35
|
-
inset: '2rem',
|
|
36
|
-
width: 'calc(100vw - 4rem)',
|
|
37
|
-
height: 'calc(100vh - 4rem)',
|
|
38
|
-
},
|
|
39
37
|
smDown: {
|
|
38
|
+
[borderRadius]: '0px',
|
|
40
39
|
border: 'none',
|
|
41
40
|
inset: 0,
|
|
42
41
|
padding: 0,
|
|
42
|
+
// [offset]: '0px',
|
|
43
|
+
// [inset]: '0px',
|
|
43
44
|
width: '100vw',
|
|
44
45
|
height: '100vh',
|
|
45
46
|
},
|
|
47
|
+
sm: {
|
|
48
|
+
inset: '[var(--_inset) var(--_offset) var(--_offset) var(--_inset)]',
|
|
49
|
+
width: 'calc(100vw - var(--_offset) - var(--_inset))',
|
|
50
|
+
height: 'calc(100vh - var(--_offset) - var(--_inset))',
|
|
51
|
+
[borderRadius]: '6px',
|
|
52
|
+
padding: '6px',
|
|
53
|
+
[offset]: '1rem',
|
|
54
|
+
},
|
|
55
|
+
md: {
|
|
56
|
+
[offset]: '1rem',
|
|
57
|
+
},
|
|
58
|
+
lg: {
|
|
59
|
+
[offset]: '2rem',
|
|
60
|
+
},
|
|
61
|
+
xl: {
|
|
62
|
+
[offset]: '4rem',
|
|
63
|
+
},
|
|
64
|
+
// inset: '[calc(2rem + var(--_level, 0) * 1rem), 2rem, 2rem, 2rem]',
|
|
65
|
+
// width: 'calc(100vw - 4rem)',
|
|
66
|
+
// height: 'calc(100vh - 4rem - var(--_level, 0) * 1rem)',
|
|
67
|
+
// },
|
|
68
|
+
// lg: {
|
|
69
|
+
// inset: '[calc(4rem + var(--_level, 0) * 1rem), 4rem, 4rem, 4rem]',
|
|
70
|
+
// width: 'calc(100vw - 8rem)',
|
|
71
|
+
// height: 'calc(100vh - 8rem)',
|
|
72
|
+
// },
|
|
73
|
+
// xl: {
|
|
74
|
+
// [borderRadius]: '8px',
|
|
75
|
+
// padding: '8px',
|
|
76
|
+
// inset: '[calc(5rem + var(--_level, 0) * 1rem), 5rem, 5rem, 5rem]',
|
|
77
|
+
// width: 'calc(100vw - 10rem)',
|
|
78
|
+
// height: 'calc(100vh - 10rem - var(--_level, 0) * 1rem)',
|
|
79
|
+
// },
|
|
46
80
|
})
|
|
47
81
|
|
|
48
|
-
|
|
82
|
+
const body = css.raw({
|
|
49
83
|
position: 'relative',
|
|
50
84
|
containerName: 'overlay-dialog',
|
|
51
85
|
containerType: 'size',
|
|
52
86
|
border: `0 solid transparent`,
|
|
53
|
-
borderRadius: `calc(${borderRadius} - 2px)`,
|
|
54
87
|
background: 'mantine.colors.body',
|
|
55
88
|
overflow: 'hidden',
|
|
56
89
|
width: '100%',
|
|
57
90
|
height: '100%',
|
|
91
|
+
sm: {
|
|
92
|
+
borderRadius: `calc(var(${borderRadius}) - 2px)`,
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
export const overlay = sva({
|
|
97
|
+
slots: ['dialog', 'body'],
|
|
98
|
+
base: {
|
|
99
|
+
dialog: dialog,
|
|
100
|
+
body: body,
|
|
101
|
+
},
|
|
102
|
+
variants: {
|
|
103
|
+
level: {
|
|
104
|
+
0: {
|
|
105
|
+
dialog: {
|
|
106
|
+
[level]: '0',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
1: {
|
|
110
|
+
dialog: {
|
|
111
|
+
[level]: '1',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
2: {
|
|
115
|
+
dialog: {
|
|
116
|
+
[level]: '2',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
3: {
|
|
120
|
+
dialog: {
|
|
121
|
+
[level]: '3',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
58
126
|
})
|
|
@@ -5,28 +5,30 @@ import {
|
|
|
5
5
|
} from '@mantine/core'
|
|
6
6
|
import { useMergedRef } from '@mantine/hooks'
|
|
7
7
|
import { useDebouncedCallback, useSyncedRef, useTimeoutEffect } from '@react-hookz/web'
|
|
8
|
-
import { type HTMLMotionProps, m } from 'framer-motion'
|
|
8
|
+
import { type HTMLMotionProps, m, useReducedMotionConfig } from 'framer-motion'
|
|
9
9
|
import { type PropsWithChildren, forwardRef, useLayoutEffect, useRef, useState } from 'react'
|
|
10
10
|
import { stopPropagation } from '../../utils'
|
|
11
|
-
import
|
|
11
|
+
import { backdropBlur, backdropOpacity, overlay as overlayCVA } from './Overlay.css'
|
|
12
12
|
|
|
13
|
-
type OverlayProps = PropsWithChildren<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
onClose: () => void
|
|
20
|
-
onClick?: never
|
|
13
|
+
type OverlayProps = PropsWithChildren<{
|
|
14
|
+
overlayLevel?: 0 | 1 | 2 | 3
|
|
15
|
+
className?: string
|
|
16
|
+
classes?: {
|
|
17
|
+
dialog?: string
|
|
18
|
+
body?: string
|
|
21
19
|
}
|
|
22
|
-
|
|
20
|
+
onClose: () => void
|
|
21
|
+
onClick?: never
|
|
22
|
+
}>
|
|
23
23
|
|
|
24
24
|
export const Overlay = forwardRef<HTMLDialogElement, OverlayProps>(
|
|
25
|
-
({ children, onClose, className, classes, ...rest }, ref) => {
|
|
25
|
+
({ children, onClose, className, classes, overlayLevel = 0, ...rest }, ref) => {
|
|
26
26
|
const [opened, setOpened] = useState(false)
|
|
27
27
|
const dialogRef = useRef<HTMLDialogElement>(null)
|
|
28
28
|
const isClosingRef = useRef(false)
|
|
29
29
|
|
|
30
|
+
const motionNotReduced = useReducedMotionConfig() !== true
|
|
31
|
+
|
|
30
32
|
const onCloseRef = useSyncedRef(onClose)
|
|
31
33
|
const close = useDebouncedCallback(
|
|
32
34
|
() => {
|
|
@@ -54,44 +56,53 @@ export const Overlay = forwardRef<HTMLDialogElement, OverlayProps>(
|
|
|
54
56
|
// Move dialog to the top of the DOM
|
|
55
57
|
dialogRef.current?.showModal()
|
|
56
58
|
}
|
|
57
|
-
},
|
|
59
|
+
}, 20)
|
|
58
60
|
|
|
59
61
|
useTimeoutEffect(() => {
|
|
60
62
|
setOpened(true)
|
|
61
63
|
}, 120)
|
|
62
64
|
|
|
65
|
+
const styles = overlayCVA({
|
|
66
|
+
level: overlayLevel as 0 | 1 | 2 | 3,
|
|
67
|
+
})
|
|
68
|
+
|
|
63
69
|
return (
|
|
64
70
|
<m.dialog
|
|
65
71
|
ref={useMergedRef(dialogRef, ref)}
|
|
66
72
|
className={cx(RemoveScroll.classNames.fullWidth, styles.dialog, classes?.dialog, className)}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
layout
|
|
74
|
+
{...motionNotReduced
|
|
75
|
+
? ({
|
|
76
|
+
initial: {
|
|
77
|
+
[backdropBlur]: '0px',
|
|
78
|
+
[backdropOpacity]: '0%',
|
|
79
|
+
scale: overlayLevel > 0 ? 0.9 : 1.075,
|
|
80
|
+
opacity: 0,
|
|
81
|
+
},
|
|
82
|
+
animate: {
|
|
83
|
+
[backdropBlur]: overlayLevel > 0 ? '4px' : '8px',
|
|
84
|
+
[backdropOpacity]: overlayLevel > 0 ? '50%' : '60%',
|
|
85
|
+
scale: 1,
|
|
86
|
+
opacity: 1,
|
|
87
|
+
translateY: 0,
|
|
88
|
+
transition: {
|
|
89
|
+
delay: 0.075,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
exit: {
|
|
93
|
+
scale: 1.3,
|
|
94
|
+
opacity: 0,
|
|
95
|
+
translateY: -10,
|
|
96
|
+
[backdropBlur]: '0px',
|
|
97
|
+
[backdropOpacity]: '0%',
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
: {
|
|
101
|
+
initial: {
|
|
102
|
+
[backdropBlur]: '8px',
|
|
103
|
+
[backdropOpacity]: '60%',
|
|
104
|
+
},
|
|
105
|
+
}}
|
|
95
106
|
onClick={e => {
|
|
96
107
|
e.stopPropagation()
|
|
97
108
|
if ((e.target as any)?.nodeName?.toUpperCase() === 'DIALOG') {
|
|
@@ -133,8 +133,8 @@ export const overlaysActorLogic = setup({
|
|
|
133
133
|
const currentOverlay = last(context.overlays)
|
|
134
134
|
if (currentOverlay?.type === 'relationshipDetails') {
|
|
135
135
|
enqueue.sendTo(currentOverlay.id, {
|
|
136
|
+
...event,
|
|
136
137
|
type: 'navigate.to',
|
|
137
|
-
edgeId: event.edgeId,
|
|
138
138
|
})
|
|
139
139
|
return
|
|
140
140
|
}
|
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DiagramEdge, type DiagramView, ifind, invariant, isAncestor, nonNullable } from '@likec4/core'
|
|
2
2
|
import { ActionIcon, Group } from '@mantine/core'
|
|
3
3
|
import { useCallbackRef, useStateHistory } from '@mantine/hooks'
|
|
4
4
|
import { IconChevronLeft, IconChevronRight, IconX } from '@tabler/icons-react'
|
|
5
|
-
import {
|
|
5
|
+
import { useSelector } from '@xstate/react'
|
|
6
|
+
import { Panel, ReactFlowProvider, useReactFlow, useStoreApi } from '@xyflow/react'
|
|
6
7
|
import clsx from 'clsx'
|
|
8
|
+
import { deepEqual } from 'fast-equals'
|
|
7
9
|
import { AnimatePresence, LayoutGroup, m } from 'framer-motion'
|
|
8
|
-
import { memo, useEffect, useRef } from 'react'
|
|
10
|
+
import { memo, useEffect, useMemo, useRef } from 'react'
|
|
11
|
+
import { first } from 'remeda'
|
|
9
12
|
import { BaseXYFlow } from '../../base/BaseXYFlow'
|
|
13
|
+
import { useLikeC4Model } from '../../likec4model/useLikeC4Model'
|
|
10
14
|
import type { RelationshipDetailsTypes, RelationshipDetailsTypes as Types } from './_types'
|
|
11
15
|
import type { RelationshipDetailsActorRef, RelationshipDetailsSnapshot } from './actor'
|
|
16
|
+
import {
|
|
17
|
+
type RelationshipDetailsViewData,
|
|
18
|
+
computeEdgeDetailsViewData,
|
|
19
|
+
computeRelationshipDetailsViewData,
|
|
20
|
+
} from './compute'
|
|
12
21
|
import { CompoundNode, ElementNode, RelationshipEdge } from './custom'
|
|
13
22
|
import {
|
|
14
23
|
RelationshipDetailsActorContext,
|
|
15
24
|
useRelationshipDetails,
|
|
25
|
+
useRelationshipDetailsActor,
|
|
16
26
|
useRelationshipDetailsState,
|
|
17
27
|
} from './hooks'
|
|
28
|
+
import { layoutRelationshipDetails } from './layout'
|
|
18
29
|
import { SelectEdge } from './SelectEdge'
|
|
19
|
-
import { useLayoutedDetails } from './useLayoutedDetails'
|
|
20
30
|
|
|
21
31
|
const nodeTypes = {
|
|
22
32
|
element: ElementNode,
|
|
@@ -59,60 +69,76 @@ export function RelationshipDetails({ actorRef }: RelationshipDetailsProps) {
|
|
|
59
69
|
<RelationshipDetailsInner />
|
|
60
70
|
</AnimatePresence>
|
|
61
71
|
</LayoutGroup>
|
|
72
|
+
<SyncRelationshipDetailsXYFlow />
|
|
62
73
|
</ReactFlowProvider>
|
|
63
74
|
</RelationshipDetailsActorContext.Provider>
|
|
64
75
|
)
|
|
65
76
|
}
|
|
66
77
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
initialized: state.context.initialized,
|
|
71
|
-
nodes: state.context.xynodes,
|
|
72
|
-
edges: state.context.xyedges,
|
|
78
|
+
const selectSubject = (state: RelationshipDetailsSnapshot) => ({
|
|
79
|
+
...state.context.subject,
|
|
80
|
+
viewId: state.context.viewId,
|
|
73
81
|
})
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
83
|
+
function SyncRelationshipDetailsXYFlow() {
|
|
84
|
+
const actor = useRelationshipDetailsActor()
|
|
85
|
+
const subject = useSelector(actor, selectSubject, deepEqual)
|
|
86
|
+
const likec4model = useLikeC4Model(true)
|
|
87
|
+
const view = likec4model.findView(subject.viewId) ?? null
|
|
88
|
+
const data = useMemo(() => {
|
|
89
|
+
let data: RelationshipDetailsViewData
|
|
90
|
+
if ('edgeId' in subject) {
|
|
91
|
+
invariant(view, `view ${subject.viewId} not found`)
|
|
92
|
+
const edge = nonNullable(view.findEdge(subject.edgeId), `edge ${subject.edgeId} not found in ${subject.viewId}`)
|
|
93
|
+
data = computeEdgeDetailsViewData([edge.id], view)
|
|
94
|
+
} else {
|
|
95
|
+
data = computeRelationshipDetailsViewData({
|
|
96
|
+
source: likec4model.element(subject.source),
|
|
97
|
+
target: likec4model.element(subject.target),
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
return layoutRelationshipDetails(data, view)
|
|
101
|
+
}, [
|
|
102
|
+
subject,
|
|
79
103
|
view,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
edges,
|
|
83
|
-
} = useRelationshipDetailsState(selector)
|
|
104
|
+
likec4model,
|
|
105
|
+
])
|
|
84
106
|
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
xynodes,
|
|
88
|
-
xyedges,
|
|
89
|
-
bounds,
|
|
90
|
-
} = useLayoutedDetails(edgeId, view)
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
browser.send({ type: 'update.xydata', xynodes, xyedges })
|
|
94
|
-
}, [xynodes, xyedges])
|
|
95
|
-
|
|
96
|
-
const [historyEdgeId, historyOps, { history, current }] = useStateHistory(edgeId)
|
|
107
|
+
const store = useStoreApi<RelationshipDetailsTypes.Node, RelationshipDetailsTypes.Edge>()
|
|
108
|
+
const instance = useReactFlow<RelationshipDetailsTypes.Node, RelationshipDetailsTypes.Edge>()
|
|
97
109
|
|
|
98
110
|
useEffect(() => {
|
|
99
|
-
if (
|
|
100
|
-
|
|
111
|
+
if (instance.viewportInitialized) {
|
|
112
|
+
actor.send({ type: 'xyflow.init', instance, store })
|
|
101
113
|
}
|
|
102
|
-
}, [
|
|
114
|
+
}, [store, instance.viewportInitialized, actor])
|
|
103
115
|
|
|
104
116
|
useEffect(() => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
}, [historyEdgeId])
|
|
117
|
+
actor.send({ type: 'update.layoutData', data })
|
|
118
|
+
}, [data, actor])
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const selector = ({ context }: RelationshipDetailsSnapshot) => ({
|
|
124
|
+
// subject: context.subject,
|
|
125
|
+
// view: state.context.view,
|
|
126
|
+
initialized: context.initialized.xydata && context.initialized.xyflow,
|
|
127
|
+
nodes: context.xynodes,
|
|
128
|
+
edges: context.xyedges,
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const RelationshipDetailsInner = memo(() => {
|
|
132
|
+
const browser = useRelationshipDetails()
|
|
133
|
+
const {
|
|
134
|
+
initialized,
|
|
135
|
+
nodes,
|
|
136
|
+
edges,
|
|
137
|
+
} = useRelationshipDetailsState(selector, deepEqual)
|
|
112
138
|
|
|
113
139
|
return (
|
|
114
140
|
<BaseXYFlow<Types.Node, Types.Edge>
|
|
115
|
-
id={
|
|
141
|
+
id={browser.rootElementId}
|
|
116
142
|
nodes={nodes}
|
|
117
143
|
edges={edges}
|
|
118
144
|
className={clsx(initialized ? 'initialized' : 'not-initialized')}
|
|
@@ -125,9 +151,6 @@ const RelationshipDetailsInner = memo(() => {
|
|
|
125
151
|
browser.send({ type: 'xyflow.applyEdgeChanges', changes })
|
|
126
152
|
})}
|
|
127
153
|
fitViewPadding={0.05}
|
|
128
|
-
onInit={useCallbackRef((instance) => {
|
|
129
|
-
browser.send({ type: 'xyflow.init', instance })
|
|
130
|
-
})}
|
|
131
154
|
onNodeClick={useCallbackRef((e, node) => {
|
|
132
155
|
e.stopPropagation()
|
|
133
156
|
browser.send({ type: 'xyflow.nodeClick', node })
|
|
@@ -137,17 +160,23 @@ const RelationshipDetailsInner = memo(() => {
|
|
|
137
160
|
browser.send({ type: 'xyflow.edgeClick', edge })
|
|
138
161
|
})}
|
|
139
162
|
onPaneClick={useCallbackRef((e) => {
|
|
140
|
-
e.stopPropagation()
|
|
141
163
|
browser.send({ type: 'xyflow.paneClick' })
|
|
142
164
|
})}
|
|
165
|
+
onDoubleClick={useCallbackRef(e => {
|
|
166
|
+
browser.send({ type: 'xyflow.paneDblClick' })
|
|
167
|
+
})}
|
|
143
168
|
onViewportResize={useCallbackRef(() => {
|
|
144
169
|
browser.send({ type: 'xyflow.resized' })
|
|
145
170
|
})}
|
|
146
171
|
onEdgeMouseEnter={useCallbackRef((_event, edge) => {
|
|
147
|
-
|
|
172
|
+
if (!edge.data.hovered) {
|
|
173
|
+
browser.send({ type: 'xyflow.edgeMouseEnter', edge })
|
|
174
|
+
}
|
|
148
175
|
})}
|
|
149
176
|
onEdgeMouseLeave={useCallbackRef((_event, edge) => {
|
|
150
|
-
|
|
177
|
+
if (edge.data.hovered) {
|
|
178
|
+
browser.send({ type: 'xyflow.edgeMouseLeave', edge })
|
|
179
|
+
}
|
|
151
180
|
})}
|
|
152
181
|
onSelectionChange={useCallbackRef((params) => {
|
|
153
182
|
browser.send({ type: 'xyflow.selectionChange', ...params })
|
|
@@ -157,14 +186,7 @@ const RelationshipDetailsInner = memo(() => {
|
|
|
157
186
|
pannable
|
|
158
187
|
zoomable
|
|
159
188
|
>
|
|
160
|
-
<TopLeftPanel
|
|
161
|
-
edge={edge}
|
|
162
|
-
view={view}
|
|
163
|
-
hasStepBack={hasStepBack}
|
|
164
|
-
hasStepForward={hasStepForward}
|
|
165
|
-
onStepBack={() => historyOps.back()}
|
|
166
|
-
onStepForward={() => historyOps.forward()}
|
|
167
|
-
/>
|
|
189
|
+
<TopLeftPanel />
|
|
168
190
|
<Panel position="top-right">
|
|
169
191
|
<ActionIcon
|
|
170
192
|
variant="default"
|
|
@@ -184,23 +206,64 @@ const RelationshipDetailsInner = memo(() => {
|
|
|
184
206
|
)
|
|
185
207
|
})
|
|
186
208
|
|
|
209
|
+
// type TopLeftPanelProps = {
|
|
210
|
+
// edge: DiagramEdge
|
|
211
|
+
// view: DiagramView
|
|
212
|
+
// hasStepBack: boolean
|
|
213
|
+
// hasStepForward: boolean
|
|
214
|
+
// onStepBack: () => void
|
|
215
|
+
// onStepForward: () => void
|
|
216
|
+
// }
|
|
217
|
+
const topLeftPanelselector = ({ context }: RelationshipDetailsSnapshot) => ({
|
|
218
|
+
subject: context.subject,
|
|
219
|
+
viewId: context.viewId,
|
|
220
|
+
})
|
|
221
|
+
const TopLeftPanel = memo(() => {
|
|
222
|
+
const { subject, viewId } = useRelationshipDetailsState(topLeftPanelselector, deepEqual)
|
|
223
|
+
const likec4model = useLikeC4Model(true)
|
|
224
|
+
const view = likec4model.findView(viewId)
|
|
225
|
+
|
|
226
|
+
if (!view || !view.isDiagram()) {
|
|
227
|
+
return null
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let edge = ('edgeId' in subject)
|
|
231
|
+
? view.findEdge(subject.edgeId)
|
|
232
|
+
: ifind(view.edges(), (e) => e.source.element?.id === subject.source && e.target.element?.id === subject.target)
|
|
233
|
+
?? ifind(view.edges(), (e) => {
|
|
234
|
+
return (e.source.element?.id === subject.source || isAncestor(e.source.element?.id ?? '--', subject.source)) &&
|
|
235
|
+
(e.target.element?.id === subject.target || isAncestor(e.target.element?.id ?? '', subject.target))
|
|
236
|
+
})
|
|
237
|
+
if (!edge) {
|
|
238
|
+
return null
|
|
239
|
+
}
|
|
240
|
+
return <TopLeftPanelInner edge={edge.$edge} view={view.$view} />
|
|
241
|
+
})
|
|
242
|
+
|
|
187
243
|
type TopLeftPanelProps = {
|
|
188
244
|
edge: DiagramEdge
|
|
189
245
|
view: DiagramView
|
|
190
|
-
hasStepBack: boolean
|
|
191
|
-
hasStepForward: boolean
|
|
192
|
-
onStepBack: () => void
|
|
193
|
-
onStepForward: () => void
|
|
194
246
|
}
|
|
195
|
-
const
|
|
196
|
-
edge,
|
|
197
|
-
view,
|
|
198
|
-
hasStepBack,
|
|
199
|
-
hasStepForward,
|
|
200
|
-
onStepBack,
|
|
201
|
-
onStepForward,
|
|
202
|
-
}: TopLeftPanelProps) => {
|
|
247
|
+
const TopLeftPanelInner = ({ edge, view }: TopLeftPanelProps) => {
|
|
203
248
|
const browser = useRelationshipDetails()
|
|
249
|
+
const edgeId = edge.id
|
|
250
|
+
const [historyEdgeId, historyOps, { history, current }] = useStateHistory(edge.id)
|
|
251
|
+
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
if (historyEdgeId !== edgeId) {
|
|
254
|
+
historyOps.set(edgeId)
|
|
255
|
+
}
|
|
256
|
+
}, [edgeId])
|
|
257
|
+
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
if (historyEdgeId !== edgeId) {
|
|
260
|
+
browser.navigateTo(historyEdgeId)
|
|
261
|
+
}
|
|
262
|
+
}, [historyEdgeId])
|
|
263
|
+
|
|
264
|
+
const hasStepBack = current > 0
|
|
265
|
+
const hasStepForward = current + 1 < history.length
|
|
266
|
+
|
|
204
267
|
return (
|
|
205
268
|
<Panel position="top-left">
|
|
206
269
|
<Group gap={4} wrap={'nowrap'}>
|
|
@@ -220,7 +283,7 @@ const TopLeftPanel = ({
|
|
|
220
283
|
color="gray"
|
|
221
284
|
onClick={e => {
|
|
222
285
|
e.stopPropagation()
|
|
223
|
-
|
|
286
|
+
historyOps.back()
|
|
224
287
|
}}>
|
|
225
288
|
<IconChevronLeft />
|
|
226
289
|
</ActionIcon>
|
|
@@ -241,7 +304,7 @@ const TopLeftPanel = ({
|
|
|
241
304
|
color="gray"
|
|
242
305
|
onClick={e => {
|
|
243
306
|
e.stopPropagation()
|
|
244
|
-
|
|
307
|
+
historyOps.forward()
|
|
245
308
|
}}>
|
|
246
309
|
<IconChevronRight />
|
|
247
310
|
</ActionIcon>
|
|
@@ -24,7 +24,7 @@ export const SelectEdge = ({
|
|
|
24
24
|
view: DiagramView
|
|
25
25
|
// onSelect: (id: Fqn) => void
|
|
26
26
|
}) => {
|
|
27
|
-
const
|
|
27
|
+
const browser = useRelationshipDetails()
|
|
28
28
|
const viewport = useRef<HTMLDivElement>(null)
|
|
29
29
|
const portalProps = useMantinePortalProps()
|
|
30
30
|
// const data = useLikeC4ElementsTree(scope === 'view' ? viewId : undefined)
|
|
@@ -41,20 +41,27 @@ export const SelectEdge = ({
|
|
|
41
41
|
|
|
42
42
|
const theme = useComputedColorScheme()
|
|
43
43
|
|
|
44
|
-
const edgeSource = view.nodes.find(n => n.id === edge.source)
|
|
45
|
-
const edgeTarget = view.nodes.find(n => n.id === edge.target)
|
|
44
|
+
const edgeSource = view.nodes.find(n => n.id === edge.source)
|
|
45
|
+
const edgeTarget = view.nodes.find(n => n.id === edge.target)
|
|
46
46
|
|
|
47
|
-
const edges = view.edges.
|
|
48
|
-
const source = view.nodes.find(n => n.id === edge.source)
|
|
49
|
-
const target = view.nodes.find(n => n.id === edge.target)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const edges = view.edges.flatMap(edge => {
|
|
48
|
+
const source = view.nodes.find(n => n.id === edge.source)
|
|
49
|
+
const target = view.nodes.find(n => n.id === edge.target)
|
|
50
|
+
if (source && target) {
|
|
51
|
+
return {
|
|
52
|
+
id: edge.id,
|
|
53
|
+
source,
|
|
54
|
+
target,
|
|
55
|
+
label: edge.label,
|
|
56
|
+
}
|
|
55
57
|
}
|
|
58
|
+
return []
|
|
56
59
|
})
|
|
57
60
|
|
|
61
|
+
if (!edgeSource || !edgeTarget || edges.length === 0) {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
|
|
58
65
|
return (
|
|
59
66
|
<Popover
|
|
60
67
|
position="bottom-start"
|
|
@@ -113,7 +120,7 @@ export const SelectEdge = ({
|
|
|
113
120
|
data-selected={e.id === edge.id}
|
|
114
121
|
onClick={event => {
|
|
115
122
|
event.stopPropagation()
|
|
116
|
-
|
|
123
|
+
browser.navigateTo(e.id)
|
|
117
124
|
}}>
|
|
118
125
|
<Box
|
|
119
126
|
className={css.edgeSource}
|
|
@@ -2,6 +2,7 @@ import type { Color, DiagramNode, Fqn, IconUrl, RelationId, RelationshipLineType
|
|
|
2
2
|
import type { Base, NonOptional, ReactFlowEdge, ReactFlowNode } from '../../base/types'
|
|
3
3
|
|
|
4
4
|
export namespace RelationshipDetailsTypes {
|
|
5
|
+
export type Column = 'sources' | 'targets'
|
|
5
6
|
/**
|
|
6
7
|
* The node's incoming and outgoing ports
|
|
7
8
|
*/
|
|
@@ -26,6 +27,7 @@ export namespace RelationshipDetailsTypes {
|
|
|
26
27
|
>
|
|
27
28
|
>
|
|
28
29
|
& {
|
|
30
|
+
column: Column
|
|
29
31
|
fqn: Fqn
|
|
30
32
|
icon: IconUrl
|
|
31
33
|
ports: Ports
|
|
@@ -38,11 +40,11 @@ export namespace RelationshipDetailsTypes {
|
|
|
38
40
|
DiagramNode,
|
|
39
41
|
| 'title'
|
|
40
42
|
| 'color'
|
|
41
|
-
| 'shape'
|
|
42
43
|
| 'style'
|
|
43
44
|
>
|
|
44
45
|
>
|
|
45
46
|
& {
|
|
47
|
+
column: Column
|
|
46
48
|
fqn: Fqn
|
|
47
49
|
depth: number
|
|
48
50
|
icon?: IconUrl
|