@likec4/diagram 1.18.0 → 1.19.1

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,808 @@
1
+ import { nonNullable, getBBoxCenter, invariant, nonexhaustive, isStepEdgeId, getParallelStepsPrefix } from "@likec4/core";
2
+ import { applyNodeChanges, applyEdgeChanges, getViewportForBounds } from "@xyflow/react";
3
+ import { getNodeDimensions, getBoundsOfRects, boxToRect } from "@xyflow/system";
4
+ import { DEV } from "esm-env";
5
+ import { deepEqual, shallowEqual } from "fast-equals";
6
+ import { isNullish, entries, reduce, hasAtLeast, first, map, prop } from "remeda";
7
+ import { subscribeWithSelector, devtools } from "zustand/middleware";
8
+ import { shallow } from "zustand/shallow";
9
+ import { createWithEqualityFn } from "zustand/traditional";
10
+ import { VectorImpl, vector } from "../utils/vector.js";
11
+ import { MinZoom } from "../xyflow/const.js";
12
+ import { toDomPrecision, isSamePoint, bezierControlPoints, isInside } from "../xyflow/utils.js";
13
+ import { diagramViewToXYFlowData } from "./diagram-to-xyflow.js";
14
+ import { align } from "./diagramStore.layout.js";
15
+ const StringSet = Set;
16
+ const DEFAULT_PROPS = {
17
+ xyedges: [],
18
+ xynodes: [],
19
+ isDynamicView: false,
20
+ viewSyncDebounceTimeout: null,
21
+ initialized: false,
22
+ navigationHistoryIndex: 0,
23
+ viewportChanged: false,
24
+ activeOverlay: null,
25
+ activeWalkthrough: null,
26
+ focusedNodeId: null,
27
+ hoveredEdgeId: null,
28
+ lastClickedNodeId: null,
29
+ lastClickedEdgeId: null,
30
+ dimmed: new StringSet(),
31
+ lastOnNavigate: null
32
+ };
33
+ const noReplace = false;
34
+ let StoreDevId = 1;
35
+ const EmptyStringSet = new StringSet();
36
+ function createDiagramStore(props) {
37
+ const storeDevId = "DiagramStore" + String(StoreDevId++).padStart(2, "0");
38
+ const {
39
+ xynodes,
40
+ xyedges
41
+ } = diagramViewToXYFlowData(props.view, {
42
+ where: props.whereFilter,
43
+ draggable: props.nodesDraggable,
44
+ selectable: props.nodesSelectable
45
+ });
46
+ return createWithEqualityFn(
47
+ subscribeWithSelector(
48
+ devtools(
49
+ (set, get) => ({
50
+ ...DEFAULT_PROPS,
51
+ ...props,
52
+ storeDevId,
53
+ isDynamicView: props.view.__ === "dynamic",
54
+ xynodes,
55
+ xyedges,
56
+ navigationHistory: [{
57
+ viewId: props.view.id,
58
+ nodeId: null
59
+ }],
60
+ navigationHistoryIndex: 0,
61
+ onNodesChange: (changes) => {
62
+ set({
63
+ xynodes: applyNodeChanges(changes, get().xynodes)
64
+ });
65
+ },
66
+ onEdgesChange: (changes) => {
67
+ set({
68
+ xyedges: applyEdgeChanges(changes, get().xyedges)
69
+ });
70
+ },
71
+ updateView: (nextView) => {
72
+ let {
73
+ viewSyncDebounceTimeout,
74
+ xyflow,
75
+ xystore,
76
+ dimmed,
77
+ whereFilter,
78
+ view: current,
79
+ lastOnNavigate,
80
+ navigationHistory,
81
+ navigationHistoryIndex,
82
+ focusedNodeId,
83
+ lastClickedNodeId,
84
+ lastClickedEdgeId,
85
+ activeWalkthrough,
86
+ activeOverlay,
87
+ nodesDraggable,
88
+ nodesSelectable,
89
+ hoveredEdgeId,
90
+ xyedges: xyedges2,
91
+ xynodes: xynodes2
92
+ } = get();
93
+ if (viewSyncDebounceTimeout !== null) {
94
+ clearTimeout(viewSyncDebounceTimeout);
95
+ viewSyncDebounceTimeout = null;
96
+ }
97
+ const isSameView = current.id === nextView.id;
98
+ if (isSameView) {
99
+ const nodeIds = new StringSet(nextView.nodes.map((n) => n.id));
100
+ const edgeIds = new StringSet(nextView.edges.map((e) => e.id));
101
+ if (lastClickedNodeId && !nodeIds.has(lastClickedNodeId)) {
102
+ lastClickedNodeId = null;
103
+ }
104
+ if (focusedNodeId && !nodeIds.has(focusedNodeId)) {
105
+ focusedNodeId = null;
106
+ dimmed = EmptyStringSet;
107
+ }
108
+ if (lastClickedEdgeId && !edgeIds.has(lastClickedEdgeId)) {
109
+ lastClickedEdgeId = null;
110
+ }
111
+ if (hoveredEdgeId && !edgeIds.has(hoveredEdgeId)) {
112
+ hoveredEdgeId = null;
113
+ }
114
+ if (activeWalkthrough && !edgeIds.has(activeWalkthrough.stepId)) {
115
+ activeWalkthrough = null;
116
+ dimmed = EmptyStringSet;
117
+ }
118
+ if (dimmed.size > 0) {
119
+ let nextDimmed = new StringSet([...dimmed].filter((id) => nodeIds.has(id) || edgeIds.has(id)));
120
+ if (nextDimmed.size !== dimmed.size) {
121
+ dimmed = nextDimmed;
122
+ }
123
+ }
124
+ } else {
125
+ const stepCurrent = nonNullable(navigationHistory[navigationHistoryIndex]);
126
+ if (stepCurrent.viewId !== nextView.id) {
127
+ navigationHistory = [
128
+ ...navigationHistory.slice(0, navigationHistoryIndex + 1),
129
+ {
130
+ viewId: nextView.id,
131
+ nodeId: (lastOnNavigate == null ? void 0 : lastOnNavigate.fromNode) || null
132
+ }
133
+ ];
134
+ navigationHistoryIndex = navigationHistory.length - 1;
135
+ } else {
136
+ if (stepCurrent.nodeId) {
137
+ lastOnNavigate ?? (lastOnNavigate = {
138
+ fromView: current.id,
139
+ toView: nextView.id,
140
+ fromNode: stepCurrent.nodeId
141
+ });
142
+ }
143
+ }
144
+ if (lastOnNavigate && lastOnNavigate.toView !== nextView.id) {
145
+ lastOnNavigate = null;
146
+ }
147
+ const elTo = lastOnNavigate && nextView.nodes.find((n) => n.id === (lastOnNavigate == null ? void 0 : lastOnNavigate.fromNode));
148
+ const xynodeFrom = elTo && xyflow.getInternalNode(elTo.id);
149
+ if (!lastOnNavigate || isNullish(elTo) || isNullish(xynodeFrom)) {
150
+ const zoom = xyflow.getZoom();
151
+ const { x, y } = getBBoxCenter(nextView.bounds);
152
+ xyflow.setCenter(x, y, { zoom });
153
+ lastOnNavigate = null;
154
+ }
155
+ if (lastOnNavigate && !!elTo && !!xynodeFrom) {
156
+ const fromPos = xyflow.flowToScreenPosition({
157
+ x: xynodeFrom.internals.positionAbsolute.x,
158
+ // + dimensions.width / 2,
159
+ y: xynodeFrom.internals.positionAbsolute.y
160
+ // + dimensions.height / 2
161
+ }), toPos = xyflow.flowToScreenPosition({
162
+ x: elTo.position[0],
163
+ // + elFrom.width / 2,
164
+ y: elTo.position[1]
165
+ // + elFrom.height / 2
166
+ }), diff = {
167
+ x: toDomPrecision(fromPos.x - toPos.x),
168
+ y: toDomPrecision(fromPos.y - toPos.y)
169
+ };
170
+ xystore.getState().panBy(diff);
171
+ lastOnNavigate = null;
172
+ }
173
+ lastClickedEdgeId = null;
174
+ lastClickedNodeId = null;
175
+ hoveredEdgeId = null;
176
+ focusedNodeId = null;
177
+ activeWalkthrough = null;
178
+ activeOverlay = null;
179
+ dimmed = EmptyStringSet;
180
+ }
181
+ const update = diagramViewToXYFlowData(nextView, {
182
+ where: whereFilter,
183
+ draggable: nodesDraggable,
184
+ selectable: nodesSelectable
185
+ });
186
+ update.xynodes = update.xynodes.map((update2) => {
187
+ const existing = xynodes2.find((n) => n.id === update2.id);
188
+ if (existing && existing.type === update2.type && deepEqual(existing.parentId ?? null, update2.parentId ?? null)) {
189
+ if (existing.width === update2.width && existing.height === update2.height && deepEqual(existing.hidden ?? false, update2.hidden ?? false) && deepEqual(existing.position, update2.position) && deepEqual(existing.data, update2.data)) {
190
+ return existing;
191
+ }
192
+ return {
193
+ ...existing,
194
+ ...update2
195
+ };
196
+ }
197
+ return update2;
198
+ });
199
+ if (isSameView && !nextView.hasLayoutDrift) {
200
+ update.xyedges = update.xyedges.map((update2) => {
201
+ const existing = xyedges2.find((n) => n.id === update2.id);
202
+ if (existing) {
203
+ if (deepEqual(existing.hidden ?? false, update2.hidden ?? false) && deepEqual(existing.data.label, update2.data.label) && deepEqual(existing.data.controlPoints, update2.data.controlPoints) && deepEqual(existing.data.edge, update2.data.edge)) {
204
+ return existing;
205
+ }
206
+ return {
207
+ ...existing,
208
+ ...update2,
209
+ data: {
210
+ ...existing.data,
211
+ ...update2.data
212
+ }
213
+ };
214
+ }
215
+ return update2;
216
+ });
217
+ }
218
+ set(
219
+ {
220
+ isDynamicView: nextView.__ === "dynamic",
221
+ viewSyncDebounceTimeout,
222
+ view: nextView,
223
+ activeWalkthrough,
224
+ activeOverlay,
225
+ lastOnNavigate,
226
+ lastClickedNodeId,
227
+ lastClickedEdgeId,
228
+ focusedNodeId,
229
+ hoveredEdgeId,
230
+ navigationHistory,
231
+ navigationHistoryIndex,
232
+ dimmed,
233
+ xynodes: !isSameView || !shallowEqual(update.xynodes, xynodes2) ? update.xynodes : xynodes2,
234
+ xyedges: !isSameView || !shallowEqual(update.xyedges, xyedges2) ? update.xyedges : xyedges2
235
+ },
236
+ noReplace,
237
+ isSameView ? "update-view [same]" : "update-view [another]"
238
+ );
239
+ },
240
+ focusOnNode: (nodeId) => {
241
+ const { focusedNodeId, view, enableFocusMode } = get();
242
+ invariant(enableFocusMode, "focus mode is not enabled");
243
+ if (nodeId === false) {
244
+ set(
245
+ {
246
+ activeWalkthrough: null,
247
+ activeOverlay: null,
248
+ focusedNodeId: null,
249
+ dimmed: EmptyStringSet
250
+ },
251
+ noReplace,
252
+ `unfocus`
253
+ );
254
+ return;
255
+ }
256
+ if (nodeId !== focusedNodeId) {
257
+ const notDimmed = new StringSet([nodeId]);
258
+ const dimmed = new StringSet();
259
+ for (const edge of view.edges) {
260
+ if (edge.source === nodeId || edge.target === nodeId) {
261
+ notDimmed.add(edge.source);
262
+ notDimmed.add(edge.target);
263
+ } else {
264
+ dimmed.add(edge.id);
265
+ }
266
+ }
267
+ for (const node of view.nodes) {
268
+ if (notDimmed.has(node.id)) {
269
+ continue;
270
+ }
271
+ dimmed.add(node.id);
272
+ }
273
+ set(
274
+ {
275
+ activeWalkthrough: null,
276
+ activeOverlay: null,
277
+ focusedNodeId: nodeId,
278
+ dimmed
279
+ },
280
+ noReplace,
281
+ `focus on node: ${nodeId}`
282
+ );
283
+ }
284
+ },
285
+ setHoveredEdge: (edgeId) => {
286
+ if (edgeId !== get().hoveredEdgeId) {
287
+ set({ hoveredEdgeId: edgeId });
288
+ }
289
+ },
290
+ setLastClickedNode: (nodeId) => {
291
+ if (nodeId !== get().lastClickedNodeId) {
292
+ set({ lastClickedNodeId: nodeId });
293
+ }
294
+ },
295
+ setLastClickedEdge: (edgeId) => {
296
+ if (edgeId !== get().lastClickedEdgeId) {
297
+ set({ lastClickedEdgeId: edgeId });
298
+ }
299
+ },
300
+ resetFocusAndLastClicked: () => {
301
+ set(
302
+ {
303
+ activeWalkthrough: null,
304
+ activeOverlay: null,
305
+ focusedNodeId: null,
306
+ lastClickedNodeId: null,
307
+ lastClickedEdgeId: null,
308
+ dimmed: EmptyStringSet
309
+ },
310
+ noReplace,
311
+ "resetLastClicked"
312
+ );
313
+ get().xystore.getState().resetSelectedElements();
314
+ },
315
+ getElement: (fqn) => {
316
+ const { view } = get();
317
+ return view.nodes.find(({ id }) => id === fqn) ?? null;
318
+ },
319
+ isEditable: () => {
320
+ const { readonly, onChange } = get();
321
+ return !readonly && !!onChange;
322
+ },
323
+ triggerChangeElementStyle: (change) => {
324
+ if (DEV) {
325
+ console.debug("triggerChangeElementStyle", change);
326
+ }
327
+ const { view, updateView, onChange } = get();
328
+ let hasChanges = false;
329
+ const nodes = view.nodes.map((origin) => {
330
+ var _a, _b;
331
+ if (!change.targets.includes(origin.id)) {
332
+ return origin;
333
+ }
334
+ let element = origin;
335
+ for (const [key, value] of entries(change.style)) {
336
+ switch (key) {
337
+ case "shape":
338
+ if (value !== element.shape) {
339
+ element = {
340
+ ...element,
341
+ shape: value
342
+ };
343
+ }
344
+ break;
345
+ case "color":
346
+ if (value !== element.color) {
347
+ element = {
348
+ ...element,
349
+ color: value
350
+ };
351
+ }
352
+ break;
353
+ case "opacity":
354
+ if (value !== ((_a = element.style) == null ? void 0 : _a.opacity)) {
355
+ element = {
356
+ ...element,
357
+ style: {
358
+ ...element.style,
359
+ opacity: value
360
+ }
361
+ };
362
+ }
363
+ break;
364
+ case "border":
365
+ if (value !== ((_b = element.style) == null ? void 0 : _b.border)) {
366
+ element = {
367
+ ...element,
368
+ style: {
369
+ ...element.style,
370
+ border: value
371
+ }
372
+ };
373
+ }
374
+ break;
375
+ default:
376
+ nonexhaustive(key);
377
+ }
378
+ }
379
+ if (element !== origin) {
380
+ hasChanges = true;
381
+ return element;
382
+ }
383
+ return origin;
384
+ });
385
+ if (hasChanges) {
386
+ updateView({
387
+ ...view,
388
+ nodes
389
+ });
390
+ }
391
+ onChange == null ? void 0 : onChange({ change });
392
+ },
393
+ cancelSaveManualLayout: () => {
394
+ let { viewSyncDebounceTimeout } = get();
395
+ if (viewSyncDebounceTimeout !== null) {
396
+ clearTimeout(viewSyncDebounceTimeout);
397
+ set({ viewSyncDebounceTimeout: null });
398
+ return true;
399
+ }
400
+ return false;
401
+ },
402
+ triggerSaveManualLayout: () => {
403
+ const { xyflow, view, onChange, xystore, viewSyncDebounceTimeout } = get();
404
+ if (viewSyncDebounceTimeout !== null) {
405
+ clearTimeout(viewSyncDebounceTimeout);
406
+ set({ viewSyncDebounceTimeout: null });
407
+ }
408
+ const { nodeLookup } = xystore.getState();
409
+ const movedNodes = new StringSet();
410
+ let bounds = {
411
+ x: 0,
412
+ y: 0,
413
+ width: 1,
414
+ height: 1
415
+ };
416
+ const nodes = reduce([...nodeLookup.values()], (acc, node) => {
417
+ const dimensions = getNodeDimensions(node);
418
+ if (!isSamePoint(node.internals.positionAbsolute, node.data.element.position)) {
419
+ movedNodes.add(node.id);
420
+ }
421
+ const rect = acc[node.data.fqn] = {
422
+ isCompound: node.data.element.children.length > 0,
423
+ x: Math.floor(node.internals.positionAbsolute.x),
424
+ y: Math.floor(node.internals.positionAbsolute.y),
425
+ width: Math.ceil(dimensions.width),
426
+ height: Math.ceil(dimensions.height)
427
+ };
428
+ bounds = getBoundsOfRects(bounds, rect);
429
+ return acc;
430
+ }, {});
431
+ const edges = reduce(xyflow.getEdges(), (acc, { source, target, data }) => {
432
+ var _a;
433
+ let controlPoints = data.controlPoints ?? [];
434
+ const sourceOrTargetMoved = movedNodes.has(source) || movedNodes.has(target);
435
+ if (controlPoints.length === 0 && sourceOrTargetMoved) {
436
+ controlPoints = bezierControlPoints(data.edge);
437
+ }
438
+ if (data.edge.points.length === 0 && controlPoints.length === 0) {
439
+ return acc;
440
+ }
441
+ const _updated = acc[data.edge.id] = {
442
+ points: data.edge.points
443
+ };
444
+ if ((_a = data.label) == null ? void 0 : _a.bbox) {
445
+ _updated.labelBBox = data.label.bbox;
446
+ }
447
+ if (data.edge.labelBBox) {
448
+ _updated.labelBBox ?? (_updated.labelBBox = data.edge.labelBBox);
449
+ }
450
+ if (hasAtLeast(controlPoints, 1)) {
451
+ _updated.controlPoints = controlPoints;
452
+ }
453
+ if (!sourceOrTargetMoved && data.edge.dotpos) {
454
+ _updated.dotpos = data.edge.dotpos;
455
+ }
456
+ const allX = [
457
+ ...data.edge.points.map((p) => p[0]),
458
+ ...controlPoints.map((p) => p.x),
459
+ ..._updated.labelBBox ? [_updated.labelBBox.x, _updated.labelBBox.x + _updated.labelBBox.width] : []
460
+ ];
461
+ const allY = [
462
+ ...data.edge.points.map((p) => p[1]),
463
+ ...controlPoints.map((p) => p.y),
464
+ ..._updated.labelBBox ? [_updated.labelBBox.y, _updated.labelBBox.y + _updated.labelBBox.height] : []
465
+ ];
466
+ const rect = boxToRect({
467
+ x: Math.floor(Math.min(...allX)),
468
+ y: Math.floor(Math.min(...allY)),
469
+ x2: Math.ceil(Math.max(...allX)),
470
+ y2: Math.ceil(Math.max(...allY))
471
+ });
472
+ bounds = getBoundsOfRects(bounds, rect);
473
+ return acc;
474
+ }, {});
475
+ const change = {
476
+ op: "save-manual-layout",
477
+ layout: {
478
+ hash: view.hash,
479
+ autoLayout: view.autoLayout,
480
+ nodes,
481
+ edges,
482
+ ...bounds
483
+ }
484
+ };
485
+ if (DEV) {
486
+ console.debug("triggerSaveManualLayout", change);
487
+ }
488
+ if (!isInside(bounds, view.bounds)) {
489
+ set(
490
+ {
491
+ view: {
492
+ ...view,
493
+ bounds
494
+ }
495
+ },
496
+ noReplace,
497
+ "update view bounds"
498
+ );
499
+ }
500
+ onChange == null ? void 0 : onChange({ change });
501
+ },
502
+ scheduleSaveManualLayout: () => {
503
+ clearTimeout(get().viewSyncDebounceTimeout ?? void 0);
504
+ set(
505
+ {
506
+ viewSyncDebounceTimeout: setTimeout(() => {
507
+ get().triggerSaveManualLayout();
508
+ }, 1e3)
509
+ // explicit typecast to number to suppress TS error in astro build
510
+ },
511
+ noReplace,
512
+ "debounce sync state"
513
+ );
514
+ },
515
+ triggerOnNavigateTo: (xynodeId, event) => {
516
+ const { view, xynodes: xynodes2, onNavigateTo, cancelSaveManualLayout } = get();
517
+ if (!onNavigateTo) {
518
+ return;
519
+ }
520
+ const xynode = xynodes2.find(({ id }) => id === xynodeId);
521
+ invariant(xynode, `xynode not found: ${xynodeId}`);
522
+ const element = xynode.data.element;
523
+ invariant(element == null ? void 0 : element.navigateTo, `node is not navigable: ${xynodeId}`);
524
+ cancelSaveManualLayout();
525
+ set(
526
+ {
527
+ lastClickedNodeId: xynodeId,
528
+ lastOnNavigate: {
529
+ fromView: view.id,
530
+ toView: element.navigateTo,
531
+ fromNode: element.id
532
+ }
533
+ },
534
+ noReplace,
535
+ "triggerOnNavigateTo"
536
+ );
537
+ onNavigateTo(
538
+ element.navigateTo,
539
+ event,
540
+ element
541
+ );
542
+ },
543
+ goBack: () => {
544
+ const { navigationHistory, navigationHistoryIndex, onNavigateTo } = get();
545
+ const { viewId, nodeId } = nonNullable(navigationHistory[navigationHistoryIndex]);
546
+ const stepBack = navigationHistoryIndex > 0 && navigationHistory[navigationHistoryIndex - 1] || null;
547
+ if (stepBack && onNavigateTo) {
548
+ set(
549
+ {
550
+ lastClickedEdgeId: null,
551
+ lastClickedNodeId: null,
552
+ navigationHistoryIndex: navigationHistoryIndex - 1,
553
+ lastOnNavigate: nodeId ? {
554
+ fromView: viewId,
555
+ toView: stepBack.viewId,
556
+ fromNode: nodeId
557
+ } : null
558
+ },
559
+ noReplace,
560
+ "goBack"
561
+ );
562
+ onNavigateTo(stepBack.viewId);
563
+ }
564
+ },
565
+ goForward: () => {
566
+ const { navigationHistory, navigationHistoryIndex, onNavigateTo } = get();
567
+ const { viewId } = nonNullable(navigationHistory[navigationHistoryIndex]);
568
+ const stepForward = navigationHistoryIndex < navigationHistory.length - 1 ? navigationHistory[navigationHistoryIndex + 1] : null;
569
+ if (stepForward && onNavigateTo) {
570
+ set(
571
+ {
572
+ lastClickedEdgeId: null,
573
+ lastClickedNodeId: null,
574
+ navigationHistoryIndex: navigationHistoryIndex + 1,
575
+ lastOnNavigate: stepForward.nodeId ? {
576
+ fromView: viewId,
577
+ toView: stepForward.viewId,
578
+ fromNode: stepForward.nodeId
579
+ } : null
580
+ },
581
+ noReplace,
582
+ "goForward"
583
+ );
584
+ onNavigateTo(stepForward.viewId);
585
+ }
586
+ },
587
+ onOpenSourceView: () => {
588
+ const { view, onOpenSource } = get();
589
+ onOpenSource == null ? void 0 : onOpenSource({
590
+ view: view.id
591
+ });
592
+ },
593
+ openOverlay: (overlay) => {
594
+ if (deepEqual(overlay, get().activeOverlay)) {
595
+ return;
596
+ }
597
+ if ("elementDetails" in overlay) {
598
+ const diagramNode = get().view.nodes.find(({ id }) => id === overlay.elementDetails);
599
+ if (!diagramNode || !diagramNode.modelRef) {
600
+ get().closeOverlay();
601
+ return;
602
+ }
603
+ }
604
+ set(
605
+ {
606
+ activeWalkthrough: null,
607
+ activeOverlay: overlay
608
+ },
609
+ noReplace,
610
+ "openOverlay"
611
+ );
612
+ },
613
+ closeOverlay: () => {
614
+ if (get().activeOverlay !== null) {
615
+ set(
616
+ {
617
+ activeOverlay: null
618
+ },
619
+ noReplace,
620
+ "closeOverlay"
621
+ );
622
+ }
623
+ },
624
+ fitDiagram: (duration = 500) => {
625
+ const { fitViewPadding, view, xystore } = get();
626
+ const { width, height, panZoom, transform } = xystore.getState();
627
+ const bounds = view.bounds;
628
+ const maxZoom = Math.max(1, transform[2]);
629
+ const viewport = getViewportForBounds(bounds, width, height, MinZoom, maxZoom, fitViewPadding);
630
+ panZoom == null ? void 0 : panZoom.setViewport(viewport, duration > 0 ? { duration } : void 0);
631
+ },
632
+ nextDynamicStep: (increment = 1) => {
633
+ const { activeWalkthrough, xyedges: xyedges2, activateWalkthrough } = get();
634
+ const stepId = activeWalkthrough == null ? void 0 : activeWalkthrough.stepId;
635
+ let nextStep;
636
+ if (stepId) {
637
+ const currentIndex = xyedges2.findIndex(({ id }) => id === stepId);
638
+ const nextIndex = currentIndex + increment;
639
+ nextStep = xyedges2[nextIndex];
640
+ } else {
641
+ nextStep = first(xyedges2);
642
+ }
643
+ if (nextStep) {
644
+ activateWalkthrough(nextStep.data.edge.id);
645
+ return;
646
+ }
647
+ },
648
+ activateWalkthrough: (step) => {
649
+ const stepId = typeof step === "string" ? step : step.data.edge.id;
650
+ invariant(isStepEdgeId(stepId), `stepId ${stepId} is not a step edge id`);
651
+ let {
652
+ isDynamicView,
653
+ xyflow,
654
+ xyedges: xyedges2,
655
+ xystore,
656
+ fitViewPadding,
657
+ activeWalkthrough
658
+ } = get();
659
+ invariant(isDynamicView, "view is not dynamic");
660
+ const edge = typeof step === "string" ? xyedges2.find(({ id }) => id === stepId) : step;
661
+ invariant(edge, `edge not found: ${stepId}`);
662
+ const currentIndex = xyedges2.findIndex(({ id }) => id === stepId);
663
+ activeWalkthrough = {
664
+ stepId,
665
+ hasPrevious: currentIndex > 0,
666
+ hasNext: currentIndex < xyedges2.length - 1,
667
+ parallelPrefix: getParallelStepsPrefix(stepId)
668
+ };
669
+ const dimmed = new StringSet(
670
+ xyedges2.filter(
671
+ ({ id }) => id !== stepId && !(activeWalkthrough.parallelPrefix && id.startsWith(activeWalkthrough.parallelPrefix))
672
+ ).map(({ id }) => id)
673
+ );
674
+ const selected = [];
675
+ for (const n of xyflow.getNodes()) {
676
+ if (n.id === edge.source || n.id === edge.target) {
677
+ selected.push(n);
678
+ continue;
679
+ }
680
+ dimmed.add(n.id);
681
+ }
682
+ const { fitView, transform } = xystore.getState();
683
+ fitView({
684
+ duration: 400,
685
+ includeHiddenNodes: true,
686
+ maxZoom: Math.max(1, transform[2]),
687
+ minZoom: MinZoom,
688
+ padding: Math.max(fitViewPadding, 0.2),
689
+ nodes: selected
690
+ });
691
+ set(
692
+ {
693
+ focusedNodeId: null,
694
+ activeWalkthrough,
695
+ dimmed
696
+ },
697
+ noReplace,
698
+ "activateWalkthrough"
699
+ );
700
+ },
701
+ stopWalkthrough: () => {
702
+ if (get().activeWalkthrough !== null) {
703
+ set(
704
+ {
705
+ activeWalkthrough: null,
706
+ focusedNodeId: null,
707
+ dimmed: EmptyStringSet
708
+ },
709
+ noReplace,
710
+ "stopWalkthrough"
711
+ );
712
+ get().fitDiagram();
713
+ }
714
+ },
715
+ onInit: (instance) => {
716
+ const { xyflow, initialized, fitViewEnabled, fitDiagram } = get();
717
+ if (!initialized || xyflow !== instance) {
718
+ if (fitViewEnabled) {
719
+ fitDiagram(0);
720
+ }
721
+ set(
722
+ {
723
+ xyflow: instance,
724
+ initialized: true
725
+ },
726
+ noReplace,
727
+ "onInit"
728
+ );
729
+ }
730
+ },
731
+ highlightByElementNotation: (notation, onlyOfKind) => {
732
+ const { xynodes: xynodes2, xyedges: xyedges2 } = get();
733
+ const dimmed = new StringSet(map(xyedges2, prop("id")));
734
+ xynodes2.forEach(({ id, data }) => {
735
+ const node = data.element;
736
+ if (node.shape !== notation.shape || node.color !== notation.color || !notation.kinds.includes(node.kind) || onlyOfKind && node.kind !== onlyOfKind) {
737
+ dimmed.add(id);
738
+ }
739
+ });
740
+ set({ dimmed }, noReplace, "highlightByElementNotation");
741
+ },
742
+ resetEdgeControlPoints: () => {
743
+ const { xyflow, scheduleSaveManualLayout, xynodes: xynodes2, xyedges: xyedges2 } = get();
744
+ xyedges2.forEach((edge) => {
745
+ xyflow.updateEdgeData(edge.id, {
746
+ controlPoints: getControlPointForEdge(edge)
747
+ });
748
+ });
749
+ scheduleSaveManualLayout();
750
+ function getNodeCenter(node, nodes) {
751
+ const dimensions = vector({ x: node.width || 0, y: node.height || 0 });
752
+ let position = vector(node.position).add(dimensions.mul(0.5));
753
+ let currentNode = node;
754
+ do {
755
+ const parent = currentNode.parentId && nodes.find((x) => x.id == currentNode.parentId);
756
+ if (!parent) {
757
+ break;
758
+ }
759
+ currentNode = parent;
760
+ position = position.add(parent.position);
761
+ } while (true);
762
+ return position;
763
+ }
764
+ function getControlPointForEdge(edge) {
765
+ const source = xynodes2.find((x) => x.id == edge.source);
766
+ const target = xynodes2.find((x) => x.id == edge.target);
767
+ if (!source || !target) {
768
+ return [];
769
+ }
770
+ const sourceCenter = getNodeCenter(source, xynodes2);
771
+ const targetCenter = getNodeCenter(target, xynodes2);
772
+ if (!sourceCenter || !targetCenter) {
773
+ return [];
774
+ }
775
+ if (source == target) {
776
+ const loopSize = 80;
777
+ const centerOfTopBoundary = new VectorImpl(0, source.height || 0).mul(-0.5).add(sourceCenter);
778
+ return [
779
+ centerOfTopBoundary.add(new VectorImpl(-loopSize / 2.5, -loopSize)),
780
+ centerOfTopBoundary.add(new VectorImpl(loopSize / 2.5, -loopSize))
781
+ ];
782
+ }
783
+ const sourceToTargetVector = targetCenter.sub(sourceCenter);
784
+ const sourceBorderPoint = getBorderPointOnVector(source, sourceCenter, sourceToTargetVector);
785
+ const targetBorderPoint = getBorderPointOnVector(target, targetCenter, sourceToTargetVector.mul(-1));
786
+ return [sourceBorderPoint.add(targetBorderPoint.sub(sourceBorderPoint).mul(0.3))];
787
+ }
788
+ function getBorderPointOnVector(node, nodeCenter, v) {
789
+ const xScale = (node.width || 0) / 2 / v.x;
790
+ const yScale = (node.height || 0) / 2 / v.y;
791
+ const scale = Math.min(Math.abs(xScale), Math.abs(yScale));
792
+ return vector(v).mul(scale).add(nodeCenter);
793
+ }
794
+ },
795
+ align: align(get)
796
+ }),
797
+ {
798
+ name: `${storeDevId} - ${props.view.id}`,
799
+ enabled: DEV
800
+ }
801
+ )
802
+ ),
803
+ shallow
804
+ );
805
+ }
806
+ export {
807
+ createDiagramStore
808
+ };