@likec4/diagram 1.18.0 → 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 (277) 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 +34 -27
  222. package/src/LikeC4Diagram.tsx +4 -4
  223. package/src/LikeC4Search.css.ts +12 -0
  224. package/src/LikeC4Search.tsx +39 -90
  225. package/src/controls/Text.ts +5 -0
  226. package/src/controls/action-button-bar/ActionButtonBar.css.ts +13 -0
  227. package/src/controls/action-button-bar/ActionButtonBar.tsx +138 -0
  228. package/src/controls/action-button-bar/useActionButtonBarCtx.ts +13 -0
  229. package/src/controls/action-buttons/ActionButton.css.ts +29 -0
  230. package/src/controls/action-buttons/ActionButton.tsx +66 -0
  231. package/src/controls/action-buttons/ActionButtons.tsx +138 -0
  232. package/src/hooks/useXYFlow.ts +8 -8
  233. package/src/index.ts +12 -6
  234. package/src/likec4model/index.ts +12 -2
  235. package/src/overlays/edge-details/EdgeDetailsXYFlow.tsx +18 -12
  236. package/src/overlays/edge-details/_types.ts +13 -37
  237. package/src/overlays/edge-details/use-layouted-edge-details.ts +16 -14
  238. package/src/overlays/edge-details/xyflow/CompoundNode.tsx +3 -11
  239. package/src/overlays/edge-details/xyflow/ElementNode.tsx +4 -11
  240. package/src/overlays/edge-details/xyflow/RelationshipEdge.tsx +3 -3
  241. package/src/overlays/edge-details/xyflow/styles.css.ts +1 -59
  242. package/src/overlays/relationships-of/RelationshipsXYFlow.tsx +23 -23
  243. package/src/overlays/relationships-of/_types.ts +20 -58
  244. package/src/overlays/relationships-of/use-layouted-relationships.ts +36 -40
  245. package/src/overlays/relationships-of/xyflow/CompoundNode.tsx +9 -13
  246. package/src/overlays/relationships-of/xyflow/ElementNode.tsx +12 -15
  247. package/src/overlays/relationships-of/xyflow/EmptyNode.tsx +4 -7
  248. package/src/overlays/relationships-of/xyflow/RelationshipEdge.tsx +16 -14
  249. package/src/overlays/shared/xyflow/RelationshipEdge.css.ts +60 -0
  250. package/src/overlays/shared/xyflow/_types.ts +87 -0
  251. package/src/state/diagram-to-xyflow.ts +6 -7
  252. package/src/state/diagramStore.layout.ts +3 -4
  253. package/src/state/diagramStore.ts +35 -37
  254. package/src/theme-vars.css.ts +81 -0
  255. package/src/theme-vars.ts +8 -81
  256. package/src/ui/DiagramTitlePanel.tsx +6 -6
  257. package/src/utils/types.ts +6 -0
  258. package/src/xyflow/SelectEdgesOnNodeFocus.tsx +3 -3
  259. package/src/xyflow/XYFlow.tsx +2 -2
  260. package/src/xyflow/edges/EdgeLabel.tsx +25 -18
  261. package/src/xyflow/edges/RelationshipEdge.tsx +5 -3
  262. package/src/xyflow/edges/RelationshipsDropdownMenu.tsx +3 -3
  263. package/src/xyflow/edges/edges.css.ts +68 -74
  264. package/src/xyflow/edges/utils.ts +6 -6
  265. package/src/xyflow/nodes/AnimateVariants.ts +143 -0
  266. package/src/xyflow/nodes/Node.css.ts +44 -0
  267. package/src/xyflow/nodes/compound/CompoundNode.css.ts +1 -64
  268. package/src/xyflow/nodes/compound/CompoundNode.tsx +69 -182
  269. package/src/xyflow/nodes/element/ElementLink.tsx +2 -3
  270. package/src/xyflow/nodes/element/ElementNode.tsx +64 -266
  271. package/src/xyflow/nodes/element/element.css.ts +0 -57
  272. package/src/xyflow/nodes/shared/Toolbar.tsx +30 -30
  273. package/src/xyflow/types.ts +48 -51
  274. package/src/xyflow/useLayoutConstraints.ts +9 -9
  275. package/src/xyflow/useXYFlowEvents.ts +13 -30
  276. package/src/xyflow/utils.ts +2 -2
  277. package/src/xyflow/nodes/use-animate-variants.tsx +0 -64
