@likec4/diagram 1.13.0 → 1.15.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.
Files changed (43) hide show
  1. package/package.json +9 -9
  2. package/src/LikeC4CustomColors.tsx +6 -3
  3. package/src/LikeC4Diagram.css.ts +4 -0
  4. package/src/LikeC4Diagram.tsx +9 -7
  5. package/src/overlays/Overlays.css.ts +124 -0
  6. package/src/overlays/Overlays.tsx +210 -0
  7. package/src/overlays/edge-details/EdgeDetailsXYFlow.tsx +247 -0
  8. package/src/overlays/edge-details/SelectEdge.css.ts +99 -0
  9. package/src/overlays/edge-details/SelectEdge.tsx +153 -0
  10. package/src/overlays/edge-details/_types.ts +38 -0
  11. package/src/overlays/edge-details/use-layouted-edge-details.ts +356 -0
  12. package/src/overlays/edge-details/xyflow/CompoundNode.tsx +80 -0
  13. package/src/overlays/edge-details/xyflow/ElementNode.tsx +154 -0
  14. package/src/overlays/edge-details/xyflow/RelationshipEdge.tsx +81 -0
  15. package/src/overlays/edge-details/xyflow/styles.css.ts +196 -0
  16. package/src/overlays/index.tsx +1 -33
  17. package/src/overlays/relationships-of/RelationshipsXYFlow.tsx +124 -63
  18. package/src/overlays/relationships-of/_types.ts +13 -2
  19. package/src/overlays/relationships-of/use-layouted-relationships.ts +37 -37
  20. package/src/overlays/relationships-of/xyflow/CompoundNode.tsx +2 -2
  21. package/src/overlays/relationships-of/xyflow/ElementNode.tsx +47 -26
  22. package/src/overlays/relationships-of/xyflow/RelationshipEdge.tsx +58 -22
  23. package/src/overlays/relationships-of/xyflow/styles.css.ts +53 -16
  24. package/src/state/DiagramContext.tsx +23 -5
  25. package/src/state/diagram-to-xyflow.ts +31 -20
  26. package/src/state/diagramStore.ts +30 -23
  27. package/src/xyflow/XYFlow.tsx +2 -1
  28. package/src/xyflow/XYFlowEvents.tsx +13 -1
  29. package/src/xyflow/edges/RelationshipEdge.tsx +10 -4
  30. package/src/xyflow/edges/RelationshipsDropdownMenu.tsx +24 -21
  31. package/src/xyflow/nodes/compound/CompoundNode.css.ts +1 -0
  32. package/src/xyflow/nodes/compound/CompoundNode.tsx +11 -11
  33. package/src/xyflow/nodes/shared/Toolbar.tsx +1 -1
  34. package/src/xyflow/types.ts +1 -0
  35. package/src/xyflow/useLayoutConstraints.ts +38 -19
  36. package/src/components/Overlay.css.ts +0 -78
  37. package/src/components/Overlay.tsx +0 -102
  38. package/src/components/index.ts +0 -2
  39. package/src/overlays/edge-details/EdgeDetailsOverlay.css.ts +0 -13
  40. package/src/overlays/edge-details/EdgeDetailsOverlay.tsx +0 -37
  41. package/src/overlays/relationships-of/RelationshipsOverlay.tsx +0 -33
  42. package/src/overlays/relationships-of/styles.css.ts +0 -34
  43. /package/src/{components → overlays}/OverlayContext.tsx +0 -0
