@likec4/diagram 1.39.0 → 1.39.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/{chunk-Bg7UjtMS.js → chunk-CaxOLfbm.js} +58 -58
- package/bundle/custom.js +22 -22
- package/bundle/index.js +162 -120
- package/dist/LikeC4Diagram.js +4 -2
- package/dist/LikeC4Styles.d.ts +3 -1
- package/dist/LikeC4Styles.js +52 -20
- package/dist/base/primitives/edge/EdgeLabel.js +1 -2
- package/dist/bundle/LikeC4View.js +6 -3
- package/dist/context/RootContainer.d.ts +2 -1
- package/dist/context/RootContainer.js +1 -2
- package/dist/globals.css.js +1 -1
- package/dist/likec4diagram/relationship-popover/RelationshipPopover.js +75 -68
- package/dist/likec4diagram/relationship-popover/styles.css.js +8 -5
- package/dist/styles-min.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css2.js +1 -1
- package/package.json +4 -4
- package/panda.buildinfo.json +16 -16
- package/src/LikeC4Diagram.tsx +4 -2
- package/src/LikeC4Styles.tsx +50 -22
- package/src/base/primitives/edge/EdgeLabel.tsx +1 -2
- package/src/bundle/LikeC4View.tsx +7 -3
- package/src/context/RootContainer.tsx +2 -2
- package/src/globals.css +2 -2
- package/src/hooks/useReducedGraphics.ts +0 -7
- package/src/likec4diagram/relationship-popover/RelationshipPopover.tsx +49 -41
- package/src/likec4diagram/relationship-popover/styles.css.ts +8 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/diagram",
|
|
3
|
-
"version": "1.39.
|
|
3
|
+
"version": "1.39.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"remeda": "^2.23.1",
|
|
89
89
|
"type-fest": "^4.41.0",
|
|
90
90
|
"xstate": "^5.20.2",
|
|
91
|
-
"@likec4/core": "1.39.
|
|
92
|
-
"@likec4/styles": "1.39.
|
|
91
|
+
"@likec4/core": "1.39.2",
|
|
92
|
+
"@likec4/styles": "1.39.2"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"@pandacss/dev": "^1.1.0",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"vite-plugin-dts": "^4.5.4",
|
|
120
120
|
"vitest": "3.2.4",
|
|
121
121
|
"wireit": "0.14.12",
|
|
122
|
-
"@likec4/tsconfig": "1.39.
|
|
122
|
+
"@likec4/tsconfig": "1.39.2"
|
|
123
123
|
},
|
|
124
124
|
"scripts": {
|
|
125
125
|
"typecheck": "tsc --build --verbose",
|
package/panda.buildinfo.json
CHANGED
|
@@ -195,39 +195,42 @@
|
|
|
195
195
|
"borderBlockEndWidth]___[value:var(--thickness)",
|
|
196
196
|
"width]___[value:max-content",
|
|
197
197
|
"cursor]___[value:default",
|
|
198
|
-
"gap]___[value:3
|
|
198
|
+
"gap]___[value:3",
|
|
199
199
|
"padding]___[value:4",
|
|
200
|
-
"paddingTop]___[value:2
|
|
200
|
+
"paddingTop]___[value:2",
|
|
201
|
+
"marginTop]___[value:2",
|
|
202
|
+
"marginTop]___[value:0",
|
|
201
203
|
"--bleed-x]___[value:token(spacing.2, 2)",
|
|
202
204
|
"--bleed-y]___[value:token(spacing.2, 2)",
|
|
203
205
|
"marginInline]___[value:calc(var(--bleed-x, 0) * -1)",
|
|
204
206
|
"marginBlock]___[value:calc(var(--bleed-y, 0) * -1)",
|
|
205
|
-
"paddingBlock]___[value:2",
|
|
207
|
+
"paddingBlock]___[value:2.5",
|
|
206
208
|
"paddingInline]___[value:2",
|
|
207
209
|
"gap]___[value:1",
|
|
208
210
|
"backgroundColor]___[value:mantine.colors.dark[5]/70]___[cond:_hover<___>_dark",
|
|
209
211
|
"gap]___[value:0.5",
|
|
210
212
|
"gap]___[value:2",
|
|
211
213
|
"flexWrap]___[value:wrap",
|
|
214
|
+
"offset]___[value:2",
|
|
215
|
+
"position]___[value:top-start",
|
|
212
216
|
"opacity]___[value:0.65",
|
|
213
217
|
"paddingLeft]___[value:2.5",
|
|
214
218
|
"paddingBlock]___[value:1.5",
|
|
215
219
|
"borderLeft]___[value:2px dotted",
|
|
216
220
|
"borderLeftColor]___[value:mantine.colors.gray[3]",
|
|
217
221
|
"borderLeftColor]___[value:mantine.colors.dark[4]]___[cond:_dark",
|
|
218
|
-
"display]___[value:inline-block",
|
|
219
|
-
"fontSize]___[value:xxs",
|
|
220
|
-
"lineHeight]___[value:[1.11]",
|
|
221
222
|
"display]___[value:block",
|
|
223
|
+
"fontSize]___[value:xxs",
|
|
224
|
+
"lineHeight]___[value:sm",
|
|
222
225
|
"whiteSpace]___[value:nowrap",
|
|
223
|
-
"
|
|
226
|
+
"paddingInline]___[value:1",
|
|
227
|
+
"paddingBlock]___[value:0.5",
|
|
224
228
|
"borderRadius]___[value:[2px]",
|
|
225
|
-
"background]___[value:var(--likec4-palette-fill)/
|
|
226
|
-
"
|
|
227
|
-
"color]___[value:
|
|
229
|
+
"background]___[value:var(--likec4-palette-fill)/90]___[cond:_light",
|
|
230
|
+
"background]___[value:var(--likec4-palette-fill)/60]___[cond:_dark",
|
|
231
|
+
"color]___[value:var(--likec4-palette-hiContrast)]___[cond:_light",
|
|
228
232
|
"color]___[value:var(--likec4-palette-loContrast)]___[cond:_dark",
|
|
229
233
|
"whiteSpaceCollapse]___[value:preserve-breaks",
|
|
230
|
-
"lineHeight]___[value:sm",
|
|
231
234
|
"color]___[value:likec4.panel.action-icon.text",
|
|
232
235
|
"color]___[value:likec4.panel.action-icon.text.hover]___[cond:_hover",
|
|
233
236
|
"backgroundColor]___[value:likec4.panel.action-icon.bg",
|
|
@@ -255,7 +258,6 @@
|
|
|
255
258
|
"maxWidth]___[value:700]___[cond:@/lg",
|
|
256
259
|
"marginBlock]___[value:md",
|
|
257
260
|
"overflow]___[value:visible",
|
|
258
|
-
"paddingInline]___[value:1",
|
|
259
261
|
"color]___[value:mantine.colors.gray[8]]___[cond:_light",
|
|
260
262
|
"opacity]___[value:0.5",
|
|
261
263
|
"marginInlineEnd]___[value:0.5",
|
|
@@ -279,7 +281,6 @@
|
|
|
279
281
|
"padding]___[value:xxs",
|
|
280
282
|
"color]___[value:orange",
|
|
281
283
|
"background]___[value:mantine.colors.orange.light",
|
|
282
|
-
"marginTop]___[value:2",
|
|
283
284
|
"marginTop]___[value:xs",
|
|
284
285
|
"position]___[value:top",
|
|
285
286
|
"width]___[value:70%]___[cond:& > svg",
|
|
@@ -437,7 +438,6 @@
|
|
|
437
438
|
"fontFamily]___[value:[var(--mantine-font-family-monospace)]",
|
|
438
439
|
"overscrollBehavior]___[value:none",
|
|
439
440
|
"marginBottom]___[value:sm]___[cond:&[data-level='1']",
|
|
440
|
-
"marginTop]___[value:0",
|
|
441
441
|
"marginBottom]___[value:0",
|
|
442
442
|
"transition]___[value:fast]___[cond:& > *",
|
|
443
443
|
"transitionTimingFunction]___[value:out]___[cond:_hover<___>& > :not([data-no-transform])",
|
|
@@ -454,6 +454,7 @@
|
|
|
454
454
|
"stroke]___[value:1.2",
|
|
455
455
|
"offset]___[value:0",
|
|
456
456
|
"paddingBlock]___[value:4",
|
|
457
|
+
"display]___[value:inline-block",
|
|
457
458
|
"padding]___[value:[3px 6px]",
|
|
458
459
|
"background]___[value:var(--likec4-palette-fill)/75",
|
|
459
460
|
"lineHeight]___[value:1.2",
|
|
@@ -772,6 +773,7 @@
|
|
|
772
773
|
"padding]___[value:sm",
|
|
773
774
|
"marginBottom]___[value:xs",
|
|
774
775
|
"height]___[value:sm",
|
|
776
|
+
"paddingBlock]___[value:2",
|
|
775
777
|
"opacity]___[value:0.7",
|
|
776
778
|
"flex]___[value:0 0 auto",
|
|
777
779
|
"maxHeight]___[value:60",
|
|
@@ -830,12 +832,10 @@
|
|
|
830
832
|
"strokeWidth]___[value:5",
|
|
831
833
|
"border]___[value:3px dashed",
|
|
832
834
|
"position]___[value:right-end",
|
|
833
|
-
"offset]___[value:2",
|
|
834
835
|
"paddingInline]___[value:3",
|
|
835
836
|
"height]___[value:xs",
|
|
836
837
|
"justifyContent]___[value:flex-start",
|
|
837
838
|
"position]___[value:left-start",
|
|
838
|
-
"position]___[value:top-start",
|
|
839
839
|
"paddingInline]___[value:5",
|
|
840
840
|
"paddingBottom]___[value:8",
|
|
841
841
|
"paddingTop]___[value:4",
|
package/src/LikeC4Diagram.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Any } from '@likec4/core/types'
|
|
2
|
+
import { useId } from '@mantine/hooks'
|
|
2
3
|
import { ReactFlowProvider as XYFlowProvider } from '@xyflow/react'
|
|
3
4
|
import { type PropsWithChildren, useRef } from 'react'
|
|
4
5
|
import {
|
|
@@ -66,6 +67,7 @@ export function LikeC4Diagram<A extends Any = Any>({
|
|
|
66
67
|
renderNodes,
|
|
67
68
|
children,
|
|
68
69
|
}: LikeC4DiagramProps<A>) {
|
|
70
|
+
const id = useId().replace('mantine-', 'likec4-')
|
|
69
71
|
const initialRef = useRef<{
|
|
70
72
|
defaultNodes: Types.Node[]
|
|
71
73
|
defaultEdges: Types.Edge[]
|
|
@@ -129,8 +131,8 @@ export function LikeC4Diagram<A extends Any = Any>({
|
|
|
129
131
|
onBurgerMenuClick,
|
|
130
132
|
}}>
|
|
131
133
|
<ReduceGraphicsContext reduceGraphics={isReducedGraphicsMode}>
|
|
132
|
-
<LikeC4Styles />
|
|
133
|
-
<RootContainer className={className} reduceGraphics={isReducedGraphicsMode}>
|
|
134
|
+
<LikeC4Styles id={id} />
|
|
135
|
+
<RootContainer id={id} className={className} reduceGraphics={isReducedGraphicsMode}>
|
|
134
136
|
<XYFlowProvider
|
|
135
137
|
fitView={fitView}
|
|
136
138
|
{...initialRef.current}
|
package/src/LikeC4Styles.tsx
CHANGED
|
@@ -17,7 +17,7 @@ const whenDark = scheme('dark')
|
|
|
17
17
|
const whenLight = scheme('light')
|
|
18
18
|
|
|
19
19
|
const MAX_DEPTH = 5
|
|
20
|
-
const generateCompoundColors = (name: string, colors: ThemeColorValues, depth: number) => {
|
|
20
|
+
const generateCompoundColors = (rootSelector: string, name: string, colors: ThemeColorValues, depth: number) => {
|
|
21
21
|
const compoundDarkColor = (color: string) =>
|
|
22
22
|
toHex(
|
|
23
23
|
scale(color, {
|
|
@@ -32,7 +32,7 @@ const generateCompoundColors = (name: string, colors: ThemeColorValues, depth: n
|
|
|
32
32
|
s: -3 - 6 * depth,
|
|
33
33
|
}),
|
|
34
34
|
)
|
|
35
|
-
const selector = `:where([data-likec4-color="${name}"][data-compound-depth="${depth}"])`
|
|
35
|
+
const selector = `:where(${rootSelector} [data-likec4-color="${name}"][data-compound-depth="${depth}"])`
|
|
36
36
|
|
|
37
37
|
return `
|
|
38
38
|
${selector} {
|
|
@@ -46,8 +46,8 @@ ${whenDark} ${selector} {
|
|
|
46
46
|
`.trim()
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
function toStyle(name: string, colors: ThemeColorValues): string {
|
|
50
|
-
const selector = `:where([data-likec4-color=${name}])`
|
|
49
|
+
function toStyle(rootSelector: string, name: string, colors: ThemeColorValues): string {
|
|
50
|
+
const selector = `:where(${rootSelector} [data-likec4-color=${name}])`
|
|
51
51
|
return [
|
|
52
52
|
`
|
|
53
53
|
${selector} {
|
|
@@ -67,47 +67,75 @@ ${whenDark} ${selector} {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
`.trim(),
|
|
70
|
-
...range(1, MAX_DEPTH + 1).map((depth) => generateCompoundColors(name, colors, depth)),
|
|
70
|
+
...range(1, MAX_DEPTH + 1).map((depth) => generateCompoundColors(rootSelector, name, colors, depth)),
|
|
71
71
|
].join('\n')
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
toStyle(color, {
|
|
76
|
-
elements: defaultTheme.elements[color],
|
|
77
|
-
relationships: defaultTheme.relationships[color],
|
|
78
|
-
})
|
|
79
|
-
).join('\n')
|
|
80
|
-
|
|
81
|
-
function generateCustomColorStyles(customColors: CustomColorDefinitions) {
|
|
74
|
+
function generateCustomColorStyles(customColors: CustomColorDefinitions, rootSelector: string) {
|
|
82
75
|
return pipe(
|
|
83
76
|
entries(customColors),
|
|
84
|
-
map(([name, color]) => toStyle(name, color)),
|
|
77
|
+
map(([name, color]) => toStyle(rootSelector, name, color)),
|
|
78
|
+
join('\n'),
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function generateBuiltInColorStyles(rootSelector: string) {
|
|
83
|
+
return pipe(
|
|
84
|
+
ThemeColors,
|
|
85
|
+
map((color) =>
|
|
86
|
+
toStyle(rootSelector, color, {
|
|
87
|
+
elements: defaultTheme.elements[color],
|
|
88
|
+
relationships: defaultTheme.relationships[color],
|
|
89
|
+
})
|
|
90
|
+
),
|
|
85
91
|
join('\n'),
|
|
86
92
|
)
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
export function LikeC4Styles() {
|
|
95
|
+
export function LikeC4Styles({ id }: { id: string }) {
|
|
96
|
+
const rootSelector = `#${id}`
|
|
90
97
|
const nonce = useMantineStyleNonce()?.()
|
|
91
98
|
|
|
92
99
|
const { customColors } = useLikeC4Specification()
|
|
93
|
-
const customColorsStyles = customColors ? generateCustomColorStyles(customColors) : ''
|
|
100
|
+
const customColorsStyles = customColors ? generateCustomColorStyles(customColors, rootSelector) : ''
|
|
94
101
|
|
|
95
|
-
|
|
102
|
+
const builtInColors = generateBuiltInColorStyles(rootSelector)
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<MemoizedStyles
|
|
106
|
+
id={id}
|
|
107
|
+
nonce={nonce}
|
|
108
|
+
customColorsStyles={customColorsStyles}
|
|
109
|
+
builtInColors={builtInColors} />
|
|
110
|
+
)
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
/**
|
|
99
114
|
* @internal This gives a performance boost during development
|
|
100
115
|
*/
|
|
101
|
-
const MemoizedStyles = memo<{
|
|
102
|
-
|
|
116
|
+
const MemoizedStyles = memo<{
|
|
117
|
+
id: string
|
|
118
|
+
nonce: string | undefined
|
|
119
|
+
customColorsStyles: string
|
|
120
|
+
builtInColors: string
|
|
121
|
+
}>((
|
|
122
|
+
{ id, nonce, customColorsStyles, builtInColors },
|
|
103
123
|
) => (
|
|
104
124
|
<>
|
|
105
|
-
<style
|
|
106
|
-
|
|
125
|
+
<style
|
|
126
|
+
type="text/css"
|
|
127
|
+
data-likec4-global={id}
|
|
128
|
+
dangerouslySetInnerHTML={{ __html: globalsCss.replaceAll('.likec4-root', `#${id}.likec4-root`) }}
|
|
129
|
+
nonce={nonce} />
|
|
130
|
+
<style
|
|
131
|
+
type="text/css"
|
|
132
|
+
data-likec4-colors={id}
|
|
133
|
+
dangerouslySetInnerHTML={{ __html: builtInColors }}
|
|
134
|
+
nonce={nonce} />
|
|
107
135
|
{customColorsStyles && (
|
|
108
136
|
<style
|
|
109
137
|
type="text/css"
|
|
110
|
-
data-likec4-custom-colors
|
|
138
|
+
data-likec4-custom-colors={id}
|
|
111
139
|
dangerouslySetInnerHTML={{ __html: customColorsStyles }}
|
|
112
140
|
nonce={nonce} />
|
|
113
141
|
)}
|
|
@@ -56,8 +56,7 @@ export const EdgeLabel = forwardRef<HTMLDivElement, EdgeLabelProps>((
|
|
|
56
56
|
className={cx(classes.root, 'likec4-edge-label', className)}
|
|
57
57
|
data-edge-id={id}
|
|
58
58
|
animate={{
|
|
59
|
-
|
|
60
|
-
scale: isHovered && !selected ? 1.08 : 1,
|
|
59
|
+
scale: isHovered && !selected ? 1.06 : 1,
|
|
61
60
|
}}
|
|
62
61
|
{...rest}
|
|
63
62
|
>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as t from '@likec4/core/types'
|
|
2
2
|
import { cx } from '@likec4/styles/css'
|
|
3
3
|
import { ActionIcon, Box } from '@mantine/core'
|
|
4
|
-
import { shallowEqual } from '@mantine/hooks'
|
|
4
|
+
import { shallowEqual, useCallbackRef } from '@mantine/hooks'
|
|
5
5
|
import { IconX } from '@tabler/icons-react'
|
|
6
6
|
import { memo, useState } from 'react'
|
|
7
7
|
import { isBoolean } from 'remeda'
|
|
@@ -83,6 +83,10 @@ const LikeC4ViewInner = memo<LikeC4ViewInnerProps<t.aux.UnknownLayouted>>(({
|
|
|
83
83
|
|
|
84
84
|
const [browserViewId, onNavigateTo] = useState(null as t.aux.ViewId<t.aux.UnknownLayouted> | null)
|
|
85
85
|
|
|
86
|
+
const onNavigateToThisView = useCallbackRef(() => {
|
|
87
|
+
onNavigateTo(view.id)
|
|
88
|
+
})
|
|
89
|
+
|
|
86
90
|
const browserView = browserViewId ? likec4model.findView(browserViewId)?.$view : null
|
|
87
91
|
|
|
88
92
|
const notations = view.notation?.nodes ?? []
|
|
@@ -149,8 +153,8 @@ const LikeC4ViewInner = memo<LikeC4ViewInnerProps<t.aux.UnknownLayouted>>(({
|
|
|
149
153
|
enableSearch={false}
|
|
150
154
|
{...isBrowserEnabled && {
|
|
151
155
|
onNavigateTo: onNavigateTo,
|
|
152
|
-
onCanvasClick:
|
|
153
|
-
onNodeClick:
|
|
156
|
+
onCanvasClick: onNavigateToThisView,
|
|
157
|
+
onNodeClick: onNavigateToThisView,
|
|
154
158
|
}}
|
|
155
159
|
reactFlowProps={reactFlowProps}
|
|
156
160
|
renderNodes={renderNodes}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { cx } from '@likec4/styles/css'
|
|
2
2
|
import { Box } from '@likec4/styles/jsx'
|
|
3
|
-
import { useId } from '@mantine/hooks'
|
|
4
3
|
import { type PropsWithChildren, createContext, createRef, useContext, useEffect, useRef } from 'react'
|
|
5
4
|
import { usePanningAtom } from './ReduceGraphics'
|
|
6
5
|
import { TagStylesProvider } from './TagStylesContext'
|
|
@@ -8,14 +7,15 @@ import { TagStylesProvider } from './TagStylesContext'
|
|
|
8
7
|
const RootContainerContext = createContext(createRef<HTMLDivElement>())
|
|
9
8
|
|
|
10
9
|
export function RootContainer({
|
|
10
|
+
id,
|
|
11
11
|
className,
|
|
12
12
|
reduceGraphics = false,
|
|
13
13
|
children,
|
|
14
14
|
}: PropsWithChildren<{
|
|
15
|
+
id: string
|
|
15
16
|
className?: string | undefined
|
|
16
17
|
reduceGraphics?: boolean
|
|
17
18
|
}>) {
|
|
18
|
-
const id = useId()
|
|
19
19
|
const ref = useRef<HTMLDivElement>(null)
|
|
20
20
|
const $isPanning = usePanningAtom()
|
|
21
21
|
|
package/src/globals.css
CHANGED
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
|
|
60
60
|
.likec4-root:not([data-likec4-reduced-graphics])
|
|
61
61
|
:where(.react-flow__node, .react-flow__edge):has([data-likec4-dimmed]) {
|
|
62
|
-
filter: grayscale(85%)
|
|
62
|
+
filter: grayscale(85%);
|
|
63
63
|
}
|
|
64
64
|
.likec4-root:not([data-likec4-reduced-graphics]) .likec4-edge-label-container:is([data-likec4-dimmed]) {
|
|
65
|
-
filter: grayscale(85%)
|
|
65
|
+
filter: grayscale(85%);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
.likec4-root:not([data-likec4-reduced-graphics])
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
// import { useStore } from '@nanostores/react'
|
|
2
|
-
// import { usePanningAtom } from '../context/ReduceGraphics'
|
|
3
1
|
export { useIsPanning, useIsReducedGraphics } from '../context/ReduceGraphics'
|
|
4
|
-
|
|
5
|
-
// export function useIsPanning() {
|
|
6
|
-
// const $isPanning = usePanningAtom()
|
|
7
|
-
// return useStore($isPanning)
|
|
8
|
-
// }
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
Divider,
|
|
12
12
|
Portal,
|
|
13
13
|
ScrollAreaAutosize,
|
|
14
|
-
Space,
|
|
15
14
|
Text,
|
|
16
15
|
Tooltip as MantineTooltip,
|
|
17
16
|
TooltipGroup,
|
|
@@ -37,8 +36,6 @@ import { useEnabledFeatures } from '../../context/DiagramFeatures'
|
|
|
37
36
|
import { MarkdownBlock } from '../../custom'
|
|
38
37
|
import { useDiagram, useDiagramContext, useOnDiagramEvent } from '../../hooks/useDiagram'
|
|
39
38
|
import { useMantinePortalProps } from '../../hooks/useMantinePortalProps'
|
|
40
|
-
import { useUpdateEffect } from '../../hooks/useUpdateEffect'
|
|
41
|
-
import { type XYStoreState, useXYStore } from '../../hooks/useXYFlow'
|
|
42
39
|
import { useLikeC4Model } from '../../likec4model'
|
|
43
40
|
import type { DiagramContext } from '../../state/types'
|
|
44
41
|
import { findDiagramEdge, findDiagramNode } from '../../state/utils'
|
|
@@ -70,9 +67,9 @@ export const RelationshipPopover = memo(() => {
|
|
|
70
67
|
|
|
71
68
|
const openedEdgeId = useSelector(actorRef, s => s.hasTag('opened') ? s.context.edgeId : null)
|
|
72
69
|
|
|
73
|
-
|
|
70
|
+
useOnDiagramEvent('viewChange', () => {
|
|
74
71
|
actorRef.send({ type: 'close' })
|
|
75
|
-
}
|
|
72
|
+
})
|
|
76
73
|
|
|
77
74
|
useOnDiagramEvent('edgeMouseEnter', ({ edge }) => {
|
|
78
75
|
actorRef.send({ type: 'xyedge.mouseEnter', edgeId: edge.data.id })
|
|
@@ -90,7 +87,7 @@ export const RelationshipPopover = memo(() => {
|
|
|
90
87
|
actorRef.send({ type: 'close' })
|
|
91
88
|
})
|
|
92
89
|
|
|
93
|
-
|
|
90
|
+
useEffect(() => {
|
|
94
91
|
if (selected) {
|
|
95
92
|
actorRef.send({ type: 'xyedge.select', edgeId: selected })
|
|
96
93
|
} else {
|
|
@@ -154,9 +151,6 @@ const getEdgeLabelElement = (edgeId: string, container: HTMLDivElement | undefin
|
|
|
154
151
|
return container?.querySelector<HTMLDivElement>(`.likec4-edge-label[data-edge-id="${edgeId}"]`) ?? null
|
|
155
152
|
}
|
|
156
153
|
|
|
157
|
-
const selectTransform = (s: XYStoreState) =>
|
|
158
|
-
roundDpr(s.transform[0]) + ' ' + roundDpr(s.transform[1]) + ' ' + s.transform[2].toFixed(3)
|
|
159
|
-
|
|
160
154
|
type RelationshipPopoverInternalProps = {
|
|
161
155
|
viewId: ViewId
|
|
162
156
|
diagramEdge: DiagramEdge
|
|
@@ -165,6 +159,7 @@ type RelationshipPopoverInternalProps = {
|
|
|
165
159
|
onMouseEnter: MouseEventHandler<HTMLDivElement>
|
|
166
160
|
onMouseLeave: MouseEventHandler<HTMLDivElement>
|
|
167
161
|
}
|
|
162
|
+
const POPOVER_PADDING = 8
|
|
168
163
|
const RelationshipPopoverInternal = ({
|
|
169
164
|
viewId,
|
|
170
165
|
diagramEdge,
|
|
@@ -180,11 +175,10 @@ const RelationshipPopoverInternal = ({
|
|
|
180
175
|
const { portalProps } = useMantinePortalProps()
|
|
181
176
|
|
|
182
177
|
const [referenceEl, setReferenceEl] = useState<HTMLDivElement | null>(null)
|
|
183
|
-
const viewport = useXYStore(selectTransform)
|
|
184
178
|
|
|
185
179
|
useEffect(() => {
|
|
186
180
|
setReferenceEl(getEdgeLabelElement(diagramEdge.id, portalProps?.target))
|
|
187
|
-
}, [diagramEdge
|
|
181
|
+
}, [diagramEdge])
|
|
188
182
|
|
|
189
183
|
useEffect(() => {
|
|
190
184
|
const reference = referenceEl
|
|
@@ -196,11 +190,11 @@ const RelationshipPopoverInternal = ({
|
|
|
196
190
|
|
|
197
191
|
const update = () => {
|
|
198
192
|
computePosition(reference, popper, {
|
|
199
|
-
placement: 'bottom',
|
|
193
|
+
placement: 'bottom-start',
|
|
200
194
|
middleware: [
|
|
201
195
|
offset(2),
|
|
202
196
|
autoPlacement({
|
|
203
|
-
padding:
|
|
197
|
+
padding: POPOVER_PADDING,
|
|
204
198
|
allowedPlacements: [
|
|
205
199
|
'bottom-start',
|
|
206
200
|
'bottom-end',
|
|
@@ -213,19 +207,19 @@ const RelationshipPopoverInternal = ({
|
|
|
213
207
|
],
|
|
214
208
|
}),
|
|
215
209
|
size({
|
|
216
|
-
padding:
|
|
210
|
+
padding: POPOVER_PADDING,
|
|
217
211
|
apply({ availableHeight, availableWidth, elements }) {
|
|
218
212
|
if (wasCanceled) {
|
|
219
213
|
return
|
|
220
214
|
}
|
|
221
215
|
Object.assign(elements.floating.style, {
|
|
222
|
-
maxWidth: `${clamp(roundDpr(availableWidth), { min:
|
|
216
|
+
maxWidth: `${clamp(roundDpr(availableWidth), { min: 200, max: 400 })}px`,
|
|
223
217
|
maxHeight: `${clamp(roundDpr(availableHeight), { min: 0, max: 500 })}px`,
|
|
224
218
|
})
|
|
225
219
|
},
|
|
226
220
|
}),
|
|
227
221
|
hide({
|
|
228
|
-
padding:
|
|
222
|
+
padding: POPOVER_PADDING * 2,
|
|
229
223
|
}),
|
|
230
224
|
],
|
|
231
225
|
}).then(({ x, y, middlewareData }) => {
|
|
@@ -236,7 +230,10 @@ const RelationshipPopoverInternal = ({
|
|
|
236
230
|
popper.style.visibility = middlewareData.hide?.referenceHidden ? 'hidden' : 'visible'
|
|
237
231
|
})
|
|
238
232
|
}
|
|
239
|
-
const cleanup = autoUpdate(reference, popper, update
|
|
233
|
+
const cleanup = autoUpdate(reference, popper, update, {
|
|
234
|
+
ancestorResize: false,
|
|
235
|
+
animationFrame: true,
|
|
236
|
+
})
|
|
240
237
|
return () => {
|
|
241
238
|
wasCanceled = true
|
|
242
239
|
cleanup()
|
|
@@ -308,7 +305,7 @@ const RelationshipPopoverInternal = ({
|
|
|
308
305
|
styles={{
|
|
309
306
|
viewport: {
|
|
310
307
|
overscrollBehavior: 'contain',
|
|
311
|
-
minWidth:
|
|
308
|
+
minWidth: 180,
|
|
312
309
|
},
|
|
313
310
|
}}
|
|
314
311
|
className={cx(
|
|
@@ -327,9 +324,9 @@ const RelationshipPopoverInternal = ({
|
|
|
327
324
|
>
|
|
328
325
|
<VStack
|
|
329
326
|
css={{
|
|
330
|
-
gap: '3
|
|
327
|
+
gap: '3',
|
|
331
328
|
padding: '4',
|
|
332
|
-
paddingTop: '2
|
|
329
|
+
paddingTop: '2',
|
|
333
330
|
}}
|
|
334
331
|
>
|
|
335
332
|
<Button
|
|
@@ -350,14 +347,19 @@ const RelationshipPopoverInternal = ({
|
|
|
350
347
|
</Button>
|
|
351
348
|
{direct.length > 0 && (
|
|
352
349
|
<>
|
|
353
|
-
<
|
|
350
|
+
<Label>DIRECT RELATIONSHIPS</Label>
|
|
354
351
|
{direct.map(renderRelationship)}
|
|
355
352
|
</>
|
|
356
353
|
)}
|
|
357
354
|
{nested.length > 0 && (
|
|
358
355
|
<>
|
|
359
|
-
|
|
360
|
-
|
|
356
|
+
<Label
|
|
357
|
+
css={{
|
|
358
|
+
mt: direct.length > 0 ? '2' : '0',
|
|
359
|
+
}}
|
|
360
|
+
>
|
|
361
|
+
RESOLVED FROM NESTED
|
|
362
|
+
</Label>
|
|
361
363
|
{nested.map(renderRelationship)}
|
|
362
364
|
</>
|
|
363
365
|
)}
|
|
@@ -388,8 +390,8 @@ const Relationship = forwardRef<
|
|
|
388
390
|
onNavigateTo,
|
|
389
391
|
onOpenSource,
|
|
390
392
|
}, ref) => {
|
|
391
|
-
const sourceId =
|
|
392
|
-
const targetId =
|
|
393
|
+
const sourceId = getEndpointId(r, 'source', sourceNode)
|
|
394
|
+
const targetId = getEndpointId(r, 'target', targetNode)
|
|
393
395
|
const navigateTo = onNavigateTo && r.navigateTo?.id !== viewId ? r.navigateTo?.id : undefined
|
|
394
396
|
const links = r.links
|
|
395
397
|
|
|
@@ -399,8 +401,8 @@ const Relationship = forwardRef<
|
|
|
399
401
|
className={bleed({
|
|
400
402
|
block: '2',
|
|
401
403
|
inline: '2',
|
|
402
|
-
|
|
403
|
-
|
|
404
|
+
paddingY: '2.5',
|
|
405
|
+
paddingX: '2',
|
|
404
406
|
gap: '1',
|
|
405
407
|
rounded: 'sm',
|
|
406
408
|
backgroundColor: {
|
|
@@ -412,14 +414,18 @@ const Relationship = forwardRef<
|
|
|
412
414
|
})}
|
|
413
415
|
>
|
|
414
416
|
<HStack gap={'0.5'}>
|
|
415
|
-
<
|
|
416
|
-
{sourceId}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
417
|
+
<TooltipGroup openDelay={200}>
|
|
418
|
+
<Tooltip label={sourceId.full} offset={2} position="top-start">
|
|
419
|
+
<Text component="div" data-likec4-color={sourceNode.color} className={styles.endpoint}>
|
|
420
|
+
{sourceId.short}
|
|
421
|
+
</Text>
|
|
422
|
+
</Tooltip>
|
|
423
|
+
<IconArrowRight stroke={2.5} size={'11px'} opacity={0.65} />
|
|
424
|
+
<Tooltip label={targetId.full} offset={2} position="top-start">
|
|
425
|
+
<Text component="div" data-likec4-color={targetNode.color} className={styles.endpoint}>
|
|
426
|
+
{targetId.short}
|
|
427
|
+
</Text>
|
|
428
|
+
</Tooltip>
|
|
423
429
|
{navigateTo && (
|
|
424
430
|
<Tooltip label={'Open dynamic view'}>
|
|
425
431
|
<ActionIcon
|
|
@@ -500,13 +506,13 @@ const Relationship = forwardRef<
|
|
|
500
506
|
)
|
|
501
507
|
})
|
|
502
508
|
|
|
503
|
-
const Label = styled('
|
|
509
|
+
const Label = styled('div', {
|
|
504
510
|
base: {
|
|
505
|
-
display: '
|
|
511
|
+
display: 'block',
|
|
506
512
|
fontSize: 'xxs',
|
|
507
513
|
fontWeight: 500,
|
|
508
514
|
userSelect: 'none',
|
|
509
|
-
lineHeight: '
|
|
515
|
+
lineHeight: 'sm',
|
|
510
516
|
color: 'mantine.colors.dimmed',
|
|
511
517
|
},
|
|
512
518
|
})
|
|
@@ -520,9 +526,9 @@ const Tooltip = MantineTooltip.withProps({
|
|
|
520
526
|
withinPortal: false,
|
|
521
527
|
})
|
|
522
528
|
|
|
523
|
-
function
|
|
529
|
+
function getEndpointId(
|
|
524
530
|
r: LikeC4Model.AnyRelation,
|
|
525
|
-
|
|
531
|
+
endpoint: 'source' | 'target',
|
|
526
532
|
diagramNode: DiagramNode,
|
|
527
533
|
) {
|
|
528
534
|
const diagramNodeId = r.isDeploymentRelation()
|
|
@@ -531,5 +537,7 @@ function getShortId(
|
|
|
531
537
|
// Relation defined in model. Get id of the model element
|
|
532
538
|
: diagramNode.modelRef || ''
|
|
533
539
|
|
|
534
|
-
|
|
540
|
+
const full = r[endpoint].id
|
|
541
|
+
const short = nameFromFqn(diagramNodeId) + full.slice(diagramNodeId.length)
|
|
542
|
+
return { full, short }
|
|
535
543
|
}
|
|
@@ -5,13 +5,16 @@ export const endpoint = css({
|
|
|
5
5
|
fontSize: 'xxs',
|
|
6
6
|
fontWeight: 500,
|
|
7
7
|
whiteSpace: 'nowrap',
|
|
8
|
-
|
|
8
|
+
paddingX: '1',
|
|
9
|
+
paddingY: '0.5',
|
|
9
10
|
borderRadius: '[2px]',
|
|
10
|
-
background:
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
background: {
|
|
12
|
+
_light: 'var(--likec4-palette-fill)/90',
|
|
13
|
+
_dark: 'var(--likec4-palette-fill)/60',
|
|
14
|
+
},
|
|
15
|
+
lineHeight: '1',
|
|
13
16
|
color: {
|
|
14
|
-
_light:
|
|
17
|
+
_light: 'var(--likec4-palette-hiContrast)',
|
|
15
18
|
_dark: 'var(--likec4-palette-loContrast)',
|
|
16
19
|
},
|
|
17
20
|
})
|