@@ -0,0 +1,290 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { isAncestor, delay } from "@likec4/core";
3
+ import { useId } from "@mantine/hooks";
4
+ import { useSyncedRef, useDebouncedCallback, useDeepCompareEffect } from "@react-hookz/web";
5
+ import { ReactFlowProvider, useReactFlow, useStoreApi, useStore, useOnViewportChange, getViewportForBounds, ReactFlow } from "@xyflow/react";
6
+ import { getNodeDimensions } from "@xyflow/system";
7
+ import { useRef, useState } from "react";
8
+ import { map, setPath, omit, isNullish } from "remeda";
9
+ import { centerXYInternalNode } from "../../xyflow/utils.js";
10
+ import { cssReactflowMarker } from "../Overlays.css.js";
11
+ import { ZIndexes } from "./use-layouted-relationships.js";
12
+ import { CompoundNode } from "./xyflow/CompoundNode.js";
13
+ import { ElementNode } from "./xyflow/ElementNode.js";
14
+ import { EmptyNode } from "./xyflow/EmptyNode.js";
15
+ import { RelationshipEdge } from "./xyflow/RelationshipEdge.js";
16
+ import { useUpdateEffect } from "../../hooks/useUpdateEffect.js";
17
+ const nodeTypes = {
18
+ element: ElementNode,
19
+ compound: CompoundNode,
20
+ empty: EmptyNode
21
+ };
22
+ const edgeTypes = {
23
+ relation: RelationshipEdge
24
+ };
25
+ const findRootSubject = (nodes) => nodes.find((n) => n.data.column === "subjects" && isNullish(n.parentId));
26
+ const resetDimmedAndHovered = (xyflow) => {
27
+ xyflow.setEdges(
28
+ (edges) => edges.map((edge) => ({
29
+ ...edge,
30
+ data: {
31
+ ...edge.data,
32
+ dimmed: false,
33
+ hovered: false
34
+ },
35
+ animated: false
36
+ }))
37
+ );
38
+ xyflow.setNodes(
39
+ (nodes) => nodes.map(
40
+ (n) => ({
41
+ ...n,
42
+ data: {
43
+ ...n.data,
44
+ dimmed: false,
45
+ hovered: false
46
+ }
47
+ })
48
+ )
49
+ );
50
+ };
51
+ const animateEdge = (node, animated = true) => (edges) => {
52
+ return edges.map((edge) => {
53
+ const isConnected = edge.source === node.id || edge.target === node.id || isAncestor(node.id, edge.source) || isAncestor(node.id, edge.target);
54
+ return {
55
+ ...edge,
56
+ animated: animated && isConnected
57
+ };
58
+ });
59
+ };
60
+ const selectContainerViewport = (s) => `${s.width}x${s.height}`;
61
+ function RelationshipsXYFlowWrapped({
62
+ subjectId,
63
+ view,
64
+ nodes,
65
+ edges,
66
+ bounds,
67
+ children,
68
+ maxZoom = 2,
69
+ minZoom = 0.05,
70
+ viewportPadding = 0.1,
71
+ ...rest
72
+ }) {
73
+ const id = useId();
74
+ const lastClickedNodeRef = useRef(null);
75
+ const xyflow = useReactFlow();
76
+ const xystore = useStoreApi();
77
+ const [zoomOnDoubleClick, setZoomOnDoubleClick] = useState(true);
78
+ const containerviewport = useStore(selectContainerViewport);
79
+ useOnViewportChange({
80
+ onEnd: ({ x, y, zoom }) => {
81
+ const roundedX = Math.round(x), roundedY = Math.round(y);
82
+ if (x !== roundedX || y !== roundedY) {
83
+ xystore.setState({ transform: [roundedX, roundedY, zoom] });
84
+ }
85
+ setZoomOnDoubleClick(zoom < 0.7);
86
+ }
87
+ });
88
+ const initialFitviewFlagRef = useRef(false);
89
+ const viewBoundsRef = useSyncedRef(bounds);
90
+ const fitview = useDebouncedCallback(
91
+ () => {
92
+ const { width, height } = xystore.getState();
93
+ xyflow.setViewport(
94
+ getViewportForBounds(viewBoundsRef.current, width, height, minZoom, maxZoom, viewportPadding),
95
+ initialFitviewFlagRef.current ? { duration: 500 } : void 0
96
+ );
97
+ initialFitviewFlagRef.current = true;
98
+ },
99
+ [xyflow, minZoom, maxZoom, viewportPadding],
100
+ 100
101
+ );
102
+ useUpdateEffect(() => {
103
+ fitview();
104
+ }, [containerviewport]);
105
+ useDeepCompareEffect(() => {
106
+ const {
107
+ nodes: _nodes,
108
+ edges: _edges,
109
+ setNodes,
110
+ setEdges,
111
+ width,
112
+ height
113
+ } = xystore.getState();
114
+ const nextSubjectNode = findRootSubject(nodes);
115
+ const currentSubjectNode = findRootSubject(_nodes);
116
+ if (currentSubjectNode && (nextSubjectNode == null ? void 0 : nextSubjectNode.data.fqn) === currentSubjectNode.data.fqn) {
117
+ setNodes(map(nodes, setPath(["data", "entering"], false)));
118
+ setEdges(edges);
119
+ fitview();
120
+ return;
121
+ }
122
+ if (!nextSubjectNode) {
123
+ console.error("Subject node not found");
124
+ } else if (nextSubjectNode.data.fqn !== subjectId) {
125
+ console.error(`Subject node mismatch, expected: ${subjectId} got: ${nextSubjectNode.data.fqn}`);
126
+ }
127
+ const nextzoom = getViewportForBounds(bounds, width, height, minZoom, maxZoom, viewportPadding).zoom;
128
+ const nextSubjectCenter = nextSubjectNode && {
129
+ x: nextSubjectNode.position.x + (nextSubjectNode.width ?? 0) / 2,
130
+ y: nextSubjectNode.position.y + (nextSubjectNode.height ?? 0) / 2
131
+ };
132
+ const existingNode = lastClickedNodeRef.current ?? xyflow.getNodes().find((n) => n.type !== "empty" && n.data.column !== "subjects" && n.data.fqn === subjectId);
133
+ lastClickedNodeRef.current = null;
134
+ if (nextSubjectCenter && existingNode && currentSubjectNode) {
135
+ const currentSubjectInternalNode = xyflow.getInternalNode(currentSubjectNode.id);
136
+ const currentSubjectCenter = centerXYInternalNode(currentSubjectInternalNode);
137
+ const existingInternalNode = xyflow.getInternalNode(existingNode.id);
138
+ const existingDimensions = getNodeDimensions(existingInternalNode);
139
+ nextSubjectNode.data.layoutId = existingNode.id;
140
+ setNodes(_nodes.map((n) => {
141
+ if (n.id !== existingNode.id) {
142
+ return {
143
+ ...n,
144
+ data: {
145
+ ...n.data,
146
+ leaving: n.data.column === "subjects",
147
+ dimmed: n.data.column === "subjects" ? "immediate" : false
148
+ }
149
+ // hidden: n.data.column === 'subjects'
150
+ };
151
+ }
152
+ return {
153
+ ...omit(n, ["parentId"]),
154
+ position: {
155
+ x: currentSubjectCenter.x - existingDimensions.width / 2,
156
+ y: currentSubjectCenter.y - existingDimensions.height / 2
157
+ },
158
+ zIndex: ZIndexes.max,
159
+ data: {
160
+ ...n.data,
161
+ leaving: false,
162
+ dimmed: false
163
+ }
164
+ };
165
+ }));
166
+ setEdges(_edges.map((e) => ({
167
+ ...e,
168
+ data: {
169
+ ...e.data,
170
+ dimmed: "immediate"
171
+ },
172
+ hidden: e.source === existingNode.id || e.target === existingNode.id || isAncestor(existingNode.id, e.source) || isAncestor(existingNode.id, e.target)
173
+ })));
174
+ const zoom = Math.min(
175
+ xyflow.getViewport().zoom,
176
+ nextzoom
177
+ );
178
+ let isCancelled = false;
179
+ const layout = async () => {
180
+ await delay(150);
181
+ if (isCancelled) return;
182
+ await xyflow.setCenter(currentSubjectCenter.x, currentSubjectCenter.y, { zoom, duration: 250 });
183
+ requestAnimationFrame(() => {
184
+ if (isCancelled) return;
185
+ xyflow.setCenter(nextSubjectCenter.x, nextSubjectCenter.y, { zoom });
186
+ setNodes(nodes);
187
+ setEdges(edges);
188
+ fitview();
189
+ });
190
+ };
191
+ requestAnimationFrame(layout);
192
+ return () => {
193
+ isCancelled = true;
194
+ };
195
+ }
196
+ setNodes(map(nodes, setPath(["data", "entering"], false)));
197
+ setEdges(edges);
198
+ fitview();
199
+ return void 0;
200
+ }, [nodes, edges, subjectId]);
201
+ return /* @__PURE__ */ jsx(
202
+ ReactFlow,
203
+ {
204
+ id,
205
+ defaultEdges: [],
206
+ defaultNodes: [],
207
+ nodeTypes,
208
+ edgeTypes,
209
+ defaultMarkerColor: "var(--likec4-relation-lineColor)",
210
+ className: cssReactflowMarker,
211
+ zoomOnPinch: true,
212
+ zoomOnScroll: false,
213
+ zoomOnDoubleClick,
214
+ maxZoom,
215
+ minZoom,
216
+ fitView: true,
217
+ fitViewOptions: {
218
+ padding: viewportPadding,
219
+ maxZoom,
220
+ minZoom,
221
+ includeHiddenNodes: true
222
+ },
223
+ preventScrolling: true,
224
+ noDragClassName: "nodrag",
225
+ noPanClassName: "nopan",
226
+ panOnScroll: true,
227
+ panOnDrag: true,
228
+ nodesFocusable: false,
229
+ edgesFocusable: false,
230
+ nodesDraggable: false,
231
+ onNodeMouseEnter: (_, node) => {
232
+ if (node.type === "empty") return;
233
+ xyflow.setEdges(animateEdge(node, true));
234
+ },
235
+ onNodeMouseLeave: () => {
236
+ resetDimmedAndHovered(xyflow);
237
+ },
238
+ onEdgeMouseEnter: (_, edge) => {
239
+ xyflow.setEdges(
240
+ (edges2) => edges2.map((e) => ({
241
+ ...e,
242
+ data: {
243
+ ...e.data,
244
+ dimmed: e.id !== edge.id,
245
+ hovered: e.id === edge.id
246
+ },
247
+ zIndex: e.id === edge.id ? ZIndexes.max : ZIndexes.edge,
248
+ animated: e.id === edge.id
249
+ }))
250
+ );
251
+ xyflow.setNodes(
252
+ (nodes2) => nodes2.map((n) => ({
253
+ ...n,
254
+ data: {
255
+ ...n.data,
256
+ dimmed: n.id !== edge.source && n.id !== edge.target
257
+ }
258
+ }))
259
+ );
260
+ },
261
+ onEdgeMouseLeave: () => {
262
+ resetDimmedAndHovered(xyflow);
263
+ },
264
+ onNodeDoubleClick: (e) => {
265
+ e.stopPropagation();
266
+ },
267
+ ...!zoomOnDoubleClick && {
268
+ onDoubleClick: (e) => {
269
+ e.stopPropagation();
270
+ fitview();
271
+ }
272
+ },
273
+ ...rest,
274
+ children
275
+ }
276
+ );
277
+ }
278
+ function RelationshipsXYFlow(props) {
279
+ return /* @__PURE__ */ jsx(
280
+ ReactFlowProvider,
281
+ {
282
+ defaultNodes: [],
283
+ defaultEdges: [],
284
+ children: /* @__PURE__ */ jsx(RelationshipsXYFlowWrapped, { ...props })
285
+ }
286
+ );
287
+ }
288
+ export {
289
+ RelationshipsXYFlow
290
+ };
@@ -0,0 +1,2 @@
1
+ export declare const node: string;
2
+ export declare const label: string;
@@ -0,0 +1,7 @@
1
+ /* empty css */
2
+ var node = "z1mia80";
3
+ var label = "z1mia81";
4
+ export {
5
+ label,
6
+ node
7
+ };
@@ -0,0 +1,7 @@
1
+ import { Element, Fqn, ViewId } from '@likec4/core';
2
+ export declare const SelectElement: ({ subject, viewId, scope, onSelect }: {
3
+ subject: Element;
4
+ viewId: ViewId;
5
+ scope: "global" | "view";
6
+ onSelect: (id: Fqn) => void;
7
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,126 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { ancestorsFqn } from "@likec4/core";
3
+ import { useTree, useComputedColorScheme, Popover, PopoverTarget, Button, PopoverDropdown, ScrollAreaAutosize, Tree, Group, ActionIcon, Box, Text } from "@mantine/core";
4
+ import { IconSelector, IconChevronRight } from "@tabler/icons-react";
5
+ import { useRef, useEffect } from "react";
6
+ import * as SelectElement_css from "./SelectElement.css.js";
7
+ import { useLikeC4ElementsTree } from "../../likec4model/useLikeC4ElementsTree.js";
8
+ const SelectElement = ({
9
+ subject,
10
+ viewId,
11
+ scope,
12
+ onSelect
13
+ }) => {
14
+ const viewport = useRef(null);
15
+ const data = useLikeC4ElementsTree(scope === "view" ? viewId : void 0);
16
+ const tree = useTree({
17
+ multiple: false
18
+ });
19
+ useEffect(() => {
20
+ ancestorsFqn(subject.id).reverse().forEach((id) => {
21
+ tree.expand(id);
22
+ });
23
+ tree.select(subject.id);
24
+ }, [subject.id]);
25
+ const theme = useComputedColorScheme();
26
+ return /* @__PURE__ */ jsxs(
27
+ Popover,
28
+ {
29
+ position: "bottom",
30
+ shadow: "md",
31
+ keepMounted: true,
32
+ withinPortal: false,
33
+ closeOnClickOutside: true,
34
+ clickOutsideEvents: ["pointerdown", "mousedown", "click"],
35
+ onOpen: () => {
36
+ setTimeout(() => {
37
+ var _a;
38
+ const item = (_a = viewport.current) == null ? void 0 : _a.querySelector(`[data-value="${subject.id}"]`);
39
+ console.log("item", item);
40
+ item == null ? void 0 : item.scrollIntoView({ behavior: "instant", block: "nearest" });
41
+ }, 100);
42
+ },
43
+ children: [
44
+ /* @__PURE__ */ jsx(PopoverTarget, { children: /* @__PURE__ */ jsx(
45
+ Button,
46
+ {
47
+ size: "xs",
48
+ variant: "light",
49
+ color: theme === "light" ? "dark" : "gray",
50
+ fw: "500",
51
+ maw: 250,
52
+ style: { padding: "0.25rem 0.75rem" },
53
+ rightSection: /* @__PURE__ */ jsx(IconSelector, { size: 16 }),
54
+ children: subject.title
55
+ }
56
+ ) }),
57
+ /* @__PURE__ */ jsx(PopoverDropdown, { p: 0, miw: 250, maw: 400, children: /* @__PURE__ */ jsx(ScrollAreaAutosize, { mah: "70vh", scrollbars: "y", type: "never", viewportRef: viewport, children: /* @__PURE__ */ jsx(
58
+ Tree,
59
+ {
60
+ allowRangeSelection: false,
61
+ selectOnClick: false,
62
+ tree,
63
+ data,
64
+ classNames: SelectElement_css,
65
+ levelOffset: 8,
66
+ styles: {
67
+ label: {
68
+ paddingTop: 5,
69
+ paddingBottom: 6
70
+ }
71
+ },
72
+ renderNode: ({ node, selected, expanded, elementProps, hasChildren }) => /* @__PURE__ */ jsxs(Group, { gap: 2, wrap: "nowrap", ...elementProps, py: "3", children: [
73
+ /* @__PURE__ */ jsx(
74
+ ActionIcon,
75
+ {
76
+ variant: "subtle",
77
+ size: 18,
78
+ c: "dimmed",
79
+ style: {
80
+ visibility: hasChildren ? "visible" : "hidden"
81
+ },
82
+ children: /* @__PURE__ */ jsx(
83
+ IconChevronRight,
84
+ {
85
+ stroke: 3.5,
86
+ style: {
87
+ transition: "transform 150ms ease",
88
+ transform: `rotate(${expanded ? "90deg" : "0"})`,
89
+ width: "80%"
90
+ }
91
+ }
92
+ )
93
+ }
94
+ ),
95
+ /* @__PURE__ */ jsx(
96
+ Box,
97
+ {
98
+ flex: "1 1 100%",
99
+ w: "100%",
100
+ onClick: (e) => {
101
+ e.stopPropagation();
102
+ onSelect(node.value);
103
+ tree.select(node.value);
104
+ tree.expand(node.value);
105
+ },
106
+ children: /* @__PURE__ */ jsx(
107
+ Text,
108
+ {
109
+ fz: "sm",
110
+ fw: selected ? "600" : "400",
111
+ truncate: "end",
112
+ children: node.label
113
+ }
114
+ )
115
+ }
116
+ )
117
+ ] })
118
+ }
119
+ ) }) })
120
+ ]
121
+ }
122
+ );
123
+ };
124
+ export {
125
+ SelectElement
126
+ };
@@ -0,0 +1,28 @@
1
+ import { AddEdgeData, AddNodeData } from '../../utils/types';
2
+ import { SharedFlowTypes } from '../shared/xyflow/_types';
3
+ export declare namespace RelationshipsOfFlowTypes {
4
+ /**
5
+ * Data that is exclusive to the relationships-of overlay. It will be merged into the node types
6
+ * provided by SharedFlowTypes.
7
+ */
8
+ type RelationshipsOfNodeData = {
9
+ depth?: number;
10
+ column: 'incomers' | 'subjects' | 'outgoers';
11
+ existsInCurrentView: boolean;
12
+ layoutId?: string;
13
+ };
14
+ export type ElementNode = AddNodeData<SharedFlowTypes.ElementNode, RelationshipsOfNodeData>;
15
+ export type CompoundNode = AddNodeData<SharedFlowTypes.CompoundNode, RelationshipsOfNodeData>;
16
+ export type NonEmptyNode = ElementNode | CompoundNode;
17
+ export type EmptyNode = AddNodeData<SharedFlowTypes.EmptyNode, RelationshipsOfNodeData>;
18
+ export type Node = NonEmptyNode | EmptyNode;
19
+ /**
20
+ * Data that is exclusive to the relationships-of overlay. It will be merged into the edge types
21
+ * provided by SharedFlowTypes.
22
+ */
23
+ type RelationshipsOfEdgeData = {
24
+ existsInCurrentView: boolean;
25
+ };
26
+ export type Edge = AddEdgeData<SharedFlowTypes.Edge, RelationshipsOfEdgeData>;
27
+ export {};
28
+ }
@@ -0,0 +1,22 @@
1
+ import { DiagramView, Fqn, LikeC4Model } from '@likec4/core';
2
+ import { RelationshipsOfFlowTypes } from './_types';
3
+ export declare const ZIndexes: {
4
+ empty: number;
5
+ compound: number;
6
+ edge: number;
7
+ element: number;
8
+ max: number;
9
+ };
10
+ export declare function useLayoutedRelationships(subjectId: Fqn, view: DiagramView, scope: 'global' | 'view'): {
11
+ viewIncludesSubject: boolean;
12
+ notIncludedRelations: number;
13
+ subject: LikeC4Model.Element;
14
+ nodes: RelationshipsOfFlowTypes.Node[];
15
+ edges: RelationshipsOfFlowTypes.Edge[];
16
+ bounds: {
17
+ x: number;
18
+ y: number;
19
+ width: number;
20
+ height: number;
21
+ };
22
+ };