@likec4/diagram 1.0.0-next.2 → 1.0.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/dist/LikeC4Diagram.css.d.ts +0 -1
- package/dist/LikeC4Diagram.d.ts +1 -2
- package/dist/LikeC4Diagram.props.d.ts +24 -25
- package/dist/StaticLikeC4Diagram.d.ts +1 -2
- package/dist/globals.css.d.ts +1 -0
- package/dist/hooks/index.d.ts +2 -3
- package/dist/hooks/useSetState.d.ts +3 -0
- package/dist/hooks/useUpdateEffect.d.ts +4 -0
- package/dist/icons/Clipboard.d.ts +0 -1
- package/dist/icons/Link.d.ts +0 -1
- package/dist/icons/ZoomIn.d.ts +0 -1
- package/dist/icons/index.d.ts +0 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.mjs +9388 -0
- package/dist/mantine/EnsureMantine.d.ts +2 -4
- package/dist/mantine/theme.d.ts +3 -0
- package/dist/mantine.css.d.ts +1 -0
- package/dist/state/DiagramContext.d.ts +386 -0
- package/dist/state/WhenInitialized.d.ts +3 -0
- package/dist/state/diagramStore.d.ts +428 -0
- package/dist/state/index.d.ts +4 -2
- package/dist/state/useDiagramStore.d.ts +387 -0
- package/dist/style.css +1212 -1
- package/dist/theme.css.d.ts +16 -2
- package/dist/ui/Camera.d.ts +0 -1
- package/dist/ui/KeepAspectRatio.css.d.ts +0 -1
- package/dist/ui/KeepAspectRatio.d.ts +0 -1
- package/dist/ui/OptionsPanel.css.d.ts +0 -1
- package/dist/ui/OptionsPanel.d.ts +0 -1
- package/dist/ui/index.d.ts +0 -1
- package/dist/ui/options/NodeOptions.d.ts +0 -1
- package/dist/xyflow/FitviewOnDiagramChange.d.ts +1 -5
- package/dist/xyflow/SyncWithDiagram.d.ts +5 -0
- package/dist/xyflow/XYFlowBackground.d.ts +0 -1
- package/dist/xyflow/XYFlowEvents.d.ts +5 -15
- package/dist/xyflow/XYFlowWrapper.d.ts +4 -5
- package/dist/xyflow/const.d.ts +1 -2
- package/dist/xyflow/diagram-to-xyflow.d.ts +4 -2
- package/dist/xyflow/edges/RelationshipEdge.d.ts +7 -7
- package/dist/xyflow/edges/edges.css.d.ts +2 -1
- package/dist/xyflow/edges/utils.d.ts +3 -4
- package/dist/xyflow/hooks/index.d.ts +2 -37
- package/dist/xyflow/hooks/{use-layout-/321/201onstraints.d.ts → useLayoutConstraints.d.ts} +2 -4
- package/dist/xyflow/hooks/useXYFlow.d.ts +266 -0
- package/dist/xyflow/nodes/compound/CompoundNode.css.d.ts +0 -1
- package/dist/xyflow/nodes/compound/CompoundNode.d.ts +0 -1
- package/dist/xyflow/nodes/compound/index.d.ts +0 -1
- package/dist/xyflow/nodes/element/ElementIcon.d.ts +1 -2
- package/dist/xyflow/nodes/element/ElementLink.css.d.ts +0 -1
- package/dist/xyflow/nodes/element/ElementLink.d.ts +1 -2
- package/dist/xyflow/nodes/element/ElementNode.d.ts +1 -3
- package/dist/xyflow/nodes/element/ElementShapeSvg.d.ts +2 -3
- package/dist/xyflow/nodes/element/element.css.d.ts +0 -1
- package/dist/xyflow/nodes/element/index.d.ts +1 -2
- package/dist/xyflow/nodes/shared/NavigateToBtn.d.ts +0 -1
- package/dist/xyflow/types.d.ts +20 -8
- package/dist/xyflow/utils.d.ts +0 -1
- package/package.json +36 -34
- package/src/LikeC4Diagram.css.ts +31 -0
- package/src/LikeC4Diagram.props.ts +154 -0
- package/src/LikeC4Diagram.tsx +119 -0
- package/src/StaticLikeC4Diagram.tsx +39 -0
- package/src/globals.css.ts +128 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useSetState.ts +19 -0
- package/src/hooks/useUpdateEffect.ts +28 -0
- package/src/icons/Clipboard.tsx +24 -0
- package/src/icons/Link.tsx +23 -0
- package/src/icons/ZoomIn.tsx +25 -0
- package/src/icons/index.ts +3 -0
- package/src/index.ts +11 -0
- package/src/mantine/EnsureMantine.tsx +14 -0
- package/src/mantine/theme.ts +19 -0
- package/src/mantine.css.ts +4 -0
- package/src/reset.d.ts +2 -0
- package/src/state/DiagramContext.tsx +42 -0
- package/src/state/WhenInitialized.tsx +24 -0
- package/src/state/diagramStore.ts +358 -0
- package/src/state/index.ts +4 -0
- package/src/state/useDiagramStore.ts +39 -0
- package/src/theme.css.ts +64 -0
- package/src/ui/Camera.tsx +174 -0
- package/src/ui/KeepAspectRatio.css.ts +7 -0
- package/src/ui/KeepAspectRatio.tsx +35 -0
- package/src/ui/OptionsPanel.css.ts +10 -0
- package/src/ui/OptionsPanel.tsx +65 -0
- package/src/ui/index.ts +3 -0
- package/src/ui/options/NodeOptions.tsx +253 -0
- package/src/xyflow/FitviewOnDiagramChange.tsx +93 -0
- package/src/xyflow/SyncWithDiagram.tsx +113 -0
- package/src/xyflow/XYFlowBackground.tsx +33 -0
- package/src/xyflow/XYFlowEvents.tsx +100 -0
- package/src/xyflow/XYFlowWrapper.tsx +166 -0
- package/src/xyflow/const.ts +7 -0
- package/src/xyflow/diagram-to-xyflow.ts +197 -0
- package/src/xyflow/edges/RelationshipEdge.tsx +288 -0
- package/src/xyflow/edges/edges.css.ts +124 -0
- package/src/xyflow/edges/utils.ts +110 -0
- package/src/xyflow/hooks/index.ts +2 -0
- package/src/xyflow/hooks/useLayoutConstraints.ts +289 -0
- package/src/xyflow/hooks/useXYFlow.ts +20 -0
- package/src/xyflow/nodes/compound/CompoundNode.css.ts +191 -0
- package/src/xyflow/nodes/compound/CompoundNode.tsx +105 -0
- package/src/xyflow/nodes/compound/index.ts +1 -0
- package/src/xyflow/nodes/element/ElementIcon.tsx +44 -0
- package/src/xyflow/nodes/element/ElementLink.css.ts +67 -0
- package/src/xyflow/nodes/element/ElementLink.tsx +94 -0
- package/src/xyflow/nodes/element/ElementNode.tsx +225 -0
- package/src/xyflow/nodes/element/ElementShapeSvg.tsx +181 -0
- package/src/xyflow/nodes/element/element.css.ts +261 -0
- package/src/xyflow/nodes/element/index.ts +1 -0
- package/src/xyflow/nodes/shared/NavigateToBtn.tsx +25 -0
- package/src/xyflow/types.ts +100 -0
- package/src/xyflow/utils.ts +12 -0
- package/dist/EmbeddedLikeC4Diagram.css.d.ts +0 -6
- package/dist/EmbeddedLikeC4Diagram.d.ts +0 -18
- package/dist/bundle.d.ts +0 -3
- package/dist/hooks/use-set-state.d.ts +0 -2
- package/dist/hooks/use-update-effect.d.ts +0 -4
- package/dist/index.css.d.ts +0 -2
- package/dist/index.js +0 -13043
- package/dist/mantine/index.d.ts +0 -3
- package/dist/state/DiagramState.d.ts +0 -162
- package/dist/xyflow/UpdateOnDiagramChange.d.ts +0 -10
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { defaultTheme } from '@likec4/core'
|
|
2
|
+
import { Box, Text } from '@mantine/core'
|
|
3
|
+
import { assignInlineVars } from '@vanilla-extract/dynamic'
|
|
4
|
+
import { Handle, type NodeProps, Position } from '@xyflow/react'
|
|
5
|
+
import clsx from 'clsx'
|
|
6
|
+
import { deepEqual as eq } from 'fast-equals'
|
|
7
|
+
import { scale, toHex } from 'khroma'
|
|
8
|
+
import { memo, useMemo } from 'react'
|
|
9
|
+
import { useDiagramState } from '../../../state'
|
|
10
|
+
import { vars } from '../../../theme.css'
|
|
11
|
+
import type { CompoundXYFlowNode } from '../../types'
|
|
12
|
+
import { NavigateToBtn } from '../shared/NavigateToBtn'
|
|
13
|
+
import { cssCompound, cssContainer, cssIndicator, cssNavigateBtn, cssTitle } from './CompoundNode.css'
|
|
14
|
+
|
|
15
|
+
type CompoundNodeProps = Pick<
|
|
16
|
+
NodeProps<CompoundXYFlowNode>,
|
|
17
|
+
'id' | 'data' | 'width' | 'height' | 'selected'
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const isEqualProps = (prev: CompoundNodeProps, next: CompoundNodeProps) => (
|
|
22
|
+
prev.id === next.id
|
|
23
|
+
&& prev.selected === next.selected
|
|
24
|
+
&& prev.width === next.width
|
|
25
|
+
&& prev.height === next.height
|
|
26
|
+
&& eq(prev.data, next.data)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const compoundColor = (color: string, depth: number) =>
|
|
30
|
+
toHex(
|
|
31
|
+
scale(color, {
|
|
32
|
+
l: -35 - 5 * depth,
|
|
33
|
+
s: -15 - 5 * depth
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
export const CompoundNodeMemo = /* @__PURE__ */ memo<CompoundNodeProps>(function CompoundNode({
|
|
38
|
+
id,
|
|
39
|
+
data: {
|
|
40
|
+
element
|
|
41
|
+
}
|
|
42
|
+
}) {
|
|
43
|
+
// useTilg()
|
|
44
|
+
const { color, depth = 0, ...compound } = element
|
|
45
|
+
const colors = useMemo(() => {
|
|
46
|
+
const colors = defaultTheme.elements[color]
|
|
47
|
+
return {
|
|
48
|
+
fill: compoundColor(colors.fill, depth),
|
|
49
|
+
stroke: compoundColor(colors.stroke, depth)
|
|
50
|
+
}
|
|
51
|
+
}, [color, depth])
|
|
52
|
+
|
|
53
|
+
// const w = toDomPrecision(width ?? compound.width)
|
|
54
|
+
// const h = toDomPrecision(height ?? compound.height)
|
|
55
|
+
|
|
56
|
+
const { isHovered, hasOnNavigateTo } = useDiagramState(s => ({
|
|
57
|
+
isHovered: s.hoveredNodeId === id,
|
|
58
|
+
hasOnNavigateTo: !!s.onNavigateTo
|
|
59
|
+
}))
|
|
60
|
+
const isnavigable = !!compound.navigateTo && hasOnNavigateTo
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Box
|
|
64
|
+
className={clsx(cssContainer, 'likec4-compound-node')}
|
|
65
|
+
style={assignInlineVars({ fill: vars.element.fill, stroke: vars.element.stroke }, {
|
|
66
|
+
fill: colors.fill,
|
|
67
|
+
stroke: colors.stroke
|
|
68
|
+
})}
|
|
69
|
+
mod={{
|
|
70
|
+
'likec4-color': color,
|
|
71
|
+
'likec4-shape': compound.shape,
|
|
72
|
+
'likec4-navigable': isnavigable,
|
|
73
|
+
hovered: isHovered
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
<Handle
|
|
77
|
+
type="target"
|
|
78
|
+
position={Position.Top}
|
|
79
|
+
style={{ visibility: 'hidden' }}
|
|
80
|
+
/>
|
|
81
|
+
<svg className={cssIndicator}>
|
|
82
|
+
<rect
|
|
83
|
+
x={0}
|
|
84
|
+
y={0}
|
|
85
|
+
width={'100%'}
|
|
86
|
+
height={'100%'}
|
|
87
|
+
rx={6}
|
|
88
|
+
/>
|
|
89
|
+
</svg>
|
|
90
|
+
<div className={clsx(cssCompound, 'likec4-compound')}>
|
|
91
|
+
<Text
|
|
92
|
+
component="div"
|
|
93
|
+
className={clsx(cssTitle, 'likec4-compound-title')}>
|
|
94
|
+
{compound.title}
|
|
95
|
+
</Text>
|
|
96
|
+
</div>
|
|
97
|
+
{isnavigable && <NavigateToBtn xynodeId={id} className={cssNavigateBtn} />}
|
|
98
|
+
<Handle
|
|
99
|
+
type="source"
|
|
100
|
+
position={Position.Bottom}
|
|
101
|
+
style={{ visibility: 'hidden' }}
|
|
102
|
+
/>
|
|
103
|
+
</Box>
|
|
104
|
+
)
|
|
105
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CompoundNodeMemo as CompoundNode } from './CompoundNode'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { assignInlineVars } from '@vanilla-extract/dynamic'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import type { XYFlowNode } from '../../types'
|
|
4
|
+
import { elementIcon, iconMaxH } from './element.css'
|
|
5
|
+
|
|
6
|
+
type ElementIconProps = {
|
|
7
|
+
node: XYFlowNode['data']['element']
|
|
8
|
+
maxWidth?: number | undefined
|
|
9
|
+
paddingX?: number | undefined
|
|
10
|
+
paddingY?: number | undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ElementIcon({
|
|
14
|
+
node,
|
|
15
|
+
paddingY = 32
|
|
16
|
+
}: ElementIconProps) {
|
|
17
|
+
if (!node.icon) {
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
const firstLabel = node.labels[0]
|
|
21
|
+
if (!firstLabel) {
|
|
22
|
+
return null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const firstLabelY = Math.floor(firstLabel.pt[1] - firstLabel.fontSize * 1.25)
|
|
26
|
+
const maxIconHeight = Math.floor(firstLabelY - paddingY - 16)
|
|
27
|
+
// const maxIconWidth = maxWidth ?? node.width - paddingX * 2
|
|
28
|
+
|
|
29
|
+
// const centerY = paddingY + Math.floor(maxIconHeight / 2)
|
|
30
|
+
// const centerX = Math.floor(node.width / 2)
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
className={clsx(elementIcon, 'likec4-element-icon')}
|
|
35
|
+
style={assignInlineVars({ iconMaxH }, {
|
|
36
|
+
iconMaxH: maxIconHeight + 'px'
|
|
37
|
+
})}>
|
|
38
|
+
<img
|
|
39
|
+
src={node.icon!}
|
|
40
|
+
alt={node.title}
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { globalStyle, style } from '@vanilla-extract/css'
|
|
2
|
+
import { vars } from '../../../theme.css'
|
|
3
|
+
|
|
4
|
+
export const elementLink = style({
|
|
5
|
+
position: 'absolute',
|
|
6
|
+
left: 0,
|
|
7
|
+
bottom: 0,
|
|
8
|
+
paddingLeft: 6,
|
|
9
|
+
paddingBottom: 6,
|
|
10
|
+
pointerEvents: 'all',
|
|
11
|
+
selectors: {
|
|
12
|
+
':where([data-likec4-shape="cylinder"], [data-likec4-shape="storage"]) &': {
|
|
13
|
+
bottom: 6
|
|
14
|
+
},
|
|
15
|
+
':where([data-likec4-shape="queue"]) &': {
|
|
16
|
+
left: 12,
|
|
17
|
+
bottom: -3
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// fontSize: rem(10),
|
|
21
|
+
// height: 12,
|
|
22
|
+
// width: '100%',
|
|
23
|
+
// height: '100%',
|
|
24
|
+
// vars: {
|
|
25
|
+
// [stokeFillMix]: `color-mix(in srgb, ${vars.element.stroke} 90%, ${vars.element.fill})`
|
|
26
|
+
// }
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export const trigger = style({
|
|
30
|
+
display: 'flex',
|
|
31
|
+
lineHeight: 0.75,
|
|
32
|
+
fontSize: 11,
|
|
33
|
+
fontWeight: 500,
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
color: vars.element.loContrast,
|
|
37
|
+
paddingTop: 2,
|
|
38
|
+
paddingBottom: 2,
|
|
39
|
+
paddingLeft: 4,
|
|
40
|
+
paddingRight: 5,
|
|
41
|
+
borderRadius: 3,
|
|
42
|
+
backgroundColor: `color-mix(in srgb, ${vars.element.stroke}, transparent 20%)`,
|
|
43
|
+
transition: 'all 180ms ease-out',
|
|
44
|
+
opacity: 0.85,
|
|
45
|
+
':hover': {
|
|
46
|
+
color: vars.element.hiContrast,
|
|
47
|
+
backgroundColor: vars.element.stroke,
|
|
48
|
+
opacity: 1
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
globalStyle(`${trigger} .icon`, {
|
|
53
|
+
display: 'inline-block',
|
|
54
|
+
lineHeight: 1,
|
|
55
|
+
width: 10,
|
|
56
|
+
height: 10,
|
|
57
|
+
opacity: 0.6
|
|
58
|
+
})
|
|
59
|
+
globalStyle(`${trigger} span`, {
|
|
60
|
+
display: 'inline-block',
|
|
61
|
+
lineHeight: 1,
|
|
62
|
+
marginLeft: 3
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
export const linkButton = style({
|
|
66
|
+
textAlign: 'left'
|
|
67
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { invariant } from '@likec4/core'
|
|
2
|
+
import {
|
|
3
|
+
Anchor,
|
|
4
|
+
Box,
|
|
5
|
+
Button,
|
|
6
|
+
CopyButton,
|
|
7
|
+
Group,
|
|
8
|
+
HoverCard,
|
|
9
|
+
HoverCardDropdown,
|
|
10
|
+
HoverCardTarget,
|
|
11
|
+
Stack,
|
|
12
|
+
UnstyledButton
|
|
13
|
+
} from '@mantine/core'
|
|
14
|
+
import clsx from 'clsx'
|
|
15
|
+
import { useId } from 'react'
|
|
16
|
+
import { clamp } from 'remeda'
|
|
17
|
+
import { Link } from '../../../icons'
|
|
18
|
+
import type { XYFlowNode } from '../../types'
|
|
19
|
+
import { elementLink, trigger } from './ElementLink.css'
|
|
20
|
+
|
|
21
|
+
type ElementLinkProps = {
|
|
22
|
+
element: XYFlowNode['data']['element']
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function ElementLink({
|
|
26
|
+
element
|
|
27
|
+
}: ElementLinkProps) {
|
|
28
|
+
invariant(element.links, 'ElementLink: links are required')
|
|
29
|
+
const id = useId()
|
|
30
|
+
// const mantineCtx = useMantineContext()
|
|
31
|
+
// const root = mantineCtx.getRootElement()
|
|
32
|
+
|
|
33
|
+
// const targetSelector = `.react-flow:has([data-likec4-linkid="${id}"])`
|
|
34
|
+
// // const target = root?.querySelector<HTMLDivElement>(targetSelector) ?? targetSelector
|
|
35
|
+
|
|
36
|
+
// const portalProps = useMemo(() => ({
|
|
37
|
+
// get target(): HTMLElement | string {
|
|
38
|
+
// const root = mantineCtx.getRootElement()
|
|
39
|
+
// return root?.querySelector<HTMLDivElement>(targetSelector) ?? targetSelector
|
|
40
|
+
// }
|
|
41
|
+
// }), [targetSelector])
|
|
42
|
+
return (
|
|
43
|
+
<div className={elementLink} data-likec4-linkid={id}>
|
|
44
|
+
<HoverCard
|
|
45
|
+
position="bottom-start"
|
|
46
|
+
shadow="lg"
|
|
47
|
+
radius="sm"
|
|
48
|
+
classNames={{
|
|
49
|
+
dropdown: clsx('nodrag', 'nopan')
|
|
50
|
+
}}
|
|
51
|
+
transitionProps={{
|
|
52
|
+
transition: 'pop'
|
|
53
|
+
}}
|
|
54
|
+
// portalProps={portalProps}
|
|
55
|
+
withinPortal={false}
|
|
56
|
+
floatingStrategy={'fixed'}
|
|
57
|
+
openDelay={350}
|
|
58
|
+
closeDelay={800}
|
|
59
|
+
offset={{
|
|
60
|
+
mainAxis: 5,
|
|
61
|
+
crossAxis: -10
|
|
62
|
+
}}>
|
|
63
|
+
<HoverCardTarget>
|
|
64
|
+
<UnstyledButton
|
|
65
|
+
className={clsx('nodrag nopan', trigger)}
|
|
66
|
+
autoFocus={false}>
|
|
67
|
+
<Link />
|
|
68
|
+
<span>links</span>
|
|
69
|
+
</UnstyledButton>
|
|
70
|
+
</HoverCardTarget>
|
|
71
|
+
<HoverCardDropdown onClick={e => e.stopPropagation()} p={'xs'}>
|
|
72
|
+
<Stack gap={'xs'}>
|
|
73
|
+
{element.links.map((link) => (
|
|
74
|
+
<Group key={link} wrap="nowrap" gap={'sm'}>
|
|
75
|
+
<Box flex={'1'} style={{ overflow: 'clip', maxWidth: clamp(element.width, { min: 200, max: 400 }) }}>
|
|
76
|
+
<Anchor href={link} target="_blank" fz="13" truncate="end">
|
|
77
|
+
{link}
|
|
78
|
+
</Anchor>
|
|
79
|
+
</Box>
|
|
80
|
+
<CopyButton value={link}>
|
|
81
|
+
{({ copied, copy }) => (
|
|
82
|
+
<Button size="compact-xs" fz={'12'} onClick={copy} color={copied ? 'teal' : 'gray'}>
|
|
83
|
+
{copied ? 'Copied' : 'Copy'}
|
|
84
|
+
</Button>
|
|
85
|
+
)}
|
|
86
|
+
</CopyButton>
|
|
87
|
+
</Group>
|
|
88
|
+
))}
|
|
89
|
+
</Stack>
|
|
90
|
+
</HoverCardDropdown>
|
|
91
|
+
</HoverCard>
|
|
92
|
+
</div>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { Text } from '@mantine/core'
|
|
2
|
+
import { Handle, type NodeProps, Position } from '@xyflow/react'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
import { motion, type Variants } from 'framer-motion'
|
|
5
|
+
import { isNumber } from 'remeda'
|
|
6
|
+
import { useDiagramState } from '../../../state'
|
|
7
|
+
import type { ElementXYFlowNode } from '../../types'
|
|
8
|
+
import { toDomPrecision } from '../../utils'
|
|
9
|
+
import { NavigateToBtn } from '../shared/NavigateToBtn'
|
|
10
|
+
import {
|
|
11
|
+
container,
|
|
12
|
+
cssElement,
|
|
13
|
+
cssNavigateBtn,
|
|
14
|
+
cssShapeSvg,
|
|
15
|
+
description as cssdescription,
|
|
16
|
+
indicator,
|
|
17
|
+
technology as csstechnology,
|
|
18
|
+
title as cssTitle
|
|
19
|
+
} from './element.css'
|
|
20
|
+
import { ElementIcon } from './ElementIcon'
|
|
21
|
+
import { ElementLink } from './ElementLink'
|
|
22
|
+
import { ElementShapeSvg, SelectedIndicator } from './ElementShapeSvg'
|
|
23
|
+
|
|
24
|
+
type ElementNodeProps = NodeProps<ElementXYFlowNode>
|
|
25
|
+
|
|
26
|
+
const selectedScale = 1.015
|
|
27
|
+
// Frame-motion variants
|
|
28
|
+
const variants = {
|
|
29
|
+
idle: (_, { scale }) => ({
|
|
30
|
+
scale: 1,
|
|
31
|
+
transition: {
|
|
32
|
+
delay: isNumber(scale) && scale > selectedScale ? 0.075 : 0
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
selected: (_, { scale }) => ({
|
|
36
|
+
scale: selectedScale,
|
|
37
|
+
transition: {
|
|
38
|
+
delay: isNumber(scale) && scale > selectedScale ? 0.075 : 0
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
// dragging: {
|
|
42
|
+
// scale: selectedScale
|
|
43
|
+
// },
|
|
44
|
+
// hovered: {
|
|
45
|
+
// scale: 1.08
|
|
46
|
+
// },
|
|
47
|
+
// hover: (_, {scale}) => isNumber(scale) && scale < 1.02 ? ({
|
|
48
|
+
// scale: 1.08,
|
|
49
|
+
// }) : ({
|
|
50
|
+
// scale: 1.08,
|
|
51
|
+
// transition: {
|
|
52
|
+
// delay: 1
|
|
53
|
+
// }
|
|
54
|
+
// }),
|
|
55
|
+
hovered: (_, { scale }) => ({
|
|
56
|
+
scale: 1.06,
|
|
57
|
+
transition: {
|
|
58
|
+
delay: isNumber(scale) && scale !== 1 && scale !== selectedScale ? 0 : 0.15
|
|
59
|
+
}
|
|
60
|
+
}),
|
|
61
|
+
tap: {
|
|
62
|
+
scale: 0.975
|
|
63
|
+
}
|
|
64
|
+
// tap: {
|
|
65
|
+
// scale: 0.9
|
|
66
|
+
// }
|
|
67
|
+
} satisfies Variants
|
|
68
|
+
|
|
69
|
+
export function ElementNode({
|
|
70
|
+
id,
|
|
71
|
+
data: {
|
|
72
|
+
element
|
|
73
|
+
},
|
|
74
|
+
dragging,
|
|
75
|
+
selected = false,
|
|
76
|
+
width,
|
|
77
|
+
height
|
|
78
|
+
}: ElementNodeProps) {
|
|
79
|
+
const { isHovered, hasOnNavigateTo, isHovercards, isInteractive } = useDiagramState(s => ({
|
|
80
|
+
isHovered: s.hoveredNodeId === id,
|
|
81
|
+
isInteractive: s.nodesDraggable || s.nodesSelectable,
|
|
82
|
+
isHovercards: s.showElementLinks,
|
|
83
|
+
hasOnNavigateTo: !!s.onNavigateTo
|
|
84
|
+
}))
|
|
85
|
+
// const diagramState = useDiagramState()
|
|
86
|
+
// const isNodeInteractive = diagramState.isNodeInteractive
|
|
87
|
+
// const isHovercards = diagramState.disableHovercards !== true
|
|
88
|
+
// const isNavigable = diagramState.hasOnNavigateTo && !!element.navigateTo
|
|
89
|
+
const isNavigable = hasOnNavigateTo && !!element.navigateTo
|
|
90
|
+
|
|
91
|
+
const w = toDomPrecision(width ?? element.width)
|
|
92
|
+
const h = toDomPrecision(height ?? element.height)
|
|
93
|
+
|
|
94
|
+
let animate: keyof typeof variants = 'idle'
|
|
95
|
+
switch (true) {
|
|
96
|
+
case dragging && selected:
|
|
97
|
+
animate = 'selected'
|
|
98
|
+
break
|
|
99
|
+
case dragging:
|
|
100
|
+
animate = 'idle'
|
|
101
|
+
break
|
|
102
|
+
case (isInteractive || hasOnNavigateTo) && isHovered:
|
|
103
|
+
animate = 'hovered'
|
|
104
|
+
break
|
|
105
|
+
case selected:
|
|
106
|
+
animate = 'selected'
|
|
107
|
+
break
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// useTilg(animate, isHovered, isInteractive)
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<motion.div
|
|
114
|
+
id={id}
|
|
115
|
+
className={clsx(container, 'likec4-element-node')}
|
|
116
|
+
data-likec4-color={element.color}
|
|
117
|
+
data-likec4-shape={element.shape}
|
|
118
|
+
variants={variants}
|
|
119
|
+
initial={false}
|
|
120
|
+
animate={animate}
|
|
121
|
+
{...(isInteractive && {
|
|
122
|
+
whileTap: dragging ? animate : 'tap'
|
|
123
|
+
})}
|
|
124
|
+
>
|
|
125
|
+
{
|
|
126
|
+
/* <NodeToolbar
|
|
127
|
+
position={Position.Bottom}
|
|
128
|
+
align={'start'}
|
|
129
|
+
offset={-10}
|
|
130
|
+
isVisible={selected || isHovered}>
|
|
131
|
+
<Button>editggg</Button>
|
|
132
|
+
</NodeToolbar> */
|
|
133
|
+
}
|
|
134
|
+
{
|
|
135
|
+
/* <NodeResizer minWidth={100} minHeight={30} />
|
|
136
|
+
<NodeToolbar
|
|
137
|
+
position={Position.Right}
|
|
138
|
+
align={'start'}
|
|
139
|
+
style={{
|
|
140
|
+
background: 'blue'
|
|
141
|
+
}}>
|
|
142
|
+
<Stack>
|
|
143
|
+
<Button>edit</Button>
|
|
144
|
+
|
|
145
|
+
</Stack>
|
|
146
|
+
</NodeToolbar>*/
|
|
147
|
+
}
|
|
148
|
+
{
|
|
149
|
+
/* {element.inEdges.map((edge) => (
|
|
150
|
+
<Handle
|
|
151
|
+
key={edge}
|
|
152
|
+
id={edge}
|
|
153
|
+
type="target"
|
|
154
|
+
position={Position.Top}
|
|
155
|
+
style={{ visibility: 'hidden' }}
|
|
156
|
+
/>
|
|
157
|
+
))} */
|
|
158
|
+
}
|
|
159
|
+
<Handle
|
|
160
|
+
type="target"
|
|
161
|
+
position={Position.Top}
|
|
162
|
+
style={{ visibility: 'hidden' }}
|
|
163
|
+
/>
|
|
164
|
+
<svg
|
|
165
|
+
className={cssShapeSvg}
|
|
166
|
+
viewBox={`0 0 ${w} ${h}`}
|
|
167
|
+
width={w}
|
|
168
|
+
height={h}
|
|
169
|
+
>
|
|
170
|
+
<g className={indicator}>
|
|
171
|
+
<SelectedIndicator
|
|
172
|
+
shape={element.shape}
|
|
173
|
+
w={w}
|
|
174
|
+
h={h}
|
|
175
|
+
/>
|
|
176
|
+
</g>
|
|
177
|
+
<ElementShapeSvg
|
|
178
|
+
shape={element.shape}
|
|
179
|
+
w={w}
|
|
180
|
+
h={h}
|
|
181
|
+
/>
|
|
182
|
+
</svg>
|
|
183
|
+
<div className={clsx(cssElement, 'likec4-element')}>
|
|
184
|
+
{element.icon && <ElementIcon node={element} />}
|
|
185
|
+
<Text
|
|
186
|
+
component="div"
|
|
187
|
+
className={clsx(cssTitle, 'likec4-element-title')}>
|
|
188
|
+
{element.title}
|
|
189
|
+
</Text>
|
|
190
|
+
{element.technology && (
|
|
191
|
+
<Text
|
|
192
|
+
component="div"
|
|
193
|
+
className={clsx(csstechnology, 'likec4-element-technology')}>
|
|
194
|
+
{element.technology}
|
|
195
|
+
</Text>
|
|
196
|
+
)}
|
|
197
|
+
{element.description && (
|
|
198
|
+
<Text
|
|
199
|
+
component="div"
|
|
200
|
+
className={clsx(cssdescription, 'likec4-element-description')}>
|
|
201
|
+
{element.description}
|
|
202
|
+
</Text>
|
|
203
|
+
)}
|
|
204
|
+
</div>
|
|
205
|
+
<Handle
|
|
206
|
+
type="source"
|
|
207
|
+
position={Position.Bottom}
|
|
208
|
+
style={{ visibility: 'hidden' }}
|
|
209
|
+
/>
|
|
210
|
+
{
|
|
211
|
+
/* {element.outEdges.map((edge) => (
|
|
212
|
+
<Handle
|
|
213
|
+
key={edge}
|
|
214
|
+
id={edge}
|
|
215
|
+
type="source"
|
|
216
|
+
position={Position.Bottom}
|
|
217
|
+
style={{ visibility: 'hidden' }}
|
|
218
|
+
/>
|
|
219
|
+
))} */
|
|
220
|
+
}
|
|
221
|
+
{isHovercards && element.links && <ElementLink element={element} />}
|
|
222
|
+
{isNavigable && <NavigateToBtn xynodeId={id} className={cssNavigateBtn} />}
|
|
223
|
+
</motion.div>
|
|
224
|
+
)
|
|
225
|
+
}
|