@likec4/diagram 1.17.1 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/LICENSE +1 -1
  2. package/dist/LikeC4CustomColors.d.ts +7 -0
  3. package/dist/LikeC4CustomColors.js +30 -0
  4. package/dist/LikeC4Diagram.css.d.ts +5 -0
  5. package/dist/LikeC4Diagram.css.js +13 -0
  6. package/dist/LikeC4Diagram.d.ts +6 -0
  7. package/dist/LikeC4Diagram.js +194 -0
  8. package/dist/LikeC4Diagram.props.d.ts +166 -0
  9. package/dist/LikeC4ModelProvider.d.ts +9 -0
  10. package/dist/LikeC4ModelProvider.js +12 -0
  11. package/dist/LikeC4Search.css.d.ts +1 -0
  12. package/dist/LikeC4Search.css.js +5 -0
  13. package/dist/LikeC4Search.d.ts +2 -0
  14. package/dist/LikeC4Search.js +96 -0
  15. package/dist/StaticLikeC4Diagram.d.ts +3 -0
  16. package/dist/StaticLikeC4Diagram.js +41 -0
  17. package/dist/_virtual/_commonjsHelpers.js +6 -0
  18. package/dist/controls/Text.d.ts +2 -0
  19. package/dist/controls/Text.js +7 -0
  20. package/dist/controls/action-button-bar/ActionButtonBar.css.d.ts +1 -0
  21. package/dist/controls/action-button-bar/ActionButtonBar.css.js +5 -0
  22. package/dist/controls/action-button-bar/ActionButtonBar.d.ts +9 -0
  23. package/dist/controls/action-button-bar/ActionButtonBar.js +100 -0
  24. package/dist/controls/action-button-bar/useActionButtonBarCtx.d.ts +10 -0
  25. package/dist/controls/action-button-bar/useActionButtonBarCtx.js +9 -0
  26. package/dist/controls/action-buttons/ActionButton.css.d.ts +1 -0
  27. package/dist/controls/action-buttons/ActionButton.css.js +5 -0
  28. package/dist/controls/action-buttons/ActionButton.d.ts +9 -0
  29. package/dist/controls/action-buttons/ActionButton.js +66 -0
  30. package/dist/controls/action-buttons/ActionButtons.d.ts +12 -0
  31. package/dist/controls/action-buttons/ActionButtons.js +99 -0
  32. package/dist/globals.css.d.ts +1 -0
  33. package/dist/globals.css.js +92 -0
  34. package/dist/hooks/index.d.ts +5 -0
  35. package/dist/hooks/useDiagramState.d.ts +6 -0
  36. package/dist/hooks/useDiagramState.js +27 -0
  37. package/dist/hooks/useMantinePortalProps.d.ts +9 -0
  38. package/dist/hooks/useMantinePortalProps.js +9 -0
  39. package/dist/hooks/useSetState.d.ts +2 -0
  40. package/dist/hooks/useSetState.js +19 -0
  41. package/dist/hooks/useUpdateEffect.d.ts +4 -0
  42. package/dist/hooks/useUpdateEffect.js +32 -0
  43. package/dist/hooks/useXYFlow.d.ts +270 -0
  44. package/dist/hooks/useXYFlow.js +20 -0
  45. package/dist/index.d.ts +11 -0
  46. package/dist/index.js +25 -0
  47. package/dist/likec4model/LikeC4ModelContext.d.ts +3 -0
  48. package/dist/likec4model/LikeC4ModelContext.js +5 -0
  49. package/dist/likec4model/index.d.ts +2 -0
  50. package/dist/likec4model/useLikeC4ElementsTree.d.ts +12 -0
  51. package/dist/likec4model/useLikeC4ElementsTree.js +25 -0
  52. package/dist/likec4model/useLikeC4Model.d.ts +20 -0
  53. package/dist/likec4model/useLikeC4Model.js +55 -0
  54. package/dist/overlays/OverlayContext.d.ts +10 -0
  55. package/dist/overlays/OverlayContext.js +9 -0
  56. package/dist/overlays/Overlays.css.d.ts +3 -0
  57. package/dist/overlays/Overlays.css.js +7 -0
  58. package/dist/overlays/Overlays.d.ts +2 -0
  59. package/dist/overlays/Overlays.js +137 -0
  60. package/dist/overlays/edge-details/EdgeDetailsXYFlow.d.ts +5 -0
  61. package/dist/overlays/edge-details/EdgeDetailsXYFlow.js +185 -0
  62. package/dist/overlays/edge-details/SelectEdge.css.d.ts +7 -0
  63. package/dist/overlays/edge-details/SelectEdge.css.js +17 -0
  64. package/dist/overlays/edge-details/SelectEdge.d.ts +5 -0
  65. package/dist/overlays/edge-details/SelectEdge.js +129 -0
  66. package/dist/overlays/edge-details/_types.d.ts +14 -0
  67. package/dist/overlays/edge-details/use-layouted-edge-details.d.ts +21 -0
  68. package/dist/overlays/edge-details/use-layouted-edge-details.js +270 -0
  69. package/dist/overlays/edge-details/xyflow/CompoundNode.d.ts +5 -0
  70. package/dist/overlays/edge-details/xyflow/CompoundNode.js +76 -0
  71. package/dist/overlays/edge-details/xyflow/ElementNode.d.ts +5 -0
  72. package/dist/overlays/edge-details/xyflow/ElementNode.js +159 -0
  73. package/dist/overlays/edge-details/xyflow/RelationshipEdge.d.ts +3 -0
  74. package/dist/overlays/edge-details/xyflow/RelationshipEdge.js +84 -0
  75. package/dist/overlays/edge-details/xyflow/styles.css.d.ts +9 -0
  76. package/dist/overlays/edge-details/xyflow/styles.css.js +21 -0
  77. package/dist/overlays/element-details/ElementDetailsCard.css.d.ts +16 -0
  78. package/dist/overlays/element-details/ElementDetailsCard.css.js +33 -0
  79. package/dist/overlays/element-details/ElementDetailsCard.d.ts +7 -0
  80. package/dist/overlays/element-details/ElementDetailsCard.js +484 -0
  81. package/dist/overlays/element-details/TabPanelDeployments.css.d.ts +4 -0
  82. package/dist/overlays/element-details/TabPanelDeployments.css.js +11 -0
  83. package/dist/overlays/element-details/TabPanelDeployments.d.ts +7 -0
  84. package/dist/overlays/element-details/TabPanelDeployments.js +173 -0
  85. package/dist/overlays/element-details/TabPanelRelationships.css.d.ts +5 -0
  86. package/dist/overlays/element-details/TabPanelRelationships.css.js +11 -0
  87. package/dist/overlays/element-details/TabPanelRelationships.d.ts +8 -0
  88. package/dist/overlays/element-details/TabPanelRelationships.js +157 -0
  89. package/dist/overlays/element-details/TabPanelStructure.css.d.ts +2 -0
  90. package/dist/overlays/element-details/TabPanelStructure.css.js +7 -0
  91. package/dist/overlays/element-details/TabPanelStructure.d.ts +25 -0
  92. package/dist/overlays/element-details/TabPanelStructure.js +91 -0
  93. package/dist/overlays/index.d.ts +1 -0
  94. package/dist/overlays/relationships-of/RelationshipsOverlay.d.ts +5 -0
  95. package/dist/overlays/relationships-of/RelationshipsOverlay.js +193 -0
  96. package/dist/overlays/relationships-of/RelationshipsXYFlow.d.ts +19 -0
  97. package/dist/overlays/relationships-of/RelationshipsXYFlow.js +290 -0
  98. package/dist/overlays/relationships-of/SelectElement.css.d.ts +2 -0
  99. package/dist/overlays/relationships-of/SelectElement.css.js +7 -0
  100. package/dist/overlays/relationships-of/SelectElement.d.ts +7 -0
  101. package/dist/overlays/relationships-of/SelectElement.js +126 -0
  102. package/dist/overlays/relationships-of/_types.d.ts +28 -0
  103. package/dist/overlays/relationships-of/use-layouted-relationships.d.ts +22 -0
  104. package/dist/overlays/relationships-of/use-layouted-relationships.js +496 -0
  105. package/dist/overlays/relationships-of/xyflow/CompoundNode.d.ts +6 -0
  106. package/dist/overlays/relationships-of/xyflow/CompoundNode.js +120 -0
  107. package/dist/overlays/relationships-of/xyflow/ElementNode.d.ts +6 -0
  108. package/dist/overlays/relationships-of/xyflow/ElementNode.js +194 -0
  109. package/dist/overlays/relationships-of/xyflow/EmptyNode.d.ts +5 -0
  110. package/dist/overlays/relationships-of/xyflow/EmptyNode.js +18 -0
  111. package/dist/overlays/relationships-of/xyflow/RelationshipEdge.d.ts +3 -0
  112. package/dist/overlays/relationships-of/xyflow/RelationshipEdge.js +123 -0
  113. package/dist/overlays/relationships-of/xyflow/styles.css.d.ts +14 -0
  114. package/dist/overlays/relationships-of/xyflow/styles.css.js +24 -0
  115. package/dist/overlays/shared/xyflow/RelationshipEdge.css.d.ts +4 -0
  116. package/dist/overlays/shared/xyflow/RelationshipEdge.css.js +12 -0
  117. package/dist/overlays/shared/xyflow/_types.d.ts +77 -0
  118. package/dist/state/DiagramContext.d.ts +1609 -0
  119. package/dist/state/DiagramContext.js +101 -0
  120. package/dist/state/aligners.d.ts +42 -0
  121. package/dist/state/aligners.js +349 -0
  122. package/dist/state/diagram-to-xyflow.d.ts +11 -0
  123. package/dist/state/diagram-to-xyflow.js +113 -0
  124. package/dist/state/diagramStore.d.ts +1705 -0
  125. package/dist/state/diagramStore.js +808 -0
  126. package/dist/state/diagramStore.layout.d.ts +4 -0
  127. package/dist/state/diagramStore.layout.js +56 -0
  128. package/dist/style.css +1 -0
  129. package/dist/theme-vars.css.d.ts +72 -0
  130. package/dist/theme-vars.css.js +6 -0
  131. package/dist/theme-vars.css.ts.vanilla.css.js +1 -0
  132. package/dist/theme-vars.d.ts +3 -0
  133. package/dist/theme-vars.js +5 -0
  134. package/dist/ui/DiagramTitlePanel.css.d.ts +4 -0
  135. package/dist/ui/DiagramTitlePanel.css.js +11 -0
  136. package/dist/ui/DiagramTitlePanel.d.ts +1 -0
  137. package/dist/ui/DiagramTitlePanel.js +159 -0
  138. package/dist/ui/DynamicViewWalkthrough.css.d.ts +4 -0
  139. package/dist/ui/DynamicViewWalkthrough.css.js +11 -0
  140. package/dist/ui/DynamicViewWalkthrough.d.ts +1 -0
  141. package/dist/ui/DynamicViewWalkthrough.js +156 -0
  142. package/dist/ui/EnsureMantine.d.ts +7 -0
  143. package/dist/ui/EnsureMantine.js +14 -0
  144. package/dist/ui/FramerMotionConfig.d.ts +2 -0
  145. package/dist/ui/FramerMotionConfig.js +14 -0
  146. package/dist/ui/Link.d.ts +4 -0
  147. package/dist/ui/Link.js +36 -0
  148. package/dist/ui/notation/NotationPanel.css.d.ts +6 -0
  149. package/dist/ui/notation/NotationPanel.css.js +16 -0
  150. package/dist/ui/notation/NotationPanel.d.ts +1 -0
  151. package/dist/ui/notation/NotationPanel.js +250 -0
  152. package/dist/ui/notation/index.d.ts +1 -0
  153. package/dist/ui/top-left/ChangeAutoLayoutButton.d.ts +2 -0
  154. package/dist/ui/top-left/ChangeAutoLayoutButton.js +159 -0
  155. package/dist/ui/top-left/ManualLayoutToolsButton.d.ts +2 -0
  156. package/dist/ui/top-left/ManualLayoutToolsButton.js +137 -0
  157. package/dist/ui/top-left/TopLeftPanel.d.ts +4 -0
  158. package/dist/ui/top-left/TopLeftPanel.js +211 -0
  159. package/dist/ui/top-left/_shared.d.ts +7 -0
  160. package/dist/ui/top-left/_shared.js +22 -0
  161. package/dist/ui/top-left/styles.css.d.ts +8 -0
  162. package/dist/ui/top-left/styles.css.js +17 -0
  163. package/dist/utils/types.d.ts +8 -0
  164. package/dist/utils/vector.d.ts +24 -0
  165. package/dist/utils/vector.js +55 -0
  166. package/dist/xyflow/EdgeMarkers.d.ts +12 -0
  167. package/dist/xyflow/EdgeMarkers.js +192 -0
  168. package/dist/xyflow/FitviewOnDiagramChange.d.ts +4 -0
  169. package/dist/xyflow/FitviewOnDiagramChange.js +72 -0
  170. package/dist/xyflow/SelectEdgesOnNodeFocus.d.ts +1 -0
  171. package/dist/xyflow/SelectEdgesOnNodeFocus.js +96 -0
  172. package/dist/xyflow/XYFlow.d.ts +8 -0
  173. package/dist/xyflow/XYFlow.js +145 -0
  174. package/dist/xyflow/XYFlowBackground.d.ts +10 -0
  175. package/dist/xyflow/XYFlowBackground.js +25 -0
  176. package/dist/xyflow/XYFlowInner.d.ts +8 -0
  177. package/dist/xyflow/XYFlowInner.js +41 -0
  178. package/dist/xyflow/const.d.ts +7 -0
  179. package/dist/xyflow/const.js +12 -0
  180. package/dist/xyflow/edges/EdgeLabel.d.ts +7 -0
  181. package/dist/xyflow/edges/EdgeLabel.js +160 -0
  182. package/dist/xyflow/edges/RelationshipEdge.d.ts +6 -0
  183. package/dist/xyflow/edges/RelationshipEdge.js +443 -0
  184. package/dist/xyflow/edges/RelationshipsDropdownMenu.css.d.ts +4 -0
  185. package/dist/xyflow/edges/RelationshipsDropdownMenu.css.js +11 -0
  186. package/dist/xyflow/edges/RelationshipsDropdownMenu.d.ts +13 -0
  187. package/dist/xyflow/edges/RelationshipsDropdownMenu.js +211 -0
  188. package/dist/xyflow/edges/edges.css.d.ts +17 -0
  189. package/dist/xyflow/edges/edges.css.js +37 -0
  190. package/dist/xyflow/edges/utils.d.ts +16 -0
  191. package/dist/xyflow/edges/utils.js +24 -0
  192. package/dist/xyflow/nodes/AnimateVariants.d.ts +1313 -0
  193. package/dist/xyflow/nodes/AnimateVariants.js +123 -0
  194. package/dist/xyflow/nodes/Node.css.d.ts +3 -0
  195. package/dist/xyflow/nodes/Node.css.js +9 -0
  196. package/dist/xyflow/nodes/compound/CompoundNode.css.d.ts +14 -0
  197. package/dist/xyflow/nodes/compound/CompoundNode.css.js +27 -0
  198. package/dist/xyflow/nodes/compound/CompoundNode.d.ts +6 -0
  199. package/dist/xyflow/nodes/compound/CompoundNode.js +216 -0
  200. package/dist/xyflow/nodes/compound/index.d.ts +1 -0
  201. package/dist/xyflow/nodes/element/ElementLink.css.d.ts +3 -0
  202. package/dist/xyflow/nodes/element/ElementLink.d.ts +6 -0
  203. package/dist/xyflow/nodes/element/ElementNode.d.ts +6 -0
  204. package/dist/xyflow/nodes/element/ElementNode.js +190 -0
  205. package/dist/xyflow/nodes/element/ElementShapeSvg.d.ts +17 -0
  206. package/dist/xyflow/nodes/element/ElementShapeSvg.js +175 -0
  207. package/dist/xyflow/nodes/element/element.css.d.ts +18 -0
  208. package/dist/xyflow/nodes/element/element.css.js +31 -0
  209. package/dist/xyflow/nodes/element/index.d.ts +1 -0
  210. package/dist/xyflow/nodes/shared/ElementIcon.d.ts +8 -0
  211. package/dist/xyflow/nodes/shared/ElementIcon.js +38 -0
  212. package/dist/xyflow/nodes/shared/Toolbar.d.ts +9 -0
  213. package/dist/xyflow/nodes/shared/Toolbar.js +436 -0
  214. package/dist/xyflow/types.d.ts +36 -0
  215. package/dist/xyflow/useLayoutConstraints.d.ts +42 -0
  216. package/dist/xyflow/useLayoutConstraints.js +226 -0
  217. package/dist/xyflow/useXYFlowEvents.d.ts +160 -0
  218. package/dist/xyflow/useXYFlowEvents.js +275 -0
  219. package/dist/xyflow/utils.d.ts +22 -0
  220. package/dist/xyflow/utils.js +72 -0
  221. package/package.json +40 -31
  222. package/src/LikeC4Diagram.props.ts +21 -12
  223. package/src/LikeC4Diagram.tsx +8 -10
  224. package/src/LikeC4Search.css.ts +12 -0
  225. package/src/LikeC4Search.tsx +45 -93
  226. package/src/controls/Text.ts +5 -0
  227. package/src/controls/action-button-bar/ActionButtonBar.css.ts +13 -0
  228. package/src/controls/action-button-bar/ActionButtonBar.tsx +138 -0
  229. package/src/controls/action-button-bar/useActionButtonBarCtx.ts +13 -0
  230. package/src/controls/action-buttons/ActionButton.css.ts +29 -0
  231. package/src/controls/action-buttons/ActionButton.tsx +66 -0
  232. package/src/controls/action-buttons/ActionButtons.tsx +138 -0
  233. package/src/hooks/useDiagramState.ts +8 -3
  234. package/src/hooks/useXYFlow.ts +9 -8
  235. package/src/index.ts +12 -6
  236. package/src/likec4model/index.ts +12 -2
  237. package/src/likec4model/useLikeC4ElementsTree.ts +6 -13
  238. package/src/likec4model/useLikeC4Model.ts +21 -11
  239. package/src/overlays/Overlays.tsx +96 -63
  240. package/src/overlays/edge-details/EdgeDetailsXYFlow.tsx +18 -10
  241. package/src/overlays/edge-details/_types.ts +13 -33
  242. package/src/overlays/edge-details/use-layouted-edge-details.ts +35 -26
  243. package/src/overlays/edge-details/xyflow/CompoundNode.tsx +3 -11
  244. package/src/overlays/edge-details/xyflow/ElementNode.tsx +8 -13
  245. package/src/overlays/edge-details/xyflow/RelationshipEdge.tsx +7 -7
  246. package/src/overlays/edge-details/xyflow/styles.css.ts +1 -59
  247. package/src/overlays/element-details/ElementDetailsCard.tsx +91 -78
  248. package/src/overlays/element-details/TabPanelDeployments.css.ts +69 -0
  249. package/src/overlays/element-details/TabPanelDeployments.tsx +217 -0
  250. package/src/overlays/element-details/TabPanelRelationships.tsx +8 -9
  251. package/src/overlays/element-details/TabPanelStructure.tsx +10 -10
  252. package/src/overlays/relationships-of/RelationshipsOverlay.tsx +1 -1
  253. package/src/overlays/relationships-of/RelationshipsXYFlow.tsx +26 -34
  254. package/src/overlays/relationships-of/SelectElement.tsx +2 -2
  255. package/src/overlays/relationships-of/_types.ts +20 -58
  256. package/src/overlays/relationships-of/use-layouted-relationships.ts +54 -59
  257. package/src/overlays/relationships-of/xyflow/CompoundNode.tsx +10 -16
  258. package/src/overlays/relationships-of/xyflow/ElementNode.tsx +24 -21
  259. package/src/overlays/relationships-of/xyflow/EmptyNode.tsx +4 -7
  260. package/src/overlays/relationships-of/xyflow/RelationshipEdge.tsx +16 -15
  261. package/src/overlays/shared/xyflow/RelationshipEdge.css.ts +60 -0
  262. package/src/overlays/shared/xyflow/_types.ts +87 -0
  263. package/src/state/diagram-to-xyflow.ts +6 -7
  264. package/src/state/diagramStore.layout.ts +3 -4
  265. package/src/state/diagramStore.ts +63 -48
  266. package/src/theme-vars.css.ts +81 -0
  267. package/src/theme-vars.ts +8 -81
  268. package/src/ui/DiagramTitlePanel.tsx +7 -34
  269. package/src/ui/Link.tsx +40 -0
  270. package/src/ui/notation/NotationPanel.tsx +4 -2
  271. package/src/ui/top-left/ChangeAutoLayoutButton.tsx +2 -2
  272. package/src/ui/top-left/TopLeftPanel.tsx +5 -5
  273. package/src/utils/types.ts +6 -0
  274. package/src/xyflow/SelectEdgesOnNodeFocus.tsx +3 -3
  275. package/src/xyflow/XYFlow.tsx +2 -2
  276. package/src/xyflow/edges/EdgeLabel.tsx +26 -19
  277. package/src/xyflow/edges/RelationshipEdge.tsx +5 -3
  278. package/src/xyflow/edges/RelationshipsDropdownMenu.tsx +23 -10
  279. package/src/xyflow/edges/edges.css.ts +68 -74
  280. package/src/xyflow/edges/utils.ts +6 -6
  281. package/src/xyflow/nodes/AnimateVariants.ts +143 -0
  282. package/src/xyflow/nodes/Node.css.ts +44 -0
  283. package/src/xyflow/nodes/compound/CompoundNode.css.ts +27 -75
  284. package/src/xyflow/nodes/compound/CompoundNode.tsx +82 -163
  285. package/src/xyflow/nodes/element/ElementLink.tsx +2 -3
  286. package/src/xyflow/nodes/element/ElementNode.tsx +73 -252
  287. package/src/xyflow/nodes/element/element.css.ts +40 -64
  288. package/src/xyflow/nodes/shared/ElementIcon.tsx +1 -1
  289. package/src/xyflow/nodes/shared/Toolbar.tsx +51 -35
  290. package/src/xyflow/types.ts +48 -51
  291. package/src/xyflow/useLayoutConstraints.ts +10 -10
  292. package/src/xyflow/useXYFlowEvents.ts +31 -35
  293. package/src/xyflow/utils.ts +2 -2
  294. package/src/ui/OptionsPanel.css.ts +0 -9
  295. package/src/ui/OptionsPanel.tsx +0 -70
  296. package/src/ui/options/EdgeOptions.tsx +0 -142
  297. package/src/ui/options/NodeOptions.tsx +0 -362
  298. package/src/xyflow/nodes/element/ElementDetails.css.ts +0 -101
  299. package/src/xyflow/nodes/element/ElementDetails.tsx +0 -393
  300. package/src/xyflow/nodes/use-animate-variants.tsx +0 -64