@@ -1,102 +0,0 @@
1
- import { ActionIcon, Box } from '@mantine/core'
2
- import { useMergedRef, useTimeout } from '@mantine/hooks'
3
- import { useDebouncedEffect, useSyncedRef } from '@react-hookz/web'
4
- import { IconX } from '@tabler/icons-react'
5
- import clsx from 'clsx'
6
- import { forwardRef, type HTMLAttributes, type ReactNode, useMemo, useRef, useState } from 'react'
7
- import { useDiagramStoreApi } from '../hooks/useDiagramState'
8
- import * as css from './Overlay.css'
9
- import { OverlayContext, useOverlayDialog } from './OverlayContext'
10
-
11
- type OverlayDialogProps = Pick<HTMLAttributes<HTMLDialogElement>, 'style' | 'className'> & {
12
- onClose?: (() => void) | undefined
13
- children: (renderProps: {
14
- opened: boolean
15
- close: () => void
16
- }) => ReactNode
17
- }
18
-
19
- export const OverlayDialog = forwardRef<HTMLDialogElement, OverlayDialogProps>(({
20
- className,
21
- children,
22
- onClose,
23
- ...props
24
- }, forwardedRef) => {
25
- const onCloseRef = useSyncedRef(onClose)
26
- const api = useDiagramStoreApi()
27
- const [opened, setOpened] = useState(false)
28
- const dialogRef = useRef<HTMLDialogElement>(null)
29
- const ref = useMergedRef(dialogRef, forwardedRef)
30
-
31
- useDebouncedEffect(
32
- () => {
33
- dialogRef.current?.showModal()
34
- },
35
- [],
36
- 30
37
- )
38
-
39
- useDebouncedEffect(
40
- () => {
41
- setOpened(true)
42
- },
43
- [],
44
- 80
45
- )
46
-
47
- const { start: triggerOnClose } = useTimeout(() => {
48
- onCloseRef.current?.()
49
- }, 300)
50
-
51
- const ctxValue = useMemo(() => ({
52
- openOverlay: api.getState().openOverlay,
53
- close: () => {
54
- dialogRef.current?.close()
55
- }
56
- }), [api])
57
-
58
- return (
59
- <OverlayContext.Provider value={ctxValue}>
60
- <dialog
61
- aria-modal="true"
62
- ref={ref}
63
- className={clsx(css.dialog, className)}
64
- onClick={e => {
65
- if ((e.target as any)?.nodeName?.toUpperCase() === 'DIALOG') {
66
- e.stopPropagation()
67
- dialogRef.current?.close()
68
- }
69
- }}
70
- onClose={e => {
71
- e.stopPropagation()
72
- triggerOnClose()
73
- }}
74
- {...props}
75
- >
76
- {children({
77
- opened,
78
- ...ctxValue
79
- })}
80
- </dialog>
81
- </OverlayContext.Provider>
82
- )
83
- })
84
-
85
- export const OverlayDialogCloseButton = () => {
86
- const { close } = useOverlayDialog()
87
- return (
88
- <Box pos={'absolute'} top={'1rem'} right={'1rem'}>
89
- <ActionIcon
90
- variant="default"
91
- // color="gray"
92
- size={'lg'}
93
- autoFocus
94
- onClick={(e) => {
95
- e.stopPropagation()
96
- close()
97
- }}>
98
- <IconX />
99
- </ActionIcon>
100
- </Box>
101
- )
102
- }
@@ -1,2 +0,0 @@
1
- export { OverlayDialog, OverlayDialogCloseButton } from './Overlay'
2
- export { useOverlayDialog } from './OverlayContext'
@@ -1,13 +0,0 @@
1
- import { style } from '@vanilla-extract/css'
2
-
3
- //
4
- export const dependencyViewContainer = style({
5
- width: '100%',
6
- height: '100%'
7
- // position: 'absolute',
8
- // top: 20,
9
- // left: 20,
10
- // width: 'calc(100% - 40px)',
11
- // height: 'calc(100% - 40px)',
12
- // overflow: 'hidden',
13
- })
@@ -1,37 +0,0 @@
1
- import { type EdgeId, invariant } from '@likec4/core'
2
- import { ActionIcon, Code, Paper } from '@mantine/core'
3
- import { IconX } from '@tabler/icons-react'
4
- import { OverlayDialog } from '../../components'
5
- import { useDiagramState, useDiagramStoreApi } from '../../hooks'
6
- import * as css from './EdgeDetailsOverlay.css'
7
-
8
- export function EdgeDetailsOverlay({ edgeId }: { edgeId: EdgeId }) {
9
- const diagramApi = useDiagramStoreApi()
10
- const edge = useDiagramState(s => s.xyedges.find(e => e.id === edgeId))
11
- invariant(edge, `Edge with id ${edgeId} not found`)
12
- return (
13
- <OverlayDialog
14
- onClose={() => {
15
- diagramApi.getState().closeOverlay()
16
- }}
17
- data-likec4-color="gray"
18
- >
19
- {({ close }) => (
20
- <Paper className={css.dependencyViewContainer}>
21
- <div>edge</div>
22
- <Code block>{JSON.stringify(edge, null, 2)}</Code>
23
- <ActionIcon
24
- variant="default"
25
- color="gray"
26
- autoFocus
27
- onClick={(e) => {
28
- e.stopPropagation()
29
- close()
30
- }}>
31
- <IconX />
32
- </ActionIcon>
33
- </Paper>
34
- )}
35
- </OverlayDialog>
36
- )
37
- }
@@ -1,33 +0,0 @@
1
- import { ReactFlowProvider as XYFlowProvider } from '@xyflow/react'
2
- import { memo } from 'react'
3
- import { OverlayDialog, OverlayDialogCloseButton } from '../../components'
4
- import { useDiagramStoreApi } from '../../hooks'
5
- import { RelationshipsXYFlow } from './RelationshipsXYFlow'
6
- import * as css from './styles.css'
7
-
8
- export const RelationshipsOfOverlay = memo(() => {
9
- const diagramApi = useDiagramStoreApi()
10
-
11
- return (
12
- <OverlayDialog
13
- className={css.overlay}
14
- onClose={() => {
15
- diagramApi.getState().closeOverlay()
16
- }}
17
- data-likec4-color="gray"
18
- >
19
- {({ opened }) => (
20
- <>
21
- {opened && (
22
- <XYFlowProvider
23
- defaultNodes={[]}
24
- defaultEdges={[]}>
25
- <RelationshipsXYFlow />
26
- </XYFlowProvider>
27
- )}
28
- <OverlayDialogCloseButton />
29
- </>
30
- )}
31
- </OverlayDialog>
32
- )
33
- })
@@ -1,34 +0,0 @@
1
- import { createVar, globalStyle, style } from '@vanilla-extract/css'
2
- import { vars, xyvars } from '../../theme-vars'
3
-
4
- const mixColor = createVar('mix-color')
5
-
6
- export const root = 'likec4-relationships-xyflow'
7
-
8
- export const overlay = style({
9
- vars: {
10
- [mixColor]: `black`,
11
- [xyvars.edge.stroke]: vars.relation.lineColor,
12
- [xyvars.edge.strokeSelected]: `color-mix(in srgb, ${vars.relation.lineColor}, ${mixColor} 35%)`,
13
- [xyvars.edge.labelColor]: `color-mix(in srgb, ${vars.relation.labelColor}, rgba(255 255 255 / 0.85) 50%)`,
14
- [xyvars.edge.labelBgColor]: `color-mix(in srgb, ${vars.relation.labelBgColor}, transparent 30%)`
15
- }
16
- })
17
-
18
- globalStyle(`:where([data-mantine-color-scheme="dark"]) ${overlay}`, {
19
- vars: {
20
- [mixColor]: `white`,
21
- [xyvars.edge.labelColor]: vars.relation.labelColor,
22
- [xyvars.edge.labelBgColor]: `color-mix(in srgb, ${vars.relation.labelBgColor}, transparent 50%)`
23
- }
24
- })
25
-
26
- globalStyle(`:where(${overlay}) .react-flow__attribution`, {
27
- display: 'none'
28
- })
29
- globalStyle(`:where(${overlay}) .react-flow__edge-text`, {
30
- fontSize: 14
31
- })
32
- globalStyle(`:where(${overlay}) .react-flow__node-compound`, {
33
- mixBlendMode: 'hard-light'
34
- })
File without changes