@likec4/diagram 1.19.1 → 1.20.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 (582) hide show
  1. package/dist/LikeC4Diagram.css.d.ts +0 -1
  2. package/dist/LikeC4Diagram.css.js +1 -5
  3. package/dist/LikeC4Diagram.d.ts +1 -4
  4. package/dist/LikeC4Diagram.js +102 -147
  5. package/dist/LikeC4Diagram.props.d.ts +10 -16
  6. package/dist/LikeC4Search.js +7 -15
  7. package/dist/StaticLikeC4Diagram.d.ts +1 -1
  8. package/dist/base/Background.d.ts +7 -0
  9. package/dist/{xyflow/XYFlowBackground.js → base/Background.js} +5 -6
  10. package/dist/base/BaseXYFlow.d.ts +14 -0
  11. package/dist/base/BaseXYFlow.js +146 -0
  12. package/dist/base/example/RelationshipsBrowser.d.ts +6 -0
  13. package/dist/base/example/_types.d.ts +20 -0
  14. package/dist/base/example/custom.d.ts +71 -0
  15. package/dist/base/example/useViewToNodesEdges.d.ts +6 -0
  16. package/dist/base/index.d.ts +2 -0
  17. package/dist/base/primitives/NodeHandles.d.ts +4 -0
  18. package/dist/base/primitives/NodeHandles.js +14 -0
  19. package/dist/base/primitives/compound/CompoundActionButton.css.d.ts +3 -0
  20. package/dist/base/primitives/compound/CompoundActionButton.css.js +9 -0
  21. package/dist/base/primitives/compound/CompoundActionButton.d.ts +7 -0
  22. package/dist/base/primitives/compound/CompoundActionButton.js +48 -0
  23. package/dist/base/primitives/compound/CompoundDetailsButton.css.d.ts +3 -0
  24. package/dist/base/primitives/compound/CompoundDetailsButton.css.js +9 -0
  25. package/dist/base/primitives/compound/CompoundDetailsButton.d.ts +7 -0
  26. package/dist/base/primitives/compound/CompoundDetailsButton.js +50 -0
  27. package/dist/base/primitives/compound/CompoundNodeContainer.css.d.ts +9 -0
  28. package/dist/base/primitives/compound/CompoundNodeContainer.css.js +17 -0
  29. package/dist/base/primitives/compound/CompoundNodeContainer.d.ts +26 -0
  30. package/dist/base/primitives/compound/CompoundNodeContainer.js +86 -0
  31. package/dist/base/primitives/compound/CompoundTitle.css.d.ts +2 -0
  32. package/dist/base/primitives/compound/CompoundTitle.css.js +7 -0
  33. package/dist/base/primitives/compound/CompoundTitle.d.ts +6 -0
  34. package/dist/base/primitives/compound/CompoundTitle.js +20 -0
  35. package/dist/base/primitives/customEdge.d.ts +41 -0
  36. package/dist/base/primitives/customEdge.js +13 -0
  37. package/dist/base/primitives/customNode.d.ts +7 -0
  38. package/dist/base/primitives/customNode.js +10 -0
  39. package/dist/base/primitives/edge/EdgeActionButton.d.ts +7 -0
  40. package/dist/base/primitives/edge/EdgeActionButton.js +24 -0
  41. package/dist/base/primitives/edge/EdgeContainer.d.ts +10 -0
  42. package/dist/base/primitives/edge/EdgeContainer.js +35 -0
  43. package/dist/{xyflow/edges/edges.css.d.ts → base/primitives/edge/EdgeLabel.css.d.ts} +5 -9
  44. package/dist/base/primitives/edge/EdgeLabel.css.js +25 -0
  45. package/dist/base/primitives/edge/EdgeLabel.d.ts +51 -0
  46. package/dist/base/primitives/edge/EdgeLabel.js +90 -0
  47. package/dist/{xyflow → base/primitives/edge}/EdgeMarkers.d.ts +2 -0
  48. package/dist/{xyflow → base/primitives/edge}/EdgeMarkers.js +29 -1
  49. package/dist/base/primitives/edge/EdgePath.d.ts +44 -0
  50. package/dist/base/primitives/edge/EdgePath.js +77 -0
  51. package/dist/base/primitives/edge/edge.css.d.ts +6 -0
  52. package/dist/base/primitives/edge/edge.css.js +14 -0
  53. package/dist/base/primitives/element/ElementActionButtons.css.d.ts +3 -0
  54. package/dist/base/primitives/element/ElementActionButtons.css.js +9 -0
  55. package/dist/base/primitives/element/ElementActionButtons.d.ts +13 -0
  56. package/dist/base/primitives/element/ElementActionButtons.js +62 -0
  57. package/dist/base/primitives/element/ElementDetailsButton.css.d.ts +3 -0
  58. package/dist/base/primitives/element/ElementDetailsButton.css.js +9 -0
  59. package/dist/base/primitives/element/ElementDetailsButton.d.ts +7 -0
  60. package/dist/base/primitives/element/ElementDetailsButton.js +54 -0
  61. package/dist/base/primitives/element/ElementNodeContainer.css.d.ts +3 -0
  62. package/dist/base/primitives/element/ElementNodeContainer.css.js +7 -0
  63. package/dist/base/primitives/element/ElementNodeContainer.d.ts +26 -0
  64. package/dist/base/primitives/element/ElementNodeContainer.js +60 -0
  65. package/dist/base/primitives/element/ElementShape.css.d.ts +6 -0
  66. package/dist/base/primitives/element/ElementShape.css.js +14 -0
  67. package/dist/base/primitives/element/ElementShape.d.ts +28 -0
  68. package/dist/{xyflow/nodes/element/ElementShapeSvg.js → base/primitives/element/ElementShape.js} +23 -7
  69. package/dist/base/primitives/element/ElementTitle.css.d.ts +8 -0
  70. package/dist/base/primitives/element/ElementTitle.css.js +19 -0
  71. package/dist/base/primitives/element/ElementTitle.d.ts +10 -0
  72. package/dist/base/primitives/element/ElementTitle.js +66 -0
  73. package/dist/base/primitives/index.d.ts +17 -0
  74. package/dist/base/types.d.ts +90 -0
  75. package/dist/base/types.js +54 -0
  76. package/dist/base/updateEdges.d.ts +3 -0
  77. package/dist/base/updateEdges.js +31 -0
  78. package/dist/base/updateNodes.d.ts +3 -0
  79. package/dist/base/updateNodes.js +36 -0
  80. package/dist/base/xyflowMachine.d.ts +212 -0
  81. package/dist/context/DiagramEventHandlers.d.ts +10 -0
  82. package/dist/context/DiagramEventHandlers.js +49 -0
  83. package/dist/context/DiagramFeatures.d.ts +31 -0
  84. package/dist/context/DiagramFeatures.js +140 -0
  85. package/dist/{ui → context}/FramerMotionConfig.js +2 -4
  86. package/dist/context/IconRenderer.d.ts +11 -0
  87. package/dist/{xyflow/nodes/shared/ElementIcon.js → context/IconRenderer.js} +14 -14
  88. package/dist/context/RootContainer.d.ts +9 -0
  89. package/dist/context/RootContainer.js +20 -0
  90. package/dist/context/index.d.ts +7 -0
  91. package/dist/globals.css.js +0 -87
  92. package/dist/hooks/index.d.ts +7 -5
  93. package/dist/hooks/useCurrentViewId.d.ts +2 -0
  94. package/dist/hooks/useCurrentViewId.js +8 -0
  95. package/dist/hooks/useDiagram.d.ts +10725 -0
  96. package/dist/hooks/useDiagram.js +119 -0
  97. package/dist/hooks/useDiagramActor.d.ts +5 -0
  98. package/dist/hooks/useDiagramActor.js +21 -0
  99. package/dist/hooks/useDiagramContext.d.ts +3 -0
  100. package/dist/hooks/useDiagramContext.js +10 -0
  101. package/dist/hooks/useMantinePortalProps.js +2 -2
  102. package/dist/hooks/useXYFlow.d.ts +195 -37
  103. package/dist/hooks/useXYFlow.js +4 -6
  104. package/dist/index.d.ts +3 -2
  105. package/dist/index.js +5 -6
  106. package/dist/likec4diagram/DiagramActor.d.ts +7 -0
  107. package/dist/likec4diagram/DiagramActor.js +71 -0
  108. package/dist/likec4diagram/DiagramUI.d.ts +2 -0
  109. package/dist/likec4diagram/DiagramUI.js +22 -0
  110. package/dist/likec4diagram/XYFlow.d.ts +6 -0
  111. package/dist/likec4diagram/XYFlow.js +122 -0
  112. package/dist/likec4diagram/custom/edges/NotePopover.css.d.ts +2 -0
  113. package/dist/likec4diagram/custom/edges/NotePopover.css.js +7 -0
  114. package/dist/likec4diagram/custom/edges/NotePopover.d.ts +4 -0
  115. package/dist/likec4diagram/custom/edges/NotePopover.js +101 -0
  116. package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +55 -0
  117. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +307 -0
  118. package/dist/{xyflow → likec4diagram/custom}/edges/RelationshipsDropdownMenu.css.js +4 -4
  119. package/dist/{xyflow → likec4diagram/custom}/edges/RelationshipsDropdownMenu.d.ts +5 -5
  120. package/dist/{xyflow → likec4diagram/custom}/edges/RelationshipsDropdownMenu.js +51 -53
  121. package/dist/likec4diagram/custom/edges/edges.css.d.ts +2 -0
  122. package/dist/likec4diagram/custom/edges/edges.css.js +7 -0
  123. package/dist/likec4diagram/custom/edges/utils.d.ts +22 -0
  124. package/dist/likec4diagram/custom/edges/utils.js +25 -0
  125. package/dist/likec4diagram/custom/index.d.ts +57 -0
  126. package/dist/likec4diagram/custom/index.js +7 -0
  127. package/dist/likec4diagram/custom/nodes/CompoundActions.d.ts +5 -0
  128. package/dist/likec4diagram/custom/nodes/CompoundActions.js +25 -0
  129. package/dist/likec4diagram/custom/nodes/ElementActions.d.ts +7 -0
  130. package/dist/likec4diagram/custom/nodes/ElementActions.js +69 -0
  131. package/dist/likec4diagram/custom/nodes/nodeTypes.d.ts +10 -0
  132. package/dist/likec4diagram/custom/nodes/nodeTypes.js +94 -0
  133. package/dist/likec4diagram/custom/nodes/toolbar/ColorButton.d.ts +21 -0
  134. package/dist/likec4diagram/custom/nodes/toolbar/ColorButton.js +159 -0
  135. package/dist/likec4diagram/custom/nodes/toolbar/CompoundToolbar.d.ts +7 -0
  136. package/dist/likec4diagram/custom/nodes/toolbar/CompoundToolbar.js +128 -0
  137. package/dist/likec4diagram/custom/nodes/toolbar/ElementToolbar.d.ts +7 -0
  138. package/dist/likec4diagram/custom/nodes/toolbar/ElementToolbar.js +149 -0
  139. package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.d.ts +8 -0
  140. package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.js +66 -0
  141. package/dist/likec4diagram/custom/nodes/toolbar/_shared.d.ts +40 -0
  142. package/dist/likec4diagram/custom/nodes/toolbar/_shared.js +131 -0
  143. package/dist/likec4diagram/custom/nodes/toolbar/styles.css.d.ts +1 -0
  144. package/dist/likec4diagram/custom/nodes/toolbar/styles.css.js +5 -0
  145. package/dist/likec4diagram/state/actorContext.d.ts +50849 -0
  146. package/dist/likec4diagram/state/actorContext.js +12 -0
  147. package/dist/{state → likec4diagram/state}/aligners.d.ts +4 -1
  148. package/dist/{state → likec4diagram/state}/aligners.js +31 -5
  149. package/dist/likec4diagram/state/assign.d.ts +18 -0
  150. package/dist/likec4diagram/state/assign.js +343 -0
  151. package/dist/likec4diagram/state/hotkeyActor.d.ts +5 -0
  152. package/dist/likec4diagram/state/hotkeyActor.js +18 -0
  153. package/dist/likec4diagram/state/inspector.d.ts +5 -0
  154. package/dist/likec4diagram/state/machine.d.ts +10751 -0
  155. package/dist/likec4diagram/state/machine.js +783 -0
  156. package/dist/likec4diagram/state/syncManualLayoutActor.d.ts +113 -0
  157. package/dist/likec4diagram/state/syncManualLayoutActor.js +178 -0
  158. package/dist/likec4diagram/state/utils.d.ts +8 -0
  159. package/dist/likec4diagram/state/utils.js +48 -0
  160. package/dist/likec4diagram/types.d.ts +74 -0
  161. package/dist/{ui/top-left → likec4diagram/ui/controls}/ChangeAutoLayoutButton.js +11 -10
  162. package/dist/likec4diagram/ui/controls/Controls.d.ts +2 -0
  163. package/dist/likec4diagram/ui/controls/Controls.js +102 -0
  164. package/dist/likec4diagram/ui/controls/LayoutDriftNotification.d.ts +2 -0
  165. package/dist/likec4diagram/ui/controls/LayoutDriftNotification.js +43 -0
  166. package/dist/{ui/top-left → likec4diagram/ui/controls}/ManualLayoutToolsButton.js +11 -11
  167. package/dist/likec4diagram/ui/controls/NavigationButtons.d.ts +1 -0
  168. package/dist/likec4diagram/ui/controls/NavigationButtons.js +92 -0
  169. package/dist/{ui/top-left → likec4diagram/ui/controls}/_shared.js +2 -1
  170. package/dist/{ui/top-left → likec4diagram/ui/controls}/styles.css.d.ts +1 -1
  171. package/dist/likec4diagram/ui/controls/styles.css.js +17 -0
  172. package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.css.js +11 -0
  173. package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.d.ts +1 -0
  174. package/dist/{ui → likec4diagram/ui/diagram-title}/DiagramTitlePanel.js +3 -3
  175. package/dist/likec4diagram/ui/diagram-title/Link.d.ts +4 -0
  176. package/dist/likec4diagram/ui/index.d.ts +2 -0
  177. package/dist/likec4diagram/ui/notation/NotationPanel.css.js +13 -0
  178. package/dist/likec4diagram/ui/notation/NotationPanel.d.ts +2 -0
  179. package/dist/{ui → likec4diagram/ui}/notation/NotationPanel.js +23 -31
  180. package/dist/{ui → likec4diagram/ui/walkthrough}/DynamicViewWalkthrough.css.js +4 -4
  181. package/dist/{ui → likec4diagram/ui/walkthrough}/DynamicViewWalkthrough.js +19 -44
  182. package/dist/{xyflow → likec4diagram}/useLayoutConstraints.d.ts +11 -6
  183. package/dist/{xyflow → likec4diagram}/useLayoutConstraints.js +17 -12
  184. package/dist/likec4diagram/useViewToNodesEdges.d.ts +11 -0
  185. package/dist/likec4diagram/useViewToNodesEdges.js +245 -0
  186. package/dist/likec4model/index.d.ts +1 -1
  187. package/dist/likec4model/useLikeC4Model.d.ts +1 -11
  188. package/dist/likec4model/useLikeC4Model.js +1 -39
  189. package/dist/overlays/Overlays.js +61 -105
  190. package/dist/overlays/element-details/ElementDetailsCard.js +111 -116
  191. package/dist/overlays/element-details/TabPanelDeployments.js +4 -7
  192. package/dist/overlays/element-details/TabPanelRelationships.css.js +0 -2
  193. package/dist/overlays/element-details/TabPanelRelationships.d.ts +1 -1
  194. package/dist/overlays/element-details/TabPanelRelationships.js +35 -64
  195. package/dist/overlays/element-details/TabPanelStructure.d.ts +2 -2
  196. package/dist/overlays/element-details/TabPanelStructure.js +1 -1
  197. package/dist/overlays/overlay/Overlay.css.d.ts +2 -0
  198. package/dist/overlays/overlay/Overlay.css.js +93 -0
  199. package/dist/overlays/overlay/Overlay.d.ts +8 -0
  200. package/dist/overlays/overlay/Overlay.js +86 -0
  201. package/dist/overlays/relationship-details/RelationshipDetails.d.ts +5 -0
  202. package/dist/overlays/relationship-details/RelationshipDetails.js +189 -0
  203. package/dist/overlays/{edge-details → relationship-details}/SelectEdge.css.d.ts +1 -0
  204. package/dist/overlays/relationship-details/SelectEdge.css.js +17 -0
  205. package/dist/overlays/{edge-details → relationship-details}/SelectEdge.d.ts +1 -1
  206. package/dist/overlays/{edge-details → relationship-details}/SelectEdge.js +8 -8
  207. package/dist/overlays/relationship-details/_types.d.ts +36 -0
  208. package/dist/overlays/relationship-details/actor.d.ts +41 -0
  209. package/dist/overlays/relationship-details/actor.js +113 -0
  210. package/dist/overlays/relationship-details/custom/ElementActions.d.ts +5 -0
  211. package/dist/overlays/relationship-details/custom/ElementActions.js +33 -0
  212. package/dist/overlays/relationship-details/custom/edgeTypes.d.ts +49 -0
  213. package/dist/overlays/relationship-details/custom/edgeTypes.js +51 -0
  214. package/dist/overlays/relationship-details/custom/index.d.ts +2 -0
  215. package/dist/overlays/relationship-details/custom/nodeTypes.d.ts +39 -0
  216. package/dist/overlays/relationship-details/custom/nodeTypes.js +89 -0
  217. package/dist/overlays/relationship-details/custom/styles.css.d.ts +1 -0
  218. package/dist/overlays/relationship-details/hooks.d.ts +59 -0
  219. package/dist/overlays/relationship-details/hooks.js +46 -0
  220. package/dist/overlays/{edge-details/use-layouted-edge-details.d.ts → relationship-details/useLayoutedDetails.d.ts} +4 -6
  221. package/dist/overlays/{edge-details/use-layouted-edge-details.js → relationship-details/useLayoutedDetails.js} +68 -64
  222. package/dist/overlays/relationships-browser/-useRelationshipsView.d.ts +39 -0
  223. package/dist/overlays/relationships-browser/-useRelationshipsView.js +488 -0
  224. package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +5 -0
  225. package/dist/overlays/relationships-browser/RelationshipsBrowser.js +209 -0
  226. package/dist/overlays/{relationships-of → relationships-browser}/SelectElement.css.d.ts +1 -0
  227. package/dist/overlays/relationships-browser/SelectElement.css.js +9 -0
  228. package/dist/overlays/relationships-browser/SelectElement.d.ts +7 -0
  229. package/dist/overlays/{relationships-of → relationships-browser}/SelectElement.js +11 -7
  230. package/dist/overlays/relationships-browser/_types.d.ts +40 -0
  231. package/dist/overlays/relationships-browser/actor.d.ts +66 -0
  232. package/dist/overlays/relationships-browser/actor.js +159 -0
  233. package/dist/overlays/relationships-browser/custom/ElementActions.d.ts +5 -0
  234. package/dist/overlays/relationships-browser/custom/ElementActions.js +43 -0
  235. package/dist/overlays/relationships-browser/custom/EmptyNode.d.ts +5 -0
  236. package/dist/overlays/{relationships-of/xyflow → relationships-browser/custom}/EmptyNode.js +1 -3
  237. package/dist/overlays/relationships-browser/custom/edgeTypes.d.ts +46 -0
  238. package/dist/overlays/relationships-browser/custom/edgeTypes.js +51 -0
  239. package/dist/overlays/relationships-browser/custom/index.d.ts +2 -0
  240. package/dist/overlays/relationships-browser/custom/nodeTypes.d.ts +45 -0
  241. package/dist/overlays/relationships-browser/custom/nodeTypes.js +93 -0
  242. package/dist/overlays/relationships-browser/custom/styles.css.d.ts +1 -0
  243. package/dist/overlays/relationships-browser/custom/styles.css.js +5 -0
  244. package/dist/overlays/relationships-browser/hooks.d.ts +62 -0
  245. package/dist/overlays/relationships-browser/hooks.js +46 -0
  246. package/dist/overlays/relationships-browser/useViewToNodesEdges.d.ts +10 -0
  247. package/dist/overlays/relationships-browser/useViewToNodesEdges.js +160 -0
  248. package/dist/style.css +1 -1
  249. package/dist/theme-vars.css.js +1 -0
  250. package/dist/utils/index.d.ts +4 -0
  251. package/dist/{xyflow/utils.d.ts → utils/xyflow.d.ts} +4 -4
  252. package/dist/{xyflow/utils.js → utils/xyflow.js} +14 -20
  253. package/package.json +24 -21
  254. package/src/LikeC4Diagram.css.ts +21 -15
  255. package/src/LikeC4Diagram.props.ts +14 -21
  256. package/src/LikeC4Diagram.tsx +105 -150
  257. package/src/LikeC4Search.tsx +21 -28
  258. package/src/StaticLikeC4Diagram.tsx +0 -1
  259. package/src/{xyflow/XYFlowBackground.tsx → base/Background.tsx} +8 -8
  260. package/src/base/BaseXYFlow.tsx +200 -0
  261. package/src/{xyflow → base}/const.ts +1 -1
  262. package/src/base/example/RelationshipsBrowser.tsx +62 -0
  263. package/src/base/example/_types.ts +71 -0
  264. package/src/base/example/custom.tsx +58 -0
  265. package/src/base/example/useViewToNodesEdges.ts +193 -0
  266. package/src/base/index.ts +10 -0
  267. package/src/base/primitives/NodeHandles.tsx +18 -0
  268. package/src/base/primitives/compound/CompoundActionButton.css.ts +55 -0
  269. package/src/base/primitives/compound/CompoundActionButton.tsx +52 -0
  270. package/src/base/primitives/compound/CompoundDetailsButton.css.ts +56 -0
  271. package/src/base/primitives/compound/CompoundDetailsButton.tsx +54 -0
  272. package/src/base/primitives/compound/CompoundNodeContainer.css.ts +161 -0
  273. package/src/base/primitives/compound/CompoundNodeContainer.tsx +95 -0
  274. package/src/base/primitives/compound/CompoundTitle.css.ts +43 -0
  275. package/src/base/primitives/compound/CompoundTitle.tsx +29 -0
  276. package/src/base/primitives/customEdge.ts +32 -0
  277. package/src/base/primitives/customNode.ts +21 -0
  278. package/src/base/primitives/edge/EdgeActionButton.tsx +27 -0
  279. package/src/base/primitives/edge/EdgeContainer.tsx +48 -0
  280. package/src/base/primitives/edge/EdgeLabel.css.ts +196 -0
  281. package/src/base/primitives/edge/EdgeLabel.tsx +136 -0
  282. package/src/{xyflow → base/primitives/edge}/EdgeMarkers.tsx +29 -1
  283. package/src/base/primitives/edge/EdgePath.tsx +89 -0
  284. package/src/base/primitives/edge/edge.css.ts +122 -0
  285. package/src/base/primitives/element/ElementActionButtons.css.ts +48 -0
  286. package/src/base/primitives/element/ElementActionButtons.tsx +73 -0
  287. package/src/base/primitives/element/ElementDetailsButton.css.ts +54 -0
  288. package/src/base/primitives/element/ElementDetailsButton.tsx +59 -0
  289. package/src/base/primitives/element/ElementNodeContainer.css.ts +47 -0
  290. package/src/base/primitives/element/ElementNodeContainer.tsx +72 -0
  291. package/src/base/primitives/element/ElementShape.css.ts +134 -0
  292. package/src/{xyflow/nodes/element/ElementShapeSvg.tsx → base/primitives/element/ElementShape.tsx} +64 -19
  293. package/src/base/primitives/element/ElementTitle.css.ts +156 -0
  294. package/src/base/primitives/element/ElementTitle.tsx +76 -0
  295. package/src/base/primitives/index.ts +17 -0
  296. package/src/base/types.ts +169 -0
  297. package/src/base/updateEdges.ts +40 -0
  298. package/src/base/updateNodes.ts +46 -0
  299. package/src/base/xyflowMachine.ts +75 -0
  300. package/src/context/DiagramEventHandlers.tsx +53 -0
  301. package/src/context/DiagramFeatures.tsx +162 -0
  302. package/src/{ui → context}/FramerMotionConfig.tsx +2 -6
  303. package/src/context/IconRenderer.tsx +45 -0
  304. package/src/context/RootContainer.tsx +31 -0
  305. package/src/context/index.ts +14 -0
  306. package/src/globals.css.ts +32 -32
  307. package/src/hooks/index.ts +7 -5
  308. package/src/hooks/useCurrentViewId.ts +8 -0
  309. package/src/hooks/useDiagram.ts +129 -0
  310. package/src/hooks/useDiagramActor.ts +25 -0
  311. package/src/hooks/useDiagramContext.ts +11 -0
  312. package/src/hooks/useMantinePortalProps.ts +2 -2
  313. package/src/hooks/useXYFlow.ts +12 -38
  314. package/src/index.ts +3 -7
  315. package/src/likec4diagram/DiagramActor.tsx +79 -0
  316. package/src/likec4diagram/DiagramUI.tsx +28 -0
  317. package/src/likec4diagram/XYFlow.tsx +137 -0
  318. package/src/likec4diagram/custom/edges/NotePopover.css.ts +27 -0
  319. package/src/likec4diagram/custom/edges/NotePopover.tsx +96 -0
  320. package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +355 -0
  321. package/src/{xyflow → likec4diagram/custom}/edges/RelationshipsDropdownMenu.css.ts +7 -7
  322. package/src/{xyflow → likec4diagram/custom}/edges/RelationshipsDropdownMenu.tsx +91 -70
  323. package/src/likec4diagram/custom/edges/edges.css.ts +39 -0
  324. package/src/likec4diagram/custom/edges/utils.ts +126 -0
  325. package/src/likec4diagram/custom/index.tsx +8 -0
  326. package/src/likec4diagram/custom/nodes/CompoundActions.tsx +27 -0
  327. package/src/likec4diagram/custom/nodes/ElementActions.tsx +74 -0
  328. package/src/likec4diagram/custom/nodes/nodeTypes.tsx +107 -0
  329. package/src/likec4diagram/custom/nodes/toolbar/ColorButton.tsx +175 -0
  330. package/src/likec4diagram/custom/nodes/toolbar/CompoundToolbar.tsx +122 -0
  331. package/src/likec4diagram/custom/nodes/toolbar/ElementToolbar.tsx +140 -0
  332. package/src/likec4diagram/custom/nodes/toolbar/Toolbar.tsx +77 -0
  333. package/src/likec4diagram/custom/nodes/toolbar/_shared.tsx +143 -0
  334. package/src/likec4diagram/custom/nodes/toolbar/styles.css.ts +9 -0
  335. package/src/likec4diagram/state/actorContext.ts +8 -0
  336. package/src/{state → likec4diagram/state}/aligners.ts +67 -40
  337. package/src/likec4diagram/state/assign.ts +384 -0
  338. package/src/likec4diagram/state/hotkeyActor.ts +20 -0
  339. package/src/likec4diagram/state/inspector.ts +23 -0
  340. package/src/likec4diagram/state/machine.ts +946 -0
  341. package/src/likec4diagram/state/syncManualLayoutActor.ts +219 -0
  342. package/src/likec4diagram/state/utils.ts +52 -0
  343. package/src/likec4diagram/types.ts +144 -0
  344. package/src/{ui/top-left → likec4diagram/ui/controls}/ChangeAutoLayoutButton.tsx +32 -28
  345. package/src/likec4diagram/ui/controls/Controls.tsx +107 -0
  346. package/src/likec4diagram/ui/controls/LayoutDriftNotification.tsx +46 -0
  347. package/src/{ui/top-left → likec4diagram/ui/controls}/ManualLayoutToolsButton.tsx +16 -16
  348. package/src/likec4diagram/ui/controls/NavigationButtons.tsx +83 -0
  349. package/src/{ui/top-left → likec4diagram/ui/controls}/_shared.ts +4 -3
  350. package/src/{ui/top-left → likec4diagram/ui/controls}/styles.css.ts +17 -17
  351. package/src/{ui → likec4diagram/ui/diagram-title}/DiagramTitlePanel.css.ts +11 -11
  352. package/src/{ui → likec4diagram/ui/diagram-title}/DiagramTitlePanel.tsx +6 -5
  353. package/src/likec4diagram/ui/diagram-title/Link.tsx +40 -0
  354. package/src/likec4diagram/ui/index.ts +2 -0
  355. package/src/{ui → likec4diagram/ui}/notation/NotationPanel.css.ts +18 -18
  356. package/src/{ui → likec4diagram/ui}/notation/NotationPanel.tsx +44 -44
  357. package/src/{ui → likec4diagram/ui/walkthrough}/DynamicViewWalkthrough.css.ts +16 -16
  358. package/src/{ui → likec4diagram/ui/walkthrough}/DynamicViewWalkthrough.tsx +29 -49
  359. package/src/{xyflow → likec4diagram}/useLayoutConstraints.ts +54 -43
  360. package/src/likec4diagram/useViewToNodesEdges.ts +297 -0
  361. package/src/likec4model/index.ts +0 -6
  362. package/src/likec4model/useLikeC4Model.ts +1 -43
  363. package/src/overlays/Overlays.tsx +201 -147
  364. package/src/overlays/element-details/ElementDetailsCard.css.ts +58 -58
  365. package/src/overlays/element-details/ElementDetailsCard.tsx +143 -128
  366. package/src/overlays/element-details/TabPanelDeployments.css.ts +14 -14
  367. package/src/overlays/element-details/TabPanelDeployments.tsx +22 -22
  368. package/src/overlays/element-details/TabPanelRelationships.css.ts +19 -19
  369. package/src/overlays/element-details/TabPanelRelationships.tsx +45 -28
  370. package/src/overlays/element-details/TabPanelStructure.css.ts +7 -7
  371. package/src/overlays/element-details/TabPanelStructure.tsx +11 -11
  372. package/src/overlays/overlay/Overlay.css.ts +73 -0
  373. package/src/overlays/overlay/Overlay.tsx +99 -0
  374. package/src/overlays/relationship-details/RelationshipDetails.tsx +234 -0
  375. package/src/overlays/{edge-details → relationship-details}/SelectEdge.css.ts +20 -13
  376. package/src/overlays/{edge-details → relationship-details}/SelectEdge.tsx +14 -14
  377. package/src/overlays/relationship-details/_types.ts +73 -0
  378. package/src/overlays/relationship-details/actor.ts +162 -0
  379. package/src/overlays/relationship-details/custom/ElementActions.tsx +45 -0
  380. package/src/overlays/relationship-details/custom/edgeTypes.tsx +49 -0
  381. package/src/overlays/relationship-details/custom/index.tsx +2 -0
  382. package/src/overlays/relationship-details/custom/nodeTypes.tsx +108 -0
  383. package/src/overlays/relationship-details/custom/styles.css.ts +13 -0
  384. package/src/overlays/relationship-details/hooks.ts +48 -0
  385. package/src/overlays/{edge-details/use-layouted-edge-details.ts → relationship-details/useLayoutedDetails.ts} +128 -114
  386. package/src/overlays/relationships-browser/-useRelationshipsView.ts +642 -0
  387. package/src/overlays/relationships-browser/RelationshipsBrowser.tsx +247 -0
  388. package/src/overlays/{relationships-of → relationships-browser}/SelectElement.css.ts +12 -5
  389. package/src/overlays/{relationships-of → relationships-browser}/SelectElement.tsx +19 -17
  390. package/src/overlays/relationships-browser/_types.ts +89 -0
  391. package/src/overlays/relationships-browser/actor.ts +224 -0
  392. package/src/overlays/relationships-browser/custom/ElementActions.tsx +44 -0
  393. package/src/overlays/relationships-browser/custom/EmptyNode.tsx +18 -0
  394. package/src/overlays/relationships-browser/custom/edgeTypes.tsx +49 -0
  395. package/src/overlays/relationships-browser/custom/index.tsx +2 -0
  396. package/src/overlays/relationships-browser/custom/nodeTypes.tsx +109 -0
  397. package/src/overlays/relationships-browser/custom/styles.css.ts +13 -0
  398. package/src/overlays/relationships-browser/hooks.ts +48 -0
  399. package/src/overlays/relationships-browser/useViewToNodesEdges.ts +209 -0
  400. package/src/utils/index.ts +15 -0
  401. package/src/{xyflow/utils.ts → utils/xyflow.ts} +22 -8
  402. package/dist/_virtual/_commonjsHelpers.js +0 -6
  403. package/dist/controls/Text.d.ts +0 -2
  404. package/dist/controls/Text.js +0 -7
  405. package/dist/controls/action-button-bar/ActionButtonBar.css.d.ts +0 -1
  406. package/dist/controls/action-button-bar/ActionButtonBar.css.js +0 -5
  407. package/dist/controls/action-button-bar/ActionButtonBar.d.ts +0 -9
  408. package/dist/controls/action-button-bar/ActionButtonBar.js +0 -100
  409. package/dist/controls/action-button-bar/useActionButtonBarCtx.d.ts +0 -10
  410. package/dist/controls/action-button-bar/useActionButtonBarCtx.js +0 -9
  411. package/dist/controls/action-buttons/ActionButton.css.d.ts +0 -1
  412. package/dist/controls/action-buttons/ActionButton.css.js +0 -5
  413. package/dist/controls/action-buttons/ActionButton.d.ts +0 -9
  414. package/dist/controls/action-buttons/ActionButton.js +0 -66
  415. package/dist/controls/action-buttons/ActionButtons.d.ts +0 -12
  416. package/dist/controls/action-buttons/ActionButtons.js +0 -99
  417. package/dist/hooks/useDiagramState.d.ts +0 -6
  418. package/dist/hooks/useDiagramState.js +0 -27
  419. package/dist/overlays/OverlayContext.d.ts +0 -10
  420. package/dist/overlays/OverlayContext.js +0 -9
  421. package/dist/overlays/Overlays.css.d.ts +0 -3
  422. package/dist/overlays/Overlays.css.js +0 -7
  423. package/dist/overlays/edge-details/EdgeDetailsXYFlow.d.ts +0 -5
  424. package/dist/overlays/edge-details/EdgeDetailsXYFlow.js +0 -185
  425. package/dist/overlays/edge-details/SelectEdge.css.js +0 -17
  426. package/dist/overlays/edge-details/_types.d.ts +0 -14
  427. package/dist/overlays/edge-details/xyflow/CompoundNode.d.ts +0 -5
  428. package/dist/overlays/edge-details/xyflow/CompoundNode.js +0 -76
  429. package/dist/overlays/edge-details/xyflow/ElementNode.d.ts +0 -5
  430. package/dist/overlays/edge-details/xyflow/ElementNode.js +0 -159
  431. package/dist/overlays/edge-details/xyflow/RelationshipEdge.d.ts +0 -3
  432. package/dist/overlays/edge-details/xyflow/RelationshipEdge.js +0 -84
  433. package/dist/overlays/edge-details/xyflow/styles.css.d.ts +0 -9
  434. package/dist/overlays/edge-details/xyflow/styles.css.js +0 -21
  435. package/dist/overlays/index.d.ts +0 -1
  436. package/dist/overlays/relationships-of/RelationshipsOverlay.d.ts +0 -5
  437. package/dist/overlays/relationships-of/RelationshipsOverlay.js +0 -193
  438. package/dist/overlays/relationships-of/RelationshipsXYFlow.d.ts +0 -19
  439. package/dist/overlays/relationships-of/RelationshipsXYFlow.js +0 -290
  440. package/dist/overlays/relationships-of/SelectElement.css.js +0 -7
  441. package/dist/overlays/relationships-of/SelectElement.d.ts +0 -7
  442. package/dist/overlays/relationships-of/_types.d.ts +0 -28
  443. package/dist/overlays/relationships-of/use-layouted-relationships.d.ts +0 -22
  444. package/dist/overlays/relationships-of/use-layouted-relationships.js +0 -496
  445. package/dist/overlays/relationships-of/xyflow/CompoundNode.d.ts +0 -6
  446. package/dist/overlays/relationships-of/xyflow/CompoundNode.js +0 -120
  447. package/dist/overlays/relationships-of/xyflow/ElementNode.d.ts +0 -6
  448. package/dist/overlays/relationships-of/xyflow/ElementNode.js +0 -194
  449. package/dist/overlays/relationships-of/xyflow/EmptyNode.d.ts +0 -5
  450. package/dist/overlays/relationships-of/xyflow/RelationshipEdge.d.ts +0 -3
  451. package/dist/overlays/relationships-of/xyflow/RelationshipEdge.js +0 -123
  452. package/dist/overlays/relationships-of/xyflow/styles.css.d.ts +0 -14
  453. package/dist/overlays/relationships-of/xyflow/styles.css.js +0 -24
  454. package/dist/overlays/shared/xyflow/RelationshipEdge.css.d.ts +0 -4
  455. package/dist/overlays/shared/xyflow/RelationshipEdge.css.js +0 -12
  456. package/dist/overlays/shared/xyflow/_types.d.ts +0 -77
  457. package/dist/state/DiagramContext.d.ts +0 -1609
  458. package/dist/state/DiagramContext.js +0 -101
  459. package/dist/state/diagram-to-xyflow.d.ts +0 -11
  460. package/dist/state/diagram-to-xyflow.js +0 -113
  461. package/dist/state/diagramStore.d.ts +0 -1705
  462. package/dist/state/diagramStore.js +0 -808
  463. package/dist/state/diagramStore.layout.d.ts +0 -4
  464. package/dist/state/diagramStore.layout.js +0 -56
  465. package/dist/ui/DiagramTitlePanel.css.js +0 -11
  466. package/dist/ui/DiagramTitlePanel.d.ts +0 -1
  467. package/dist/ui/notation/NotationPanel.css.js +0 -16
  468. package/dist/ui/notation/NotationPanel.d.ts +0 -1
  469. package/dist/ui/top-left/TopLeftPanel.d.ts +0 -4
  470. package/dist/ui/top-left/TopLeftPanel.js +0 -211
  471. package/dist/ui/top-left/styles.css.js +0 -17
  472. package/dist/xyflow/FitviewOnDiagramChange.d.ts +0 -4
  473. package/dist/xyflow/FitviewOnDiagramChange.js +0 -72
  474. package/dist/xyflow/SelectEdgesOnNodeFocus.d.ts +0 -1
  475. package/dist/xyflow/SelectEdgesOnNodeFocus.js +0 -96
  476. package/dist/xyflow/XYFlow.d.ts +0 -8
  477. package/dist/xyflow/XYFlow.js +0 -145
  478. package/dist/xyflow/XYFlowBackground.d.ts +0 -10
  479. package/dist/xyflow/XYFlowInner.d.ts +0 -8
  480. package/dist/xyflow/XYFlowInner.js +0 -41
  481. package/dist/xyflow/edges/EdgeLabel.d.ts +0 -7
  482. package/dist/xyflow/edges/EdgeLabel.js +0 -160
  483. package/dist/xyflow/edges/RelationshipEdge.d.ts +0 -6
  484. package/dist/xyflow/edges/RelationshipEdge.js +0 -443
  485. package/dist/xyflow/edges/edges.css.js +0 -37
  486. package/dist/xyflow/edges/utils.d.ts +0 -16
  487. package/dist/xyflow/edges/utils.js +0 -24
  488. package/dist/xyflow/nodes/AnimateVariants.d.ts +0 -1313
  489. package/dist/xyflow/nodes/AnimateVariants.js +0 -123
  490. package/dist/xyflow/nodes/Node.css.d.ts +0 -3
  491. package/dist/xyflow/nodes/Node.css.js +0 -9
  492. package/dist/xyflow/nodes/compound/CompoundNode.css.d.ts +0 -14
  493. package/dist/xyflow/nodes/compound/CompoundNode.css.js +0 -27
  494. package/dist/xyflow/nodes/compound/CompoundNode.d.ts +0 -6
  495. package/dist/xyflow/nodes/compound/CompoundNode.js +0 -216
  496. package/dist/xyflow/nodes/compound/index.d.ts +0 -1
  497. package/dist/xyflow/nodes/element/ElementLink.css.d.ts +0 -3
  498. package/dist/xyflow/nodes/element/ElementLink.d.ts +0 -6
  499. package/dist/xyflow/nodes/element/ElementNode.d.ts +0 -6
  500. package/dist/xyflow/nodes/element/ElementNode.js +0 -190
  501. package/dist/xyflow/nodes/element/ElementShapeSvg.d.ts +0 -17
  502. package/dist/xyflow/nodes/element/element.css.d.ts +0 -18
  503. package/dist/xyflow/nodes/element/element.css.js +0 -31
  504. package/dist/xyflow/nodes/element/index.d.ts +0 -1
  505. package/dist/xyflow/nodes/shared/ElementIcon.d.ts +0 -8
  506. package/dist/xyflow/nodes/shared/Toolbar.d.ts +0 -9
  507. package/dist/xyflow/nodes/shared/Toolbar.js +0 -436
  508. package/dist/xyflow/types.d.ts +0 -36
  509. package/dist/xyflow/useXYFlowEvents.d.ts +0 -160
  510. package/dist/xyflow/useXYFlowEvents.js +0 -275
  511. package/src/controls/Text.ts +0 -5
  512. package/src/controls/action-button-bar/ActionButtonBar.css.ts +0 -13
  513. package/src/controls/action-button-bar/ActionButtonBar.tsx +0 -138
  514. package/src/controls/action-button-bar/useActionButtonBarCtx.ts +0 -13
  515. package/src/controls/action-buttons/ActionButton.css.ts +0 -29
  516. package/src/controls/action-buttons/ActionButton.tsx +0 -66
  517. package/src/controls/action-buttons/ActionButtons.tsx +0 -138
  518. package/src/hooks/useDiagramState.ts +0 -36
  519. package/src/overlays/OverlayContext.tsx +0 -11
  520. package/src/overlays/Overlays.css.ts +0 -136
  521. package/src/overlays/edge-details/EdgeDetailsXYFlow.tsx +0 -255
  522. package/src/overlays/edge-details/_types.ts +0 -18
  523. package/src/overlays/edge-details/xyflow/CompoundNode.tsx +0 -72
  524. package/src/overlays/edge-details/xyflow/ElementNode.tsx +0 -152
  525. package/src/overlays/edge-details/xyflow/RelationshipEdge.tsx +0 -85
  526. package/src/overlays/edge-details/xyflow/styles.css.ts +0 -144
  527. package/src/overlays/index.tsx +0 -1
  528. package/src/overlays/relationships-of/RelationshipsOverlay.tsx +0 -185
  529. package/src/overlays/relationships-of/RelationshipsXYFlow.tsx +0 -378
  530. package/src/overlays/relationships-of/_types.ts +0 -40
  531. package/src/overlays/relationships-of/use-layouted-relationships.ts +0 -699
  532. package/src/overlays/relationships-of/xyflow/CompoundNode.tsx +0 -124
  533. package/src/overlays/relationships-of/xyflow/ElementNode.tsx +0 -194
  534. package/src/overlays/relationships-of/xyflow/EmptyNode.tsx +0 -19
  535. package/src/overlays/relationships-of/xyflow/RelationshipEdge.tsx +0 -127
  536. package/src/overlays/relationships-of/xyflow/styles.css.ts +0 -214
  537. package/src/overlays/shared/xyflow/RelationshipEdge.css.ts +0 -60
  538. package/src/overlays/shared/xyflow/_types.ts +0 -87
  539. package/src/state/DiagramContext.tsx +0 -107
  540. package/src/state/diagram-to-xyflow.ts +0 -150
  541. package/src/state/diagramStore.layout.ts +0 -66
  542. package/src/state/diagramStore.ts +0 -1099
  543. package/src/ui/top-left/TopLeftPanel.tsx +0 -220
  544. package/src/xyflow/FitviewOnDiagramChange.tsx +0 -83
  545. package/src/xyflow/SelectEdgesOnNodeFocus.tsx +0 -106
  546. package/src/xyflow/XYFlow.tsx +0 -179
  547. package/src/xyflow/XYFlowInner.tsx +0 -48
  548. package/src/xyflow/edges/EdgeLabel.tsx +0 -193
  549. package/src/xyflow/edges/RelationshipEdge.tsx +0 -547
  550. package/src/xyflow/edges/edges.css.ts +0 -288
  551. package/src/xyflow/edges/utils.ts +0 -153
  552. package/src/xyflow/nodes/AnimateVariants.ts +0 -143
  553. package/src/xyflow/nodes/Node.css.ts +0 -44
  554. package/src/xyflow/nodes/compound/CompoundNode.css.ts +0 -258
  555. package/src/xyflow/nodes/compound/CompoundNode.tsx +0 -226
  556. package/src/xyflow/nodes/compound/index.ts +0 -1
  557. package/src/xyflow/nodes/element/ElementLink.css.ts +0 -67
  558. package/src/xyflow/nodes/element/ElementLink.tsx +0 -97
  559. package/src/xyflow/nodes/element/ElementNode.tsx +0 -208
  560. package/src/xyflow/nodes/element/element.css.ts +0 -369
  561. package/src/xyflow/nodes/element/index.ts +0 -1
  562. package/src/xyflow/nodes/shared/ElementIcon.tsx +0 -43
  563. package/src/xyflow/nodes/shared/Toolbar.tsx +0 -496
  564. package/src/xyflow/types.ts +0 -57
  565. package/src/xyflow/useXYFlowEvents.ts +0 -315
  566. /package/dist/{xyflow → base}/const.d.ts +0 -0
  567. /package/dist/{xyflow → base}/const.js +0 -0
  568. /package/dist/{ui → context}/EnsureMantine.d.ts +0 -0
  569. /package/dist/{ui → context}/EnsureMantine.js +0 -0
  570. /package/dist/{ui → context}/FramerMotionConfig.d.ts +0 -0
  571. /package/dist/{xyflow → likec4diagram/custom}/edges/RelationshipsDropdownMenu.css.d.ts +0 -0
  572. /package/dist/{ui/top-left → likec4diagram/ui/controls}/ChangeAutoLayoutButton.d.ts +0 -0
  573. /package/dist/{ui/top-left → likec4diagram/ui/controls}/ManualLayoutToolsButton.d.ts +0 -0
  574. /package/dist/{ui/top-left → likec4diagram/ui/controls}/_shared.d.ts +0 -0
  575. /package/dist/{ui → likec4diagram/ui/diagram-title}/DiagramTitlePanel.css.d.ts +0 -0
  576. /package/dist/{ui → likec4diagram/ui/diagram-title}/Link.js +0 -0
  577. /package/dist/{ui → likec4diagram/ui}/notation/NotationPanel.css.d.ts +0 -0
  578. /package/dist/{ui → likec4diagram/ui}/notation/index.d.ts +0 -0
  579. /package/dist/{ui → likec4diagram/ui/walkthrough}/DynamicViewWalkthrough.css.d.ts +0 -0
  580. /package/dist/{ui → likec4diagram/ui/walkthrough}/DynamicViewWalkthrough.d.ts +0 -0
  581. /package/src/{ui → context}/EnsureMantine.tsx +0 -0
  582. /package/src/{ui → likec4diagram/ui}/notation/index.ts +0 -0
@@ -1,699 +0,0 @@
1
- import dagre, { type EdgeConfig, type GraphLabel } from '@dagrejs/dagre'
2
- import {
3
- compareByFqnHierarchically,
4
- compareNatural,
5
- compareRelations,
6
- type DiagramNode,
7
- type DiagramView,
8
- type Fqn,
9
- invariant,
10
- isAncestor,
11
- type LikeC4Model,
12
- nonNullable,
13
- parentFqn,
14
- type RelationId
15
- } from '@likec4/core'
16
- import { MarkerType } from '@xyflow/system'
17
- import { useMemo } from 'react'
18
- import {
19
- filter,
20
- find,
21
- first,
22
- flatMap,
23
- forEach,
24
- forEachObj,
25
- groupBy,
26
- isNonNullish,
27
- isTruthy,
28
- map,
29
- mapToObj,
30
- only,
31
- pipe,
32
- prop,
33
- reduce,
34
- reverse,
35
- sort,
36
- sortBy,
37
- takeWhile,
38
- tap
39
- } from 'remeda'
40
- import { useLikeC4Model } from '../../likec4model'
41
- import type { RelationshipsOfFlowTypes } from './_types'
42
-
43
- const columns = ['incomers', 'subjects', 'outgoers'] as const
44
- type ColumnKey = typeof columns[number]
45
-
46
- // const graphColumn = <C extends 'incomers' | 'subjects' | 'outgoers'>(c: C) => ({
47
- // name: c,
48
- // id: `__${c}`,
49
- // anchor: `__${c}::anchor`
50
- // })
51
-
52
- /**
53
- * All constants related to the layout
54
- */
55
- const Sizes = {
56
- dagre: {
57
- ranksep: 60,
58
- nodesep: 35,
59
- edgesep: 25
60
- } satisfies GraphLabel,
61
- edgeLabel: {
62
- width: 120,
63
- height: 10,
64
- minlen: 1,
65
- weight: 1
66
- } satisfies EdgeConfig,
67
-
68
- emptyNodeOffset: 120,
69
-
70
- nodeWidth: 320,
71
- hodeHeight: 180,
72
-
73
- // Spacer between elements in a compound node
74
- // 0 means no spacer
75
- spacerHeight: 0,
76
-
77
- compound: {
78
- labelHeight: 1,
79
- paddingTop: 50,
80
- paddingBottom: 32
81
- }
82
- }
83
-
84
- export const ZIndexes = {
85
- empty: 2,
86
- compound: 2,
87
- edge: 3,
88
- element: 4,
89
-
90
- max: 5
91
- }
92
-
93
- function createGraph() {
94
- const g = new dagre.graphlib.Graph({
95
- directed: true,
96
- compound: true
97
- })
98
- g.setGraph({
99
- ...Sizes.dagre,
100
- rankdir: 'LR'
101
- })
102
- g.setDefaultEdgeLabel(() => ({ ...Sizes.edgeLabel }))
103
- g.setDefaultNodeLabel(() => ({}))
104
-
105
- // columns.reduce((prev, column) => {
106
- // const c = graphColumn(column)
107
- // g.setNode(c.id, {})
108
- // g.setNode(c.anchor, { width: 40, height: 2 })
109
- // g.setParent(c.anchor, c.id)
110
- // if (prev) {
111
- // g.setEdge(prev, c.anchor, {
112
- // width: 0
113
- // })
114
- // }
115
- // return c.anchor
116
- // }, null as string | null)
117
-
118
- return g
119
- }
120
-
121
- type Context = {
122
- scope: 'global' | 'view'
123
- g: dagre.graphlib.Graph
124
- subjectId: Fqn
125
- diagramNodes: Map<Fqn, DiagramNode>
126
- subjectElement: LikeC4Model.Element
127
- // likec4model: LikeC4Model
128
- // subject: XYFlowTypes.ElementNode
129
- // Model
130
- // subject: LikeC4ModelElement
131
- connected: {
132
- incomers: Set<Fqn>
133
- subjects: Set<Fqn>
134
- outgoers: Set<Fqn>
135
- }
136
- columns: {
137
- incomers: Map<Fqn, RelationshipsOfFlowTypes.Node>
138
- subjects: Map<Fqn, RelationshipsOfFlowTypes.Node>
139
- outgoers: Map<Fqn, RelationshipsOfFlowTypes.Node>
140
- }
141
- edges: RelationshipsOfFlowTypes.Edge[]
142
- }
143
-
144
- const sized = (height: number = Sizes.hodeHeight) => ({
145
- width: Sizes.nodeWidth,
146
- height
147
- })
148
-
149
- const graphId = (node: RelationshipsOfFlowTypes.Node) => ({
150
- id: node.id,
151
- port: node.type === 'compound' ? `${node.id}::port` : node.id,
152
- body: `${node.id}`,
153
- spacer: `${node.id}:spacer`
154
- })
155
-
156
- function nodeData(
157
- element: LikeC4Model.Element,
158
- ctx: Context
159
- ): Omit<RelationshipsOfFlowTypes.NonEmptyNode['data'], 'column'> {
160
- // We try to inherit style from existing diagram node
161
- let diagramNode = ctx.diagramNodes.get(element.id)
162
-
163
- // Ansector separetely, because we want to inherit
164
- // color from it if there is no diagram node
165
- const ancestor = diagramNode ?? (ctx.scope === 'view'
166
- ? pipe(
167
- element.ancestors().toArray(),
168
- map(ancestor => ctx.diagramNodes.get(ancestor.id)),
169
- filter(isTruthy),
170
- first()
171
- )
172
- : undefined)
173
-
174
- return {
175
- fqn: element.id,
176
- existsInCurrentView: ctx.diagramNodes.has(element.id),
177
- element: {
178
- kind: element.kind,
179
- title: diagramNode?.title ?? element.title,
180
- description: diagramNode?.description ?? element.description,
181
- color: diagramNode?.color ?? ancestor?.color ?? element.color,
182
- shape: diagramNode?.shape ?? element.shape
183
- },
184
- navigateTo: diagramNode?.navigateTo ?? element.defaultView?.id ?? null,
185
- ports: {
186
- in: [],
187
- out: []
188
- }
189
- }
190
- }
191
-
192
- function createEmptyNode(
193
- column: ColumnKey,
194
- ctx: Context
195
- ): RelationshipsOfFlowTypes.EmptyNode {
196
- const id = `${column}__empty` as Fqn
197
- const xynodes = ctx.columns[column]
198
- let node = xynodes.get(id)
199
- if (node) {
200
- invariant(node.type === 'empty', 'Node is not empty')
201
- return node
202
- }
203
- const xynode: RelationshipsOfFlowTypes.EmptyNode = {
204
- type: 'empty',
205
- id,
206
- position: { x: 0, y: 0 },
207
- data: {
208
- column,
209
- existsInCurrentView: true
210
- },
211
- zIndex: ZIndexes.empty
212
- }
213
- xynodes.set(id, xynode)
214
- const k = graphId(xynode)
215
-
216
- const emptyContainer = id + '__container'
217
- ctx.g.setNode(emptyContainer, {})
218
- ctx.g.setNode(k.id, {
219
- width: Sizes.nodeWidth - 20,
220
- height: Sizes.hodeHeight
221
- })
222
- ctx.g.setParent(k.id, emptyContainer)
223
- return xynode
224
- }
225
-
226
- function createNode(
227
- column: ColumnKey,
228
- nodeType: Exclude<RelationshipsOfFlowTypes.Node['type'], 'empty'>,
229
- element: LikeC4Model.Element,
230
- ctx: Context,
231
- depth: number = 0
232
- ): RelationshipsOfFlowTypes.ElementNode | RelationshipsOfFlowTypes.CompoundNode {
233
- const xynodes = ctx.columns[column]
234
- let node = xynodes.get(element.id)
235
- if (node) {
236
- invariant(node.type !== 'empty', `Unexpected empty Node type ${element.id}: ${node.type}, expect ${nodeType}`)
237
- if (node.type === 'element' && nodeType === 'compound') {
238
- throw new Error(`Unexpected Node type ${element.id}: ${node.type}, expect ${nodeType}`)
239
- }
240
- return node
241
- }
242
- const g = ctx.g
243
-
244
- // Create parent node
245
- const parent = pipe(
246
- element.ancestors().toArray(),
247
- takeWhile(ancestor => !isAncestor(ancestor.id, ctx.subjectId)),
248
- find(ancestor =>
249
- ctx.diagramNodes.has(ancestor.id) || ctx.connected[column].has(ancestor.id)
250
- || (ctx.scope === 'global' && ctx.subjectElement.ascendingSiblings().some(s => s.id === ancestor.id))
251
- ),
252
- found => found ? createNode(column, 'compound', found, ctx, depth + 2) : null
253
- )
254
-
255
- const xynode: RelationshipsOfFlowTypes.NonEmptyNode = {
256
- type: nodeType,
257
- id: `${column}::${element.id}`,
258
- position: { x: 0, y: 0 },
259
- data: {
260
- ...nodeData(element, ctx),
261
- column
262
- },
263
- zIndex: ZIndexes[nodeType],
264
- ...(!!parent && { parentId: parent.id })
265
- }
266
- xynodes.set(element.id, xynode)
267
- // There is one-to-one mapping between XYFlow node and dagre node
268
- // Compound node has two nodes: body and port (for edges)
269
-
270
- const k = graphId(xynode)
271
-
272
- g.setNode(k.id, sized())
273
- if (xynode.type === 'compound') {
274
- g.setNode(k.port, {
275
- width: Sizes.nodeWidth - Sizes.dagre.ranksep,
276
- height: Sizes.compound.labelHeight
277
- })
278
- g.setParent(k.port, k.id)
279
- }
280
-
281
- if (parent) {
282
- parent.data.depth = Math.min(Math.max(parent.data.depth ?? 0, depth + 1), 6)
283
- g.setParent(k.id, graphId(parent).body)
284
- }
285
- return xynode
286
- }
287
-
288
- /**
289
- * Apply dagre layout to the graph
290
- * And return a function to get node bounds for xyflow
291
- */
292
- function applyDagreLayout(g: dagre.graphlib.Graph) {
293
- type NodeBounds = Required<Pick<RelationshipsOfFlowTypes.Node, 'position' | 'width' | 'height'>>
294
- dagre.layout(g)
295
- return function nodeBounds(nodeId: string): NodeBounds {
296
- const { x, y, width, height } = g.node(nodeId)
297
- return {
298
- position: {
299
- x: x - Math.round(width / 2),
300
- y: y - Math.round(height / 2)
301
- },
302
- width,
303
- height
304
- }
305
- }
306
- }
307
-
308
- function addEdge(
309
- ctx: Context,
310
- props: {
311
- existsInCurrentView: boolean
312
- source: string
313
- target: string
314
- relations: RelationshipsOfFlowTypes.Edge['data']['relations']
315
- }
316
- ) {
317
- const { source, target, relations, existsInCurrentView } = props
318
- const ids = relations.map(r => r.id).join('_')
319
- const label = only(relations)?.title ?? 'untitled'
320
-
321
- const isMultiple = relations.length > 1
322
- const edge: RelationshipsOfFlowTypes.Edge = {
323
- id: `rel${ctx.edges.length + 1}_${ids}`,
324
- type: 'relation',
325
- source,
326
- target,
327
- sourceHandle: target,
328
- targetHandle: source,
329
- data: {
330
- existsInCurrentView: existsInCurrentView,
331
- relations
332
- },
333
- label: isMultiple ? `${relations.length} relationships` : label,
334
- zIndex: ZIndexes.edge,
335
- markerEnd: {
336
- type: MarkerType.ArrowClosed,
337
- width: isMultiple ? 7 : 9
338
- },
339
- style: {
340
- strokeWidth: isMultiple ? 5 : 2.8,
341
- strokeDasharray: isMultiple ? undefined : '5, 5'
342
- }
343
- }
344
- ctx.edges.push(edge)
345
- }
346
-
347
- function findNodeOrFirstAncestor<N>(fqn: Fqn, nodes: Map<Fqn, N>) {
348
- let node = nodes.get(fqn)
349
- let parent: Fqn | null = fqn
350
- while (!node && !!(parent = parentFqn(parent))) {
351
- node = nodes.get(parent)
352
- }
353
- return node
354
- }
355
-
356
- function layout(
357
- subjectId: Fqn,
358
- view: DiagramView,
359
- likec4model: LikeC4Model,
360
- scope: 'global' | 'view'
361
- ): {
362
- viewIncludesSubject: boolean
363
- notIncludedRelations: number
364
- subject: LikeC4Model.Element
365
- nodes: RelationshipsOfFlowTypes.Node[]
366
- edges: RelationshipsOfFlowTypes.Edge[]
367
- bounds: {
368
- x: number
369
- y: number
370
- width: number
371
- height: number
372
- }
373
- } {
374
- const diagramNodes = new Map(view.nodes.map(n => [n.id, n]))
375
- const subjectElement = likec4model.element(subjectId)
376
-
377
- const viewIncludesSubject = diagramNodes.has(subjectId)
378
-
379
- const viewRelationships = new Set(
380
- view.edges.flatMap(e => e.relations)
381
- )
382
- // Relations that are not included in the view
383
- const notIncludedRelations = new Set<RelationId>()
384
-
385
- if (!viewIncludesSubject) {
386
- // Reset scope to global if subject is not in the view
387
- scope = 'global'
388
- } else {
389
- forEach([
390
- ...subjectElement.incoming().map(r => r.id),
391
- ...subjectElement.outgoing().map(r => r.id)
392
- ], (relationId) => {
393
- if (!viewRelationships.has(relationId)) {
394
- notIncludedRelations.add(relationId)
395
- }
396
- })
397
- }
398
-
399
- let relationships
400
-
401
- if (scope === 'global') {
402
- relationships = {
403
- incoming: subjectElement.incoming().map(r => r.$relationship).toArray(),
404
- outgoing: subjectElement.outgoing().map(r => r.$relationship).toArray()
405
- }
406
- } else {
407
- const subjectViewModel = likec4model.view(view.id).node(subjectId)
408
- relationships = {
409
- incoming: subjectViewModel.incoming()
410
- .flatMap(c => c.relationships('model').map(r => r.$relationship))
411
- .toArray(),
412
- outgoing: subjectViewModel.outgoing()
413
- .flatMap(c => c.relationships('model').map(r => r.$relationship))
414
- .toArray()
415
- }
416
- }
417
-
418
- const g = createGraph()
419
-
420
- const ctx: Context = {
421
- scope,
422
- g,
423
- diagramNodes,
424
- subjectElement,
425
- subjectId,
426
- connected: {
427
- incomers: new Set<Fqn>(),
428
- outgoers: new Set<Fqn>(),
429
- subjects: new Set<Fqn>([subjectId])
430
- },
431
- columns: {
432
- incomers: new Map(),
433
- subjects: new Map(),
434
- outgoers: new Map()
435
- },
436
- edges: []
437
- }
438
-
439
- relationships.incoming.forEach(incoming => {
440
- ctx.connected.incomers.add(incoming.source)
441
- ctx.connected.subjects.add(incoming.target)
442
- })
443
- relationships.outgoing.forEach(outgoing => {
444
- ctx.connected.subjects.add(outgoing.source)
445
- ctx.connected.outgoers.add(outgoing.target)
446
- })
447
-
448
- if (viewIncludesSubject) {
449
- const subjectViewModel = likec4model.view(view.id).node(subjectId)
450
- subjectViewModel.incomers().forEach(incomer => {
451
- ctx.connected.incomers.add(incomer.id)
452
- })
453
- subjectViewModel.outgoers().forEach(outgoer => {
454
- ctx.connected.outgoers.add(outgoer.id)
455
- })
456
- }
457
-
458
- // Created nodes per column
459
- columns.forEach(column => {
460
- pipe(
461
- [...ctx.connected[column].values()],
462
- map(id => likec4model.element(id)),
463
- sort((a, b) => -1 * compareNatural(a.title, b.title)),
464
- sort(compareByFqnHierarchically),
465
- reverse(),
466
- forEach(element => {
467
- createNode(column, 'element', element, ctx)
468
- })
469
- )
470
- })
471
-
472
- pipe(
473
- [
474
- // Process incoming
475
- {
476
- sources: ctx.columns.incomers,
477
- targets: ctx.columns.subjects,
478
- relationships: relationships.incoming.sort(compareRelations).reverse()
479
- },
480
- // Process outgoing
481
- {
482
- sources: ctx.columns.subjects,
483
- targets: ctx.columns.outgoers,
484
- relationships: relationships.outgoing.sort(compareRelations).reverse()
485
- }
486
- ],
487
- /**
488
- * We select relationships, sources and targets
489
- * If sourece or target of the relationship is not found - take first ancestor
490
- */
491
- flatMap(({ sources, targets, relationships }) => {
492
- return relationships.map(relation => {
493
- const source = findNodeOrFirstAncestor(relation.source, sources)
494
- if (!source || source.type === 'empty') {
495
- return null
496
- }
497
- const target = findNodeOrFirstAncestor(relation.target, targets)
498
- if (!target || target.type === 'empty') {
499
- return null
500
- }
501
- return ({
502
- relation,
503
- source,
504
- target,
505
- existsInCurrentView: viewRelationships.has(relation.id),
506
- id: `${source.id}:${target.id}`
507
- })
508
- })
509
- }),
510
- filter(isNonNullish),
511
- // Group relations with saame source and target - make them one edge
512
- groupBy(prop('id')),
513
- forEachObj((grouped) => {
514
- const { source, target } = grouped[0]
515
- const relations = map(grouped, g => g.relation)
516
-
517
- source.data.ports.out.push(target.id)
518
- target.data.ports.in.push(source.id)
519
-
520
- const isAnyCompound = source.type === 'compound' || target.type === 'compound'
521
-
522
- g.setEdge(graphId(source).port, graphId(target).port, {
523
- ...Sizes.edgeLabel
524
- // weight: isAnyCompound ? 1 : 2
525
- })
526
-
527
- addEdge(ctx, {
528
- // if view does not include subject - do not highlight
529
- existsInCurrentView: !viewIncludesSubject || grouped.every(g => g.existsInCurrentView),
530
- source: source.id,
531
- target: target.id,
532
- relations
533
- })
534
- })
535
- )
536
-
537
- // Create empty nodes if there are no incomers or outgoers
538
- const subjectPort = graphId(ctx.columns.subjects.get(subjectId)!).port
539
-
540
- if (ctx.columns.incomers.size == 0) {
541
- const source = createEmptyNode('incomers', ctx)
542
- g.setEdge(graphId(source).port, subjectPort)
543
- }
544
- if (ctx.columns.outgoers.size == 0) {
545
- const target = createEmptyNode('outgoers', ctx)
546
- g.setEdge(subjectPort, graphId(target).port)
547
- }
548
-
549
- // Grow nodes with more than 2 ports
550
- for (const subject of ctx.columns.subjects.values()) {
551
- if (subject.type !== 'element') {
552
- continue
553
- }
554
- const subjectPortsCount = Math.max(subject.data.ports.in.length, subject.data.ports.out.length)
555
- if (subjectPortsCount > 2) {
556
- g.node(subject.id).height = Sizes.hodeHeight + (subjectPortsCount - 3) * 14
557
- }
558
- }
559
-
560
- //
561
- const dagreBounds = applyDagreLayout(ctx.g)
562
-
563
- const xynodes = [
564
- ...ctx.columns.incomers.values(),
565
- ...ctx.columns.subjects.values(),
566
- ...ctx.columns.outgoers.values()
567
- ]
568
-
569
- // Calculate bounds for all nodes except compounds
570
- // We shrink compounds to fit their children
571
- const _calculatedNodeBounds = pipe(
572
- xynodes,
573
- filter(n => n.type !== 'compound'),
574
- mapToObj(n => [n.id, dagreBounds(n.id)])
575
- )
576
-
577
- function nodeBounds(nodeId: string): ReturnType<typeof dagreBounds> {
578
- return _calculatedNodeBounds[nodeId] ??= pipe(
579
- xynodes,
580
- filter(n => n.parentId === nodeId),
581
- map(n => nodeBounds(n.id)),
582
- tap(bounds => {
583
- invariant(bounds.length > 0, `Node ${nodeId} has no nested nodes`)
584
- }),
585
- reduce((acc, bounds) => {
586
- return {
587
- minY: Math.min(acc.minY, bounds.position.y),
588
- maxY: Math.max(acc.maxY, bounds.position.y + bounds.height)
589
- }
590
- }, { minY: Infinity, maxY: -Infinity }),
591
- ({ minY, maxY }) => {
592
- const {
593
- position: { x },
594
- width
595
- } = dagreBounds(nodeId)
596
- minY = minY - Sizes.compound.paddingTop
597
- maxY = maxY + Sizes.compound.paddingBottom
598
-
599
- return {
600
- position: {
601
- x,
602
- y: minY
603
- },
604
- width,
605
- height: maxY - minY
606
- }
607
- }
608
- )
609
- }
610
-
611
- // update xynodes
612
- for (const node of xynodes) {
613
- const { position, width, height } = nodeBounds(node.id)
614
- node.width = width
615
- node.height = height
616
- node.position = position
617
- if (node.parentId) {
618
- const parentPos = nodeBounds(node.parentId).position
619
- node.position = {
620
- x: position.x - parentPos.x,
621
- y: position.y - parentPos.y
622
- }
623
- }
624
- }
625
-
626
- // Sort ports in subject vertically
627
- const sortedPorts = (ports: string[]) => {
628
- return pipe(
629
- ports,
630
- map(port => {
631
- return {
632
- port,
633
- topY: nodeBounds(port).position.y
634
- }
635
- }),
636
- sortBy(prop('topY')),
637
- map(prop('port'))
638
- )
639
- }
640
-
641
- for (const node of xynodes) {
642
- // Grow empty nodes to fill the space
643
- if (node.type === 'empty') {
644
- const subjectBounds = nodeBounds(nonNullable(ctx.columns.subjects.get(subjectId), 'Subject node is missing').id)
645
- node.height = Math.min(subjectBounds.height, 300)
646
- node.position.y = subjectBounds.position.y + subjectBounds.height / 2 - node.height / 2
647
- if (node.data.column === 'incomers') {
648
- node.width = subjectBounds.position.x - Sizes.emptyNodeOffset - node.position.x
649
- } else {
650
- const rightX = node.position.x + node.width!
651
- node.position.x = subjectBounds.position.x + subjectBounds.width + Sizes.emptyNodeOffset
652
- node.width = rightX - node.position.x
653
- }
654
- continue
655
- }
656
- // Sort ports by their position
657
- if (node.data.ports.in.length > 1) {
658
- node.data.ports.in = sortedPorts(node.data.ports.in)
659
- }
660
- if (node.data.ports.out.length > 1) {
661
- node.data.ports.out = sortedPorts(node.data.ports.out)
662
- }
663
- }
664
-
665
- return {
666
- viewIncludesSubject,
667
- notIncludedRelations: notIncludedRelations.size,
668
- subject: subjectElement,
669
- edges: ctx.edges,
670
- nodes: xynodes,
671
- bounds: {
672
- x: 0,
673
- y: 0,
674
- width: g.graph().width ?? 100,
675
- height: g.graph().height ?? 100
676
- }
677
- }
678
- }
679
-
680
- export function useLayoutedRelationships(
681
- subjectId: Fqn,
682
- view: DiagramView,
683
- scope: 'global' | 'view'
684
- ) {
685
- const likec4model = useLikeC4Model(true)
686
- return useMemo(() =>
687
- layout(
688
- subjectId,
689
- view,
690
- likec4model,
691
- scope
692
- ), [
693
- subjectId,
694
- view,
695
- likec4model,
696
- layout,
697
- scope
698
- ])
699
- }