@@ -1,393 +0,0 @@
1
- import { type ComputedView, type DiagramView, type EdgeId, invariant, nameFromFqn, type ViewID } from '@likec4/core'
2
- import {
3
- Anchor,
4
- Badge,
5
- Box,
6
- Button,
7
- CopyButton,
8
- Divider as MantineDivider,
9
- Flex,
10
- Group,
11
- Paper,
12
- ScrollAreaAutosize,
13
- Stack,
14
- Text
15
- } from '@mantine/core'
16
- import { useElementSize, useHotkeys } from '@mantine/hooks'
17
- import { IconArrowRight, IconInfoCircle, IconTransform, IconZoomScan } from '@tabler/icons-react'
18
- import { useInternalNode, useViewport, ViewportPortal } from '@xyflow/react'
19
- import { getNodeDimensions, getViewportForBounds, type Viewport } from '@xyflow/system'
20
- import clsx from 'clsx'
21
- import React, { memo, type ReactNode, useCallback, useState } from 'react'
22
- import { createPortal } from 'react-dom'
23
- import { clamp, unique } from 'remeda'
24
- import { useDiagramStoreApi, useXYStore } from '../../../hooks'
25
- import type { OnNavigateTo } from '../../../LikeC4Diagram.props'
26
- import { useLikeC4Model } from '../../../likec4model'
27
- import { MinZoom } from '../../const'
28
- import type { ElementXYFlowNode, XYFlowState } from '../../types'
29
- import * as css from './ElementDetails.css'
30
-
31
- const Divider = MantineDivider.withProps({
32
- mb: 6,
33
- labelPosition: 'left',
34
- variant: 'dashed'
35
- })
36
-
37
- const selector = (state: XYFlowState) => state.domNode?.querySelector('.react-flow__renderer')
38
- // const selector = (state: XYFlowState) => state.domNode?.querySelector('.react-flow__nodes');
39
-
40
- export function NodeToolbarPortal({ children }: { children: ReactNode }) {
41
- const wrapperRef = useXYStore(selector)
42
-
43
- if (!wrapperRef) {
44
- return null
45
- }
46
-
47
- return createPortal(children, wrapperRef)
48
- }
49
-
50
- type ElementDetailsProps = {
51
- nodeId: string
52
- }
53
-
54
- const MAX_HEIGHT = 300
55
-
56
- export const ElementDetails = memo<ElementDetailsProps>(({ nodeId }) => {
57
- const [previousViewport, setPreviousViewport] = useState<null | Viewport>(null)
58
- const diagramApi = useDiagramStoreApi()
59
- const xyviewport = useViewport()
60
- const { ref, height: detailsHeight } = useElementSize()
61
- const hoveredNode = useInternalNode<ElementXYFlowNode>(nodeId)
62
- invariant(hoveredNode, 'Node not found')
63
-
64
- const {
65
- data: { element },
66
- internals: {
67
- positionAbsolute
68
- }
69
- } = hoveredNode
70
-
71
- const likec4Model = useLikeC4Model(true)
72
- const elementModel = likec4Model.element(element.id)
73
-
74
- const incoming = elementModel.incoming().map(r => r.id)
75
- const outgoing = elementModel.outgoing().map(r => r.id)
76
-
77
- const { view: currentView, onNavigateTo } = diagramApi.getState()
78
-
79
- const findRelationIds = (edgeId: EdgeId) => currentView.edges.find((edge) => edge.id === edgeId)?.relations ?? []
80
-
81
- const incomingInView = unique(element.inEdges.flatMap(findRelationIds))
82
- const outgoingInView = unique(element.outEdges.flatMap(findRelationIds))
83
-
84
- const notIncludedRelations = [
85
- ...incoming,
86
- ...outgoing
87
- ].filter(r => !incomingInView.includes(r) && !outgoingInView.includes(r)).length
88
-
89
- const defaultView = (element.navigateTo && element.navigateTo !== currentView.id)
90
- ? likec4Model.view(element.navigateTo).view
91
- : null
92
- const otherViews = elementModel.views().filter(v => v.id !== currentView.id && v.id !== element.navigateTo).map(v =>
93
- v.view
94
- )
95
-
96
- const { width: nodeWidth, height } = getNodeDimensions(hoveredNode)
97
- const width = Math.round(nodeWidth * 1.015)
98
- const left = positionAbsolute.x
99
- const top = positionAbsolute.y + height
100
-
101
- const zoomInOut = useCallback((e: React.UIEvent) => {
102
- e.stopPropagation()
103
- const {
104
- xyflow,
105
- xystore,
106
- fitViewPadding
107
- } = diagramApi.getState()
108
- if (previousViewport) {
109
- xyflow.updateNode(nodeId, { selected: false })
110
- xyflow.setViewport(previousViewport, { duration: 500 })
111
- setPreviousViewport(null)
112
- return
113
- }
114
- setPreviousViewport({ ...xyflow.getViewport() })
115
- const xy = xystore.getState()
116
- xy.addSelectedNodes([nodeId])
117
- const viewport = getViewportForBounds(
118
- {
119
- x: positionAbsolute.x - 25,
120
- y: positionAbsolute.y,
121
- width: width + 50,
122
- height: height + MAX_HEIGHT + 20
123
- },
124
- xy.width,
125
- xy.height,
126
- MinZoom,
127
- 1.3,
128
- fitViewPadding
129
- )
130
- xyflow.setViewport(viewport, { duration: 500 })
131
- }, [previousViewport, width, height, positionAbsolute])
132
-
133
- useHotkeys(
134
- previousViewport
135
- ? [
136
- ['Escape', zoomInOut as any, { preventDefault: true }]
137
- ]
138
- : []
139
- )
140
-
141
- const openRelationshipsOverlay = useCallback((e: React.MouseEvent): void => {
142
- e.stopPropagation()
143
- diagramApi.getState().openOverlay({
144
- relationshipsOf: element.id
145
- })
146
- }, [element.id])
147
-
148
- const onNavigateToCb = useCallback((toView: ViewID, e?: React.MouseEvent): void => {
149
- e?.stopPropagation()
150
- diagramApi.setState({
151
- hoveredNodeId: null,
152
- lastClickedNodeId: nodeId,
153
- lastOnNavigate: {
154
- fromView: currentView.id,
155
- toView,
156
- fromNode: element.id
157
- }
158
- })
159
- diagramApi.getState().onNavigateTo?.(toView, e)
160
- }, [element.id, currentView.id, nodeId])
161
-
162
- return (
163
- <ViewportPortal>
164
- <Paper
165
- shadow="lg"
166
- radius="sm"
167
- p={0}
168
- data-likec4-color={element.color}
169
- className={clsx(css.container, 'nodrag')}
170
- style={{
171
- transform: `translate(${left}px, ${top + 18}px)`,
172
- maxWidth: Math.max(width + 30, 450),
173
- width: 'max-content',
174
- minWidth: width,
175
- cursor: xyviewport.zoom < 1.01 ? 'pointer' : 'default'
176
- }}
177
- onClick={xyviewport.zoom < 1.01 ? zoomInOut : undefined}
178
- >
179
- <Group align="baseline" m="xs" wrap="nowrap" justify="space-between">
180
- <Box flex={0}>
181
- <Text component="span" size="sm" c="dimmed">kind:</Text>
182
- <Text component="span" size="sm" fw={600}>{element.kind}</Text>
183
- </Box>
184
- {element.tags && (
185
- <Flex gap={4} flex={1}>
186
- {/* {element.tags.map((tag) => <Text key={tag} size="xs" fw={600}>#{tag}</Text>)} */}
187
- {element.tags.map((tag) => (
188
- <Badge key={tag} color="violet" radius={'sm'} size="sm" fw={600} variant="gradient">#{tag}</Badge>
189
- ))}
190
- </Flex>
191
- )}
192
- <Box flex={0}>
193
- <Button
194
- size="xs"
195
- color="gray"
196
- variant="light"
197
- radius="sm"
198
- onClick={zoomInOut}
199
- >
200
- {previousViewport && 'Back'}
201
- {!previousViewport && (xyviewport.zoom < 1.01 ? 'Zoom' : 'Center')}
202
- </Button>
203
- </Box>
204
- </Group>
205
- <ScrollAreaAutosize
206
- mah={MAX_HEIGHT}
207
- mt={10}
208
- className={clsx(
209
- (detailsHeight > MAX_HEIGHT) && (
210
- (previousViewport || xyviewport.zoom > 1.1) ? 'nowheel' : css.noPointerEvents
211
- )
212
- )}
213
- pb={'sm'}
214
- scrollbars="y"
215
- type="hover">
216
- <Stack gap={'md'} px="xs" ref={ref}>
217
- {element.notation && <Text style={{ maxWidth: width }}>{element.notation}</Text>}
218
- {defaultView && !!onNavigateTo && (
219
- <Box>
220
- <Divider label="view of this element" />
221
- <ViewButton view={defaultView} onNavigateTo={onNavigateToCb} />
222
- </Box>
223
- )}
224
- {(incoming.length + outgoing.length) > 0 && (
225
- <Box>
226
- <Divider label="relationships" />
227
- <Group gap={'xs'} justify="space-between" wrap="nowrap" align="baseline">
228
- <Box>
229
- <Group gap={6} c={'dimmed'} mb={4} wrap="nowrap">
230
- <Text
231
- className={css.edgeNum}
232
- mod={{
233
- zero: incoming.length === 0,
234
- missing: incoming.length !== incomingInView.length
235
- }}>
236
- {incoming.length !== incomingInView.length
237
- ? (
238
- <>
239
- {incomingInView.length} / {incoming.length}
240
- </>
241
- )
242
- : (
243
- <>
244
- {incoming.length}
245
- </>
246
- )}
247
- </Text>
248
- <IconArrowRight style={{ width: 14 }} />
249
- <Text className={css.fqn}>{nameFromFqn(element.id)}</Text>
250
- <IconArrowRight style={{ width: 14 }} />
251
- <Text
252
- className={css.edgeNum}
253
- mod={{
254
- zero: outgoing.length === 0,
255
- missing: outgoing.length !== outgoingInView.length
256
- }}>
257
- {outgoing.length !== outgoingInView.length
258
- ? (
259
- <>
260
- {outgoingInView.length} / {outgoing.length}
261
- </>
262
- )
263
- : (
264
- <>
265
- {outgoing.length}
266
- </>
267
- )}
268
- </Text>
269
- </Group>
270
- {notIncludedRelations > 0 && (
271
- <Group
272
- mt={'xs'}
273
- gap={6}
274
- c="orange"
275
- style={{ cursor: 'pointer' }}
276
- onClick={openRelationshipsOverlay}>
277
- <IconInfoCircle style={{ width: 12 }} />
278
- <Text size="xs">
279
- {notIncludedRelations} relationship{notIncludedRelations > 1 ? 's are' : ' is'} hidden
280
- </Text>
281
- </Group>
282
- )}
283
- </Box>
284
- <Box>
285
- <Button
286
- size="xs"
287
- color="gray"
288
- variant="light"
289
- radius="sm"
290
- leftSection={<IconTransform stroke={1.8} style={{ width: '67%' }} />}
291
- styles={{
292
- section: {
293
- marginInline: 0
294
- }
295
- }}
296
- onClick={openRelationshipsOverlay}>
297
- Browse
298
- </Button>
299
- </Box>
300
- </Group>
301
- </Box>
302
- )}
303
- {element.links && (
304
- <Box>
305
- <Divider label="links" />
306
- <Stack gap={'xs'}>
307
- {element.links.map((link) => (
308
- <Group key={link.url} wrap="nowrap" gap={'sm'}>
309
- <Box
310
- flex={'1'}
311
- style={{ overflow: 'clip', maxWidth: clamp(element.width, { min: 200, max: 400 }) }}>
312
- <Anchor href={link.url} target="_blank" fz="13" truncate="end">
313
- {link.title || link.url}
314
- </Anchor>
315
- </Box>
316
- <CopyButton value={link.url}>
317
- {({ copied, copy }) => (
318
- <Button
319
- size="compact-xs"
320
- fz={'10'}
321
- variant="light"
322
- onClick={copy}
323
- color={copied ? 'teal' : 'gray'}
324
- >
325
- {copied ? 'copied' : 'copy'}
326
- </Button>
327
- )}
328
- </CopyButton>
329
- </Group>
330
- ))}
331
- </Stack>
332
- </Box>
333
- )}
334
- {otherViews.length > 0 && !!onNavigateTo && (
335
- <Box>
336
- <Divider label="views including this element" />
337
- <Stack gap={'xs'}>
338
- {otherViews.map((view) => (
339
- <ViewButton
340
- key={view.id}
341
- view={view}
342
- onNavigateTo={onNavigateToCb}
343
- />
344
- ))}
345
- </Stack>
346
- </Box>
347
- )}
348
- </Stack>
349
- </ScrollAreaAutosize>
350
- {
351
- /* <Group mt={'sm'}>
352
- <Stack gap={2}>
353
- <Button size="compact-sm" variant="light" radius="sm" color="gray" justify='start'>Base</Button>
354
- <Button size="compact-sm" variant="subtle" radius="sm" color="gray" justify='start'>Links</Button>
355
- <Button size="compact-sm" variant="subtle" radius="sm" color="gray" justify='start'>Views</Button>
356
- <Button size="compact-sm" variant="subtle" radius="sm" color="gray" justify='start'>Metadata</Button>
357
- </Stack>
358
- </Group> */
359
- }
360
- </Paper>
361
- </ViewportPortal>
362
- )
363
- })
364
-
365
- const ViewButton = ({
366
- view,
367
- onNavigateTo
368
- }: {
369
- view: ComputedView | DiagramView
370
- onNavigateTo: OnNavigateTo
371
- }) => {
372
- return (
373
- <Button
374
- className={css.viewButton}
375
- variant="subtle"
376
- radius="sm"
377
- color="gray"
378
- leftSection={<IconZoomScan stroke={1.8} />}
379
- styles={{
380
- section: {
381
- marginInline: 2,
382
- alignSelf: 'baseline'
383
- }
384
- }}
385
- justify="start"
386
- onClick={e => {
387
- onNavigateTo(view.id, e)
388
- }}>
389
- <Text component="div">{view.title || 'untitled'}</Text>
390
- <Text component="div" lh={1.2} fz={'xs'} c="dimmed">id: {view.id}</Text>
391
- </Button>
392
- )
393
- }
@@ -1,64 +0,0 @@
1
- import { useMemo, useState } from 'react'
2
- import { isEmpty, isString } from 'remeda'
3
-
4
- export function useFramerAnimateVariants() {
5
- const [variants, setVariants] = useState<string[] | null>(null)
6
-
7
- const handlers = useMemo(() => {
8
- const getTarget = (e: MouseEvent | undefined) => {
9
- try {
10
- // 🤔 Sometimes target is null
11
- return (e?.target as HTMLElement | null)?.closest('[data-animate-target]')?.getAttribute('data-animate-target')
12
- ?? null
13
- } catch (_e) {
14
- console.warn(`Failed to get animate target`, _e)
15
- // noop
16
- return null
17
- }
18
- }
19
-
20
- const onHoverStart = (e: MouseEvent) => {
21
- e?.stopPropagation()
22
- const hoverTarget = getTarget(e)
23
- if (!isString(hoverTarget) || isEmpty(hoverTarget)) {
24
- setVariants(null)
25
- return
26
- }
27
- setVariants(['hovered', `hovered:${hoverTarget}`])
28
- }
29
-
30
- const resetVariants = (e: MouseEvent) => {
31
- e?.stopPropagation()
32
- setVariants(null)
33
- }
34
-
35
- return ({
36
- onTapStart: (e: MouseEvent) => {
37
- e?.stopPropagation()
38
- const tapTarget = getTarget(e)
39
- if (!isString(tapTarget)) {
40
- setVariants(null)
41
- return
42
- }
43
- if (isEmpty(tapTarget)) {
44
- setVariants([
45
- 'hovered',
46
- 'tap'
47
- ])
48
- } else {
49
- setVariants([
50
- 'hovered',
51
- `hovered:${tapTarget}`,
52
- `tap:${tapTarget}`
53
- ])
54
- }
55
- },
56
- onHoverStart,
57
- onHoverEnd: resetVariants,
58
- onTapCancel: resetVariants,
59
- onTap: onHoverStart
60
- })
61
- }, [setVariants])
62
-
63
- return [variants, handlers] as const
64
- }