react-cosmos-diagram 0.6.0 → 0.7.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 (266) hide show
  1. package/dist/esm/components/A11yDescriptions/index.d.ts.map +1 -1
  2. package/dist/esm/components/Background/LinePath.d.ts.map +1 -1
  3. package/dist/esm/components/Background/index.d.ts.map +1 -1
  4. package/dist/esm/components/Background/type.d.ts.map +1 -1
  5. package/dist/esm/components/DragBox/index.d.ts +1 -1
  6. package/dist/esm/components/DragBox/index.d.ts.map +1 -1
  7. package/dist/esm/components/Edges/Anchor.d.ts +1 -1
  8. package/dist/esm/components/Edges/Anchor.d.ts.map +1 -1
  9. package/dist/esm/components/Edges/BaseEdge.d.ts.map +1 -1
  10. package/dist/esm/components/Edges/BezierEdge.d.ts +2 -13
  11. package/dist/esm/components/Edges/BezierEdge.d.ts.map +1 -1
  12. package/dist/esm/components/Edges/EdgeLabel.d.ts.map +1 -1
  13. package/dist/esm/components/Edges/EdgeWrapper/index.d.ts.map +1 -1
  14. package/dist/esm/components/Edges/EdgeWrapper/type.d.ts +3 -10
  15. package/dist/esm/components/Edges/EdgeWrapper/type.d.ts.map +1 -1
  16. package/dist/esm/components/Edges/StepEdge.d.ts +2 -22
  17. package/dist/esm/components/Edges/StepEdge.d.ts.map +1 -1
  18. package/dist/esm/components/Edges/StraightEdge.d.ts +0 -7
  19. package/dist/esm/components/Edges/StraightEdge.d.ts.map +1 -1
  20. package/dist/esm/components/Edges/type.d.ts +8 -35
  21. package/dist/esm/components/Edges/type.d.ts.map +1 -1
  22. package/dist/esm/components/Node/NodeWrapper/index.d.ts +3 -3
  23. package/dist/esm/components/Node/NodeWrapper/index.d.ts.map +1 -1
  24. package/dist/esm/components/Node/NodeWrapper/type.d.ts +4 -1
  25. package/dist/esm/components/Node/NodeWrapper/type.d.ts.map +1 -1
  26. package/dist/esm/components/Node/index.d.ts.map +1 -1
  27. package/dist/esm/components/Node/type.d.ts +4 -36
  28. package/dist/esm/components/Node/type.d.ts.map +1 -1
  29. package/dist/esm/components/Node/utils.d.ts +0 -3
  30. package/dist/esm/components/Node/utils.d.ts.map +1 -1
  31. package/dist/esm/components/Port/index.d.ts +2 -2
  32. package/dist/esm/components/Port/index.d.ts.map +1 -1
  33. package/dist/esm/components/ReactDiagramProvider/index.d.ts.map +1 -1
  34. package/dist/esm/components/ReactDiagramProvider/type.d.ts +10 -8
  35. package/dist/esm/components/ReactDiagramProvider/type.d.ts.map +1 -1
  36. package/dist/esm/components/SelectionBox/index.d.ts +1 -1
  37. package/dist/esm/components/SelectionBox/index.d.ts.map +1 -1
  38. package/dist/esm/components/SelectionBox/type.d.ts +1 -1
  39. package/dist/esm/components/SelectionBox/type.d.ts.map +1 -1
  40. package/dist/esm/components/StoreUpdater/index.d.ts +2 -2
  41. package/dist/esm/components/StoreUpdater/index.d.ts.map +1 -1
  42. package/dist/esm/container/ConnectionLineRenderer/ConnectionPath.d.ts +1 -1
  43. package/dist/esm/container/ConnectionLineRenderer/ConnectionPath.d.ts.map +1 -1
  44. package/dist/esm/container/ConnectionLineRenderer/index.d.ts.map +1 -1
  45. package/dist/esm/container/ConnectionLineRenderer/type.d.ts +2 -2
  46. package/dist/esm/container/ConnectionLineRenderer/type.d.ts.map +1 -1
  47. package/dist/esm/container/DiagramRenderer/index.d.ts +1 -1
  48. package/dist/esm/container/DiagramRenderer/index.d.ts.map +1 -1
  49. package/dist/esm/container/DragSelection/index.d.ts +2 -2
  50. package/dist/esm/container/DragSelection/index.d.ts.map +1 -1
  51. package/dist/esm/container/EdgeRenderer/MarkerComponent.d.ts.map +1 -1
  52. package/dist/esm/container/EdgeRenderer/MarkerSymbols.d.ts +1 -1
  53. package/dist/esm/container/EdgeRenderer/MarkerSymbols.d.ts.map +1 -1
  54. package/dist/esm/container/EdgeRenderer/index.d.ts.map +1 -1
  55. package/dist/esm/container/EdgeRenderer/type.d.ts.map +1 -1
  56. package/dist/esm/container/EdgeRenderer/utils.d.ts +3 -3
  57. package/dist/esm/container/EdgeRenderer/utils.d.ts.map +1 -1
  58. package/dist/esm/container/NodeRenderer/index.d.ts +1 -1
  59. package/dist/esm/container/NodeRenderer/index.d.ts.map +1 -1
  60. package/dist/esm/container/NodeRenderer/type.d.ts +2 -2
  61. package/dist/esm/container/NodeRenderer/type.d.ts.map +1 -1
  62. package/dist/esm/container/NodeRenderer/utils.d.ts.map +1 -1
  63. package/dist/esm/container/Pane/index.d.ts +2 -1
  64. package/dist/esm/container/Pane/index.d.ts.map +1 -1
  65. package/dist/esm/container/ReactDiagram/DiagramView.d.ts +2 -2
  66. package/dist/esm/container/ReactDiagram/DiagramView.d.ts.map +1 -1
  67. package/dist/esm/container/ReactDiagram/Wrapper.d.ts.map +1 -1
  68. package/dist/esm/container/ReactDiagram/index.d.ts +19 -20
  69. package/dist/esm/container/ReactDiagram/index.d.ts.map +1 -1
  70. package/dist/esm/container/Viewport/index.d.ts.map +1 -1
  71. package/dist/esm/contexts/NodeIdContext.d.ts.map +1 -1
  72. package/dist/esm/contexts/{RFStoreContext.d.ts → RCDStoreContext.d.ts} +1 -1
  73. package/dist/esm/contexts/RCDStoreContext.d.ts.map +1 -0
  74. package/dist/esm/hooks/useDrag.d.ts +9 -0
  75. package/dist/esm/hooks/useDrag.d.ts.map +1 -0
  76. package/dist/esm/hooks/useDragSelectionKeyPress.d.ts +4 -0
  77. package/dist/esm/hooks/useDragSelectionKeyPress.d.ts.map +1 -0
  78. package/dist/esm/hooks/useGlobalKeyHandler.d.ts +1 -1
  79. package/dist/esm/hooks/useGlobalKeyHandler.d.ts.map +1 -1
  80. package/dist/esm/hooks/useNodeOrEdgeTypes.d.ts.map +1 -1
  81. package/dist/esm/hooks/useNodesEdgesState/index.d.ts +2 -2
  82. package/dist/esm/hooks/useNodesEdgesState/index.d.ts.map +1 -1
  83. package/dist/esm/hooks/useNodesEdgesState/type.d.ts +7 -7
  84. package/dist/esm/hooks/useNodesEdgesState/type.d.ts.map +1 -1
  85. package/dist/esm/hooks/useStore.d.ts.map +1 -1
  86. package/dist/esm/hooks/useVisibleNodes.d.ts +1 -1
  87. package/dist/esm/hooks/useVisibleNodes.d.ts.map +1 -1
  88. package/dist/esm/index.d.ts +7 -5
  89. package/dist/esm/index.d.ts.map +1 -1
  90. package/dist/esm/index.js +282 -1285
  91. package/dist/esm/store/index.d.ts +2 -2
  92. package/dist/esm/store/index.d.ts.map +1 -1
  93. package/dist/esm/store/initialState.d.ts +1 -1
  94. package/dist/esm/store/initialState.d.ts.map +1 -1
  95. package/dist/esm/store/type.d.ts +0 -2
  96. package/dist/esm/store/type.d.ts.map +1 -1
  97. package/dist/esm/store/utils.d.ts +4 -4
  98. package/dist/esm/store/utils.d.ts.map +1 -1
  99. package/dist/esm/types/core.d.ts +3 -4
  100. package/dist/esm/types/core.d.ts.map +1 -1
  101. package/dist/esm/types/general.d.ts +1 -21
  102. package/dist/esm/types/general.d.ts.map +1 -1
  103. package/dist/esm/types/index.d.ts +0 -1
  104. package/dist/esm/types/index.d.ts.map +1 -1
  105. package/dist/esm/utils/changes.d.ts +2 -2
  106. package/dist/esm/utils/changes.d.ts.map +1 -1
  107. package/dist/esm/utils/deepEqual.d.ts.map +1 -1
  108. package/dist/esm/utils/index.d.ts +2 -21
  109. package/dist/esm/utils/index.d.ts.map +1 -1
  110. package/dist/style.css +13 -12
  111. package/dist/umd/components/A11yDescriptions/index.d.ts.map +1 -1
  112. package/dist/umd/components/Background/LinePath.d.ts.map +1 -1
  113. package/dist/umd/components/Background/index.d.ts.map +1 -1
  114. package/dist/umd/components/Background/type.d.ts.map +1 -1
  115. package/dist/umd/components/DragBox/index.d.ts +1 -1
  116. package/dist/umd/components/DragBox/index.d.ts.map +1 -1
  117. package/dist/umd/components/Edges/Anchor.d.ts +1 -1
  118. package/dist/umd/components/Edges/Anchor.d.ts.map +1 -1
  119. package/dist/umd/components/Edges/BaseEdge.d.ts.map +1 -1
  120. package/dist/umd/components/Edges/BezierEdge.d.ts +2 -13
  121. package/dist/umd/components/Edges/BezierEdge.d.ts.map +1 -1
  122. package/dist/umd/components/Edges/EdgeLabel.d.ts.map +1 -1
  123. package/dist/umd/components/Edges/EdgeWrapper/index.d.ts.map +1 -1
  124. package/dist/umd/components/Edges/EdgeWrapper/type.d.ts +3 -10
  125. package/dist/umd/components/Edges/EdgeWrapper/type.d.ts.map +1 -1
  126. package/dist/umd/components/Edges/StepEdge.d.ts +2 -22
  127. package/dist/umd/components/Edges/StepEdge.d.ts.map +1 -1
  128. package/dist/umd/components/Edges/StraightEdge.d.ts +0 -7
  129. package/dist/umd/components/Edges/StraightEdge.d.ts.map +1 -1
  130. package/dist/umd/components/Edges/type.d.ts +8 -35
  131. package/dist/umd/components/Edges/type.d.ts.map +1 -1
  132. package/dist/umd/components/Node/NodeWrapper/index.d.ts +3 -3
  133. package/dist/umd/components/Node/NodeWrapper/index.d.ts.map +1 -1
  134. package/dist/umd/components/Node/NodeWrapper/type.d.ts +4 -1
  135. package/dist/umd/components/Node/NodeWrapper/type.d.ts.map +1 -1
  136. package/dist/umd/components/Node/index.d.ts.map +1 -1
  137. package/dist/umd/components/Node/type.d.ts +4 -36
  138. package/dist/umd/components/Node/type.d.ts.map +1 -1
  139. package/dist/umd/components/Node/utils.d.ts +0 -3
  140. package/dist/umd/components/Node/utils.d.ts.map +1 -1
  141. package/dist/umd/components/Port/index.d.ts +2 -2
  142. package/dist/umd/components/Port/index.d.ts.map +1 -1
  143. package/dist/umd/components/ReactDiagramProvider/index.d.ts.map +1 -1
  144. package/dist/umd/components/ReactDiagramProvider/type.d.ts +10 -8
  145. package/dist/umd/components/ReactDiagramProvider/type.d.ts.map +1 -1
  146. package/dist/umd/components/SelectionBox/index.d.ts +1 -1
  147. package/dist/umd/components/SelectionBox/index.d.ts.map +1 -1
  148. package/dist/umd/components/SelectionBox/type.d.ts +1 -1
  149. package/dist/umd/components/SelectionBox/type.d.ts.map +1 -1
  150. package/dist/umd/components/StoreUpdater/index.d.ts +2 -2
  151. package/dist/umd/components/StoreUpdater/index.d.ts.map +1 -1
  152. package/dist/umd/container/ConnectionLineRenderer/ConnectionPath.d.ts +1 -1
  153. package/dist/umd/container/ConnectionLineRenderer/ConnectionPath.d.ts.map +1 -1
  154. package/dist/umd/container/ConnectionLineRenderer/index.d.ts.map +1 -1
  155. package/dist/umd/container/ConnectionLineRenderer/type.d.ts +2 -2
  156. package/dist/umd/container/ConnectionLineRenderer/type.d.ts.map +1 -1
  157. package/dist/umd/container/DiagramRenderer/index.d.ts +1 -1
  158. package/dist/umd/container/DiagramRenderer/index.d.ts.map +1 -1
  159. package/dist/umd/container/DragSelection/index.d.ts +2 -2
  160. package/dist/umd/container/DragSelection/index.d.ts.map +1 -1
  161. package/dist/umd/container/EdgeRenderer/MarkerComponent.d.ts.map +1 -1
  162. package/dist/umd/container/EdgeRenderer/MarkerSymbols.d.ts +1 -1
  163. package/dist/umd/container/EdgeRenderer/MarkerSymbols.d.ts.map +1 -1
  164. package/dist/umd/container/EdgeRenderer/index.d.ts.map +1 -1
  165. package/dist/umd/container/EdgeRenderer/type.d.ts.map +1 -1
  166. package/dist/umd/container/EdgeRenderer/utils.d.ts +3 -3
  167. package/dist/umd/container/EdgeRenderer/utils.d.ts.map +1 -1
  168. package/dist/umd/container/NodeRenderer/index.d.ts +1 -1
  169. package/dist/umd/container/NodeRenderer/index.d.ts.map +1 -1
  170. package/dist/umd/container/NodeRenderer/type.d.ts +2 -2
  171. package/dist/umd/container/NodeRenderer/type.d.ts.map +1 -1
  172. package/dist/umd/container/NodeRenderer/utils.d.ts.map +1 -1
  173. package/dist/umd/container/Pane/index.d.ts +2 -1
  174. package/dist/umd/container/Pane/index.d.ts.map +1 -1
  175. package/dist/umd/container/ReactDiagram/DiagramView.d.ts +2 -2
  176. package/dist/umd/container/ReactDiagram/DiagramView.d.ts.map +1 -1
  177. package/dist/umd/container/ReactDiagram/Wrapper.d.ts.map +1 -1
  178. package/dist/umd/container/ReactDiagram/index.d.ts +19 -20
  179. package/dist/umd/container/ReactDiagram/index.d.ts.map +1 -1
  180. package/dist/umd/container/Viewport/index.d.ts.map +1 -1
  181. package/dist/umd/contexts/NodeIdContext.d.ts.map +1 -1
  182. package/dist/umd/contexts/{RFStoreContext.d.ts → RCDStoreContext.d.ts} +1 -1
  183. package/dist/umd/contexts/RCDStoreContext.d.ts.map +1 -0
  184. package/dist/umd/hooks/useDrag.d.ts +9 -0
  185. package/dist/umd/hooks/useDrag.d.ts.map +1 -0
  186. package/dist/umd/hooks/useDragSelectionKeyPress.d.ts +4 -0
  187. package/dist/umd/hooks/useDragSelectionKeyPress.d.ts.map +1 -0
  188. package/dist/umd/hooks/useGlobalKeyHandler.d.ts +1 -1
  189. package/dist/umd/hooks/useGlobalKeyHandler.d.ts.map +1 -1
  190. package/dist/umd/hooks/useNodeOrEdgeTypes.d.ts.map +1 -1
  191. package/dist/umd/hooks/useNodesEdgesState/index.d.ts +2 -2
  192. package/dist/umd/hooks/useNodesEdgesState/index.d.ts.map +1 -1
  193. package/dist/umd/hooks/useNodesEdgesState/type.d.ts +7 -7
  194. package/dist/umd/hooks/useNodesEdgesState/type.d.ts.map +1 -1
  195. package/dist/umd/hooks/useStore.d.ts.map +1 -1
  196. package/dist/umd/hooks/useVisibleNodes.d.ts +1 -1
  197. package/dist/umd/hooks/useVisibleNodes.d.ts.map +1 -1
  198. package/dist/umd/index.d.ts +7 -5
  199. package/dist/umd/index.d.ts.map +1 -1
  200. package/dist/umd/index.js +2 -2
  201. package/dist/umd/store/index.d.ts +2 -2
  202. package/dist/umd/store/index.d.ts.map +1 -1
  203. package/dist/umd/store/initialState.d.ts +1 -1
  204. package/dist/umd/store/initialState.d.ts.map +1 -1
  205. package/dist/umd/store/type.d.ts +0 -2
  206. package/dist/umd/store/type.d.ts.map +1 -1
  207. package/dist/umd/store/utils.d.ts +4 -4
  208. package/dist/umd/store/utils.d.ts.map +1 -1
  209. package/dist/umd/types/core.d.ts +3 -4
  210. package/dist/umd/types/core.d.ts.map +1 -1
  211. package/dist/umd/types/general.d.ts +1 -21
  212. package/dist/umd/types/general.d.ts.map +1 -1
  213. package/dist/umd/types/index.d.ts +0 -1
  214. package/dist/umd/types/index.d.ts.map +1 -1
  215. package/dist/umd/utils/changes.d.ts +2 -2
  216. package/dist/umd/utils/changes.d.ts.map +1 -1
  217. package/dist/umd/utils/deepEqual.d.ts.map +1 -1
  218. package/dist/umd/utils/index.d.ts +2 -21
  219. package/dist/umd/utils/index.d.ts.map +1 -1
  220. package/package.json +8 -6
  221. package/dist/esm/components/Edges/utils.d.ts +0 -17
  222. package/dist/esm/components/Edges/utils.d.ts.map +0 -1
  223. package/dist/esm/components/Port/type.d.ts +0 -22
  224. package/dist/esm/components/Port/type.d.ts.map +0 -1
  225. package/dist/esm/components/Port/utils.d.ts +0 -25
  226. package/dist/esm/components/Port/utils.d.ts.map +0 -1
  227. package/dist/esm/contexts/RFStoreContext.d.ts.map +0 -1
  228. package/dist/esm/fixtures/errorMessages.d.ts +0 -11
  229. package/dist/esm/fixtures/errorMessages.d.ts.map +0 -1
  230. package/dist/esm/hooks/useDrag/index.d.ts +0 -10
  231. package/dist/esm/hooks/useDrag/index.d.ts.map +0 -1
  232. package/dist/esm/hooks/useDrag/type.d.ts +0 -11
  233. package/dist/esm/hooks/useDrag/type.d.ts.map +0 -1
  234. package/dist/esm/hooks/useDrag/utils.d.ts +0 -20
  235. package/dist/esm/hooks/useDrag/utils.d.ts.map +0 -1
  236. package/dist/esm/hooks/useGetPointerPosition.d.ts +0 -21
  237. package/dist/esm/hooks/useGetPointerPosition.d.ts.map +0 -1
  238. package/dist/esm/hooks/useUpdateIntersectionNodes/index.d.ts +0 -6
  239. package/dist/esm/hooks/useUpdateIntersectionNodes/index.d.ts.map +0 -1
  240. package/dist/esm/types/utils.d.ts +0 -26
  241. package/dist/esm/types/utils.d.ts.map +0 -1
  242. package/dist/esm/utils/graph.d.ts +0 -18
  243. package/dist/esm/utils/graph.d.ts.map +0 -1
  244. package/dist/umd/components/Edges/utils.d.ts +0 -17
  245. package/dist/umd/components/Edges/utils.d.ts.map +0 -1
  246. package/dist/umd/components/Port/type.d.ts +0 -22
  247. package/dist/umd/components/Port/type.d.ts.map +0 -1
  248. package/dist/umd/components/Port/utils.d.ts +0 -25
  249. package/dist/umd/components/Port/utils.d.ts.map +0 -1
  250. package/dist/umd/contexts/RFStoreContext.d.ts.map +0 -1
  251. package/dist/umd/fixtures/errorMessages.d.ts +0 -11
  252. package/dist/umd/fixtures/errorMessages.d.ts.map +0 -1
  253. package/dist/umd/hooks/useDrag/index.d.ts +0 -10
  254. package/dist/umd/hooks/useDrag/index.d.ts.map +0 -1
  255. package/dist/umd/hooks/useDrag/type.d.ts +0 -11
  256. package/dist/umd/hooks/useDrag/type.d.ts.map +0 -1
  257. package/dist/umd/hooks/useDrag/utils.d.ts +0 -20
  258. package/dist/umd/hooks/useDrag/utils.d.ts.map +0 -1
  259. package/dist/umd/hooks/useGetPointerPosition.d.ts +0 -21
  260. package/dist/umd/hooks/useGetPointerPosition.d.ts.map +0 -1
  261. package/dist/umd/hooks/useUpdateIntersectionNodes/index.d.ts +0 -6
  262. package/dist/umd/hooks/useUpdateIntersectionNodes/index.d.ts.map +0 -1
  263. package/dist/umd/types/utils.d.ts +0 -26
  264. package/dist/umd/types/utils.d.ts.map +0 -1
  265. package/dist/umd/utils/graph.d.ts +0 -18
  266. package/dist/umd/utils/graph.d.ts.map +0 -1
package/dist/esm/index.js CHANGED
@@ -1,26 +1,17 @@
1
+ import { errorMessages, CosmosPanZoom, CosmosDrag, getRectOfNodes, getEventPosition, getNodesInside, Position, internalsSymbol as internalsSymbol$1, MarkerType, getMarkerId, isNumeric, getStraightPath, getStepPath, getBezierPath, CosmosPort, devWarn, isMouseEvent, clampPosition, getNodePositionWithOrigin, getDimensions, getPortBounds } from 'cosmos-diagram';
2
+ export { MarkerType, Position, addEdge, boxToRect, clamp, getBezierEdgeCenter, getBezierPath, getStepPath, getStraightPath, isCoreEdge, isCoreNode, rectToBox, updateEdge } from 'cosmos-diagram';
1
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { createContext, useContext, useMemo, useState, useEffect, useRef, useCallback, memo, forwardRef } from 'react';
4
+ import { createContext, useContext, useMemo, useState, useEffect, useRef, memo, useCallback, forwardRef } from 'react';
3
5
  import { useStore as useStore$1, createStore } from 'zustand';
4
- import { zoom, zoomIdentity } from 'd3-zoom';
5
- import { select } from 'd3-selection';
6
- import { shallow } from 'zustand/shallow';
7
6
  import cc from 'classcat';
8
- import { drag } from 'd3-drag';
7
+ import { shallow } from 'zustand/shallow';
8
+ import { zoomIdentity } from 'd3-zoom';
9
9
 
10
10
  const StoreContext = createContext(null);
11
11
  const Provider$1 = StoreContext.Provider;
12
12
 
13
- const errorMessages = {
14
- '001': () => 'Seems like you have not used zustand provider as an ancestor',
15
- '002': () => 'It looks like you`ve created a new nodeTypes or edgeTypes object. If this wasn`t on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.',
16
- '010': (nodeType) => `Node type "${nodeType}" not found. Using fallback type "default".`,
17
- '011': () => 'Only child nodes can use a parent extent',
18
- '020': () => 'Can`t create edge. An edge needs a source and a target.',
19
- '021': (id) => `The old edge with id=${id} does not exist.`,
20
- '022': (type) => `Marker type "${type}" doesn't exist.`,
21
- };
22
-
23
13
  const zustandErrorMessage = errorMessages['001']();
14
+ // 변경 사항이 발생할때 값을 구독
24
15
  function useStore(selector, equalityFn) {
25
16
  const store = useContext(StoreContext);
26
17
  if (store === null) {
@@ -28,6 +19,7 @@ function useStore(selector, equalityFn) {
28
19
  }
29
20
  return useStore$1(store, selector, equalityFn);
30
21
  }
22
+ // 필요에 따라 값을 계산
31
23
  const useStoreApi = () => {
32
24
  const store = useContext(StoreContext);
33
25
  if (store === null) {
@@ -41,7 +33,7 @@ const useStoreApi = () => {
41
33
  }), [store]);
42
34
  };
43
35
 
44
- function useGlobalKeyHandler(multiSelectionKeyCode = 'Meta') {
36
+ const useGlobalKeyHandler = (multiSelectionKeyCode = 'Meta') => {
45
37
  const store = useStoreApi();
46
38
  const [multiSelectionActivate, setMultiSelectionActivate] = useState(false);
47
39
  const handleKeyDown = (e) => {
@@ -65,208 +57,64 @@ function useGlobalKeyHandler(multiSelectionKeyCode = 'Meta') {
65
57
  multiSelectionActive: multiSelectionActivate,
66
58
  });
67
59
  }, [multiSelectionActivate]);
68
- }
69
-
70
- const internalsSymbol = Symbol.for('internals');
71
- const devWarn = (id, value = '') => {
72
- if (process.env.NODE_ENV === 'development') {
73
- console.warn(`[React Diagram]: ${id}-${errorMessages[id](value)}`);
74
- }
75
- };
76
- const onErrorWrapper = (onError) => (id, value = '') => onError?.(id, errorMessages[id](value));
77
- const isNumeric = (n) => !isNaN(n) && isFinite(n);
78
- const getDimensions = (node) => ({
79
- width: node.offsetWidth,
80
- height: node.offsetHeight,
81
- });
82
- const getOverlappingArea = (rectA, rectB) => {
83
- const xOverlap = Math.max(0, Math.min(rectA.x + rectA.width, rectB.x + rectB.width) -
84
- Math.max(rectA.x, rectB.x));
85
- const yOverlap = Math.max(0, Math.min(rectA.y + rectA.height, rectB.y + rectB.height) -
86
- Math.max(rectA.y, rectB.y));
87
- return Math.ceil(xOverlap * yOverlap);
88
- };
89
- const clamp = (val, min = 0, max = 1) => Math.min(Math.max(val, min), max);
90
- const clampPosition = (position = { x: 0, y: 0 }, extent) => ({
91
- x: clamp(position.x, extent[0][0], extent[1][0]),
92
- y: clamp(position.y, extent[0][1], extent[1][1]),
93
- });
94
- const rectToBox = ({ x, y, width, height }) => ({
95
- x,
96
- y,
97
- x2: x + width,
98
- y2: y + height,
99
- });
100
- const boxToRect = ({ x, y, x2, y2 }) => ({
101
- x,
102
- y,
103
- width: x2 - x,
104
- height: y2 - y,
105
- });
106
- const getBoundsOfBoxes = (box1, box2) => ({
107
- x: Math.min(box1.x, box2.x),
108
- y: Math.min(box1.y, box2.y),
109
- x2: Math.max(box1.x2, box2.x2),
110
- y2: Math.max(box1.y2, box2.y2),
111
- });
112
- const isMouseEvent = (event) => 'clientX' in event;
113
- const getEventPosition = (event, bounds) => {
114
- const isMouseTriggered = isMouseEvent(event);
115
- const eventX = isMouseTriggered ? event.clientX : event.touches?.[0].clientX;
116
- const eventY = isMouseTriggered ? event.clientY : event.touches?.[0].clientY;
117
- return {
118
- x: eventX - (bounds?.left ?? 0),
119
- y: eventY - (bounds?.top ?? 0),
120
- };
121
- };
122
- const calcAutoPanVelocity = (value, bound, radius, velocity) => {
123
- const maxRadius = bound - radius;
124
- if (value < radius) {
125
- return (clamp(Math.abs(value - radius), 1, 50) / 50) * velocity;
126
- }
127
- else if (value > maxRadius) {
128
- return (-clamp(Math.abs(value - maxRadius), 1, 50) / 50) * velocity;
129
- }
130
- return 0;
131
- };
132
- const calcAutoPanPosition = (pos, bounds) => {
133
- const xMovement = calcAutoPanVelocity(pos.x, bounds.width, 30, 10);
134
- const yMovement = calcAutoPanVelocity(pos.y, bounds.height, 30, 10);
135
- return [xMovement, yMovement];
136
60
  };
137
61
 
138
- const convertTransform = (transform) => {
139
- const { x, y, k } = transform;
140
- return {
141
- x,
142
- y,
143
- zoom: k,
144
- };
145
- };
146
- const isWrappedWithClass = (event, className) => event.target.closest(`.${className}`);
147
- const isViewChanged = (prevViewport, eventViewport) => {
148
- const { x: prevX, y: prevY, zoom: prevZoom } = prevViewport;
149
- const { x, y, k } = eventViewport;
150
- return prevX !== x || prevY !== y || prevZoom !== k;
151
- };
152
- const selector$8 = (s) => ({
153
- d3Zoom: s.d3Zoom,
154
- d3Selection: s.d3Selection,
155
- });
156
- function Pane({ noPanClassName, panning, minZoom, maxZoom, defaultViewport, translateExtent, children, onMove, onMoveStart, onMoveEnd, }) {
62
+ const Pane = ({ noPanClassName, panning, selection, minZoom, maxZoom, defaultViewport, translateExtent, children, onMove, onMoveStart, onMoveEnd, }) => {
157
63
  const store = useStoreApi();
158
- const isZoomingOrPanning = useRef(false);
159
64
  const Pane = useRef(null);
160
- const d3ZoomHandler = useRef();
161
- const prevTransform = useRef({ x: 0, y: 0, zoom: 0 });
162
- const timerId = useRef();
163
- const { d3Zoom, d3Selection } = useStore(selector$8, shallow);
164
- useEffect(() => {
165
- if (Pane.current) {
166
- const bbox = Pane.current.getBoundingClientRect();
167
- const d3ZoomInstance = zoom()
168
- .scaleExtent([minZoom, maxZoom])
169
- .translateExtent(translateExtent);
170
- const selection = select(Pane.current).call(d3ZoomInstance);
171
- const updatedTransform = zoomIdentity
172
- .translate(defaultViewport.x, defaultViewport.y)
173
- .scale(clamp(defaultViewport.zoom, minZoom, maxZoom));
174
- const extent = [
175
- [0, 0],
176
- [bbox.width, bbox.height],
177
- ];
178
- const constrainedTransform = d3ZoomInstance.constrain()(updatedTransform, extent, translateExtent);
179
- d3ZoomInstance.transform(selection, constrainedTransform);
180
- d3ZoomHandler.current = selection.on('wheel.zoom');
181
- store.setState({
182
- d3Zoom: d3ZoomInstance,
183
- d3Selection: selection,
184
- // we need to pass transform because zoom handler is not registered when we set the initial transform
185
- transform: [
186
- constrainedTransform.x,
187
- constrainedTransform.y,
188
- constrainedTransform.k,
189
- ],
190
- domNode: Pane.current.closest('.react-diagram'),
191
- });
192
- }
193
- }, [translateExtent]);
194
- useEffect(() => {
195
- if (d3Zoom && d3Selection) {
196
- d3Selection.on('wheel.zoom', (event, d) => {
197
- event.preventDefault();
198
- if (Pane.current && d3ZoomHandler.current) {
199
- d3ZoomHandler.current.call(Pane.current, event, d);
200
- }
201
- });
202
- }
203
- }, [d3Zoom, d3Selection, d3ZoomHandler, panning]);
65
+ const cosmosPanZoom = useRef();
204
66
  useEffect(() => {
205
- if (d3Zoom) {
206
- d3Zoom.on('start', (event) => {
207
- if (!event.sourceEvent) {
208
- return null;
209
- }
210
- isZoomingOrPanning.current = true;
211
- if (onMoveStart) {
212
- const flowTransform = convertTransform(event.transform);
213
- prevTransform.current = flowTransform;
214
- onMoveStart?.(event.sourceEvent, flowTransform);
215
- }
216
- });
217
- }
218
- }, [d3Zoom, onMoveStart]);
219
- useEffect(() => {
220
- if (d3Zoom) {
221
- d3Zoom.on('zoom', (event) => {
222
- store.setState({
223
- transform: [
224
- event.transform.x,
225
- event.transform.y,
226
- event.transform.k,
227
- ],
228
- });
229
- if (onMove) {
230
- const flowTransform = convertTransform(event.transform);
231
- onMove?.(event.sourceEvent, flowTransform);
232
- }
233
- });
234
- }
235
- }, [d3Zoom, onMove]);
236
- useEffect(() => {
237
- if (d3Zoom) {
238
- d3Zoom.on('end', (event) => {
239
- isZoomingOrPanning.current = false;
240
- if (onMoveEnd &&
241
- isViewChanged(prevTransform.current, event.transform)) {
242
- const flowTransform = convertTransform(event.transform);
243
- prevTransform.current = flowTransform;
244
- clearTimeout(timerId.current);
245
- timerId.current = setTimeout(() => {
246
- onMoveEnd?.(event.sourceEvent, flowTransform);
247
- }, 0);
248
- }
249
- });
250
- }
251
- }, [d3Zoom]);
67
+ if (!Pane.current)
68
+ return;
69
+ cosmosPanZoom.current = CosmosPanZoom({
70
+ domNode: Pane.current,
71
+ minZoom,
72
+ maxZoom,
73
+ translateExtent,
74
+ viewport: defaultViewport,
75
+ panning,
76
+ onTransformChange: (transform) => {
77
+ store.setState({ transform });
78
+ },
79
+ onPanningChange: (panning) => {
80
+ console.log(panning);
81
+ },
82
+ onPanZoomStart: (event, viewport) => {
83
+ onMoveStart?.(event, viewport);
84
+ console.log('start', viewport);
85
+ },
86
+ onPanZoom: (event, viewport) => {
87
+ onMove?.(event, viewport);
88
+ },
89
+ onPanZoomEnd: (event, viewport) => {
90
+ console.log('end', viewport);
91
+ onMoveEnd?.(event, viewport);
92
+ },
93
+ });
94
+ const { x, y, zoom } = cosmosPanZoom.current.getViewport();
95
+ store.setState({
96
+ // 지워야할 목록
97
+ // d3Zoom: d3ZoomInstance,
98
+ // d3Selection: selection,
99
+ // we need to pass transform because zoom handler is not registered when we set the initial transform
100
+ transform: [x, y, zoom],
101
+ domNode: Pane.current.closest('.react-diagram'),
102
+ });
103
+ return () => {
104
+ cosmosPanZoom.current?.destroy();
105
+ };
106
+ }, []);
252
107
  useEffect(() => {
253
- if (d3Zoom) {
254
- d3Zoom.filter((event) => {
255
- if (isWrappedWithClass(event, noPanClassName) &&
256
- event.type !== 'wheel') {
257
- return false;
258
- }
259
- if (!panning)
260
- return false;
261
- const buttonAllowed = !event.button || event.button <= 1;
262
- if (!buttonAllowed)
263
- return false;
264
- return true;
265
- });
266
- }
267
- }, [d3Zoom, panning]);
268
- return (jsx("div", { className: "react-diagram__pane react-diagram__container", ref: Pane, children: children }));
269
- }
108
+ cosmosPanZoom.current?.update({
109
+ noPanClassName,
110
+ selection,
111
+ });
112
+ }, [noPanClassName, selection]);
113
+ return (jsx("div", { ref: Pane, className: cc([
114
+ 'react-diagram__pane react-diagram__container',
115
+ { selection },
116
+ ]), children: children }));
117
+ };
270
118
 
271
119
  const selector$7 = (s) => `translate(${s.transform[0]}px,${s.transform[1]}px) scale(${s.transform[2]})`;
272
120
  function Viewport({ children }) {
@@ -285,70 +133,6 @@ function DragBox({ rect }) {
285
133
  } }));
286
134
  }
287
135
 
288
- function useGetPointerPosition() {
289
- const store = useStoreApi();
290
- const getPointerPosition = useCallback(({ sourceEvent }) => {
291
- const { transform, gridStep, centerStep } = store.getState();
292
- const x = sourceEvent.changedTouches
293
- ? sourceEvent.changedTouches[0].clientX
294
- : sourceEvent.clientX;
295
- const y = sourceEvent.changedTouches
296
- ? sourceEvent.changedTouches[0].clientY
297
- : sourceEvent.clientY;
298
- const pointerPos = {
299
- x: (x - transform[0]) / transform[2],
300
- y: (y - transform[1]) / transform[2],
301
- };
302
- const getStepPosition = (params = {
303
- position: pointerPos,
304
- }) => {
305
- const { position, nodeSize } = params;
306
- if (!gridStep)
307
- return position;
308
- let x = gridStep[0] * Math.round(position.x / gridStep[0]), y = gridStep[1] * Math.round(position.y / gridStep[1]);
309
- if (centerStep && nodeSize) {
310
- const centerX = (gridStep[0] - nodeSize.width) / 2;
311
- const centerY = (gridStep[1] - nodeSize.height) / 2;
312
- const positionX = position.x - centerX;
313
- const positionY = position.y - centerY;
314
- x = gridStep[0] * Math.round(positionX / gridStep[0]) + centerX;
315
- y = gridStep[1] * Math.round(positionY / gridStep[1]) + centerY;
316
- }
317
- return {
318
- x,
319
- y,
320
- };
321
- };
322
- return {
323
- getStepPosition,
324
- ...pointerPos,
325
- };
326
- }, []);
327
- return getPointerPosition;
328
- }
329
-
330
- const getPortBounds = (selector, nodeElement, zoom, nodeOrigin) => {
331
- const ports = nodeElement.querySelectorAll(selector);
332
- if (!ports || !ports.length) {
333
- return null;
334
- }
335
- const portsArray = Array.from(ports);
336
- const nodeBounds = nodeElement.getBoundingClientRect();
337
- const nodeOffset = {
338
- x: nodeBounds.width * nodeOrigin[0],
339
- y: nodeBounds.height * nodeOrigin[1],
340
- };
341
- return portsArray.map((port) => {
342
- const portBounds = port.getBoundingClientRect();
343
- return {
344
- id: port.getAttribute('data-portid'),
345
- position: port.dataset.portPosition,
346
- x: (portBounds.left - nodeBounds.left - nodeOffset.x) / zoom,
347
- y: (portBounds.top - nodeBounds.top - nodeOffset.y) / zoom,
348
- ...getDimensions(port),
349
- };
350
- });
351
- };
352
136
  function getMouseHandler$1(id, getState, handler) {
353
137
  return handler === undefined
354
138
  ? handler
@@ -372,529 +156,55 @@ function handleNodeClick({ id, store, isSelectable, unselect = false, nodeRef, }
372
156
  }
373
157
  }
374
158
 
375
- const isNode = (element) => 'id' in element && !('source' in element) && !('target' in element);
376
- const isEdge = (element) => 'source' in element && 'target' in element;
377
- const getNodePositionWithOrigin = (node, nodeOrigin = [0, 0]) => {
378
- if (!node) {
379
- return {
380
- x: 0,
381
- y: 0,
382
- positionAbsolute: {
383
- x: 0,
384
- y: 0,
385
- },
386
- };
387
- }
388
- const offsetX = (node.width ?? 0) * nodeOrigin[0];
389
- const offsetY = (node.height ?? 0) * nodeOrigin[1];
390
- const position = {
391
- x: node.position.x - offsetX,
392
- y: node.position.y - offsetY,
393
- };
394
- return {
395
- ...position,
396
- positionAbsolute: node.positionAbsolute
397
- ? {
398
- x: node.positionAbsolute.x - offsetX,
399
- y: node.positionAbsolute.y - offsetY,
400
- }
401
- : position,
402
- };
403
- };
404
- const getNodesInside = (nodeInternals, rect, [tx, ty, tScale] = [0, 0, 1], partially = false, excludeNonSelectableNodes = false, nodeOrigin = [0, 0]) => {
405
- const paneRect = {
406
- x: (rect.x - tx) / tScale,
407
- y: (rect.y - ty) / tScale,
408
- width: rect.width / tScale,
409
- height: rect.height / tScale,
410
- };
411
- const visibleNodes = [];
412
- nodeInternals.forEach((node) => {
413
- const { width, height, selectable = true, hidden = false } = node;
414
- if ((excludeNonSelectableNodes && !selectable) || hidden) {
415
- return false;
416
- }
417
- const { positionAbsolute } = getNodePositionWithOrigin(node, nodeOrigin);
418
- const nodeRect = {
419
- x: positionAbsolute.x,
420
- y: positionAbsolute.y,
421
- width: width || 0,
422
- height: height || 0,
423
- };
424
- const overlappingArea = getOverlappingArea(paneRect, nodeRect);
425
- const notInitialized = typeof width === 'undefined' ||
426
- typeof height === 'undefined' ||
427
- width === null ||
428
- height === null;
429
- const partiallyVisible = partially && overlappingArea > 0;
430
- const area = (width || 0) * (height || 0);
431
- const isVisible = notInitialized || partiallyVisible || overlappingArea >= area;
432
- if (isVisible || node.dragging) {
433
- visibleNodes.push(node);
434
- }
435
- });
436
- return visibleNodes;
437
- };
438
- const getMarkerId = (marker, rfId) => {
439
- if (typeof marker === 'undefined') {
440
- return '';
441
- }
442
- if (typeof marker === 'string') {
443
- return marker;
444
- }
445
- const idPrefix = rfId ? `${rfId}__` : '';
446
- return `${idPrefix}${Object.keys(marker)
447
- .sort()
448
- .map((key) => `${key}=${marker[key]}`)
449
- .join('&')}`;
450
- };
451
- const getEdgeId = ({ source, target }) => `react-diagram__edge-${source}-${target}`;
452
- const isExistsConnection = (edge, edges) => edges.some((el) => el.source === edge.source && el.target === edge.target);
453
- const addEdge = (edgeParams, edges) => {
454
- if (!isEdge(edgeParams)) {
455
- devWarn('020');
456
- return edges;
457
- }
458
- if (isExistsConnection(edgeParams, edges)) {
459
- return edges;
460
- }
461
- let edge;
462
- if (edgeParams.id)
463
- edge = { ...edgeParams };
464
- else
465
- edge = {
466
- ...edgeParams,
467
- id: getEdgeId(edgeParams),
468
- };
469
- return edges.concat(edge);
470
- };
471
- const updateEdge = (originEdge, newConnection, edges, options = { shouldReplaceId: true }) => {
472
- const { id: oldEdgeId, ...rest } = originEdge;
473
- if (!newConnection.source || !newConnection.target)
474
- devWarn('020');
475
- const foundEdge = edges.find((e) => e.id === oldEdgeId);
476
- if (!foundEdge)
477
- devWarn('021', oldEdgeId);
478
- const edge = {
479
- ...rest,
480
- id: options.shouldReplaceId ? getEdgeId(newConnection) : oldEdgeId,
481
- source: newConnection.source,
482
- target: newConnection.target,
483
- };
484
- return edges.filter((e) => e.id !== oldEdgeId).concat(edge);
485
- };
486
- const getRectOfNodes = (nodes, nodeOrigin = [0, 0]) => {
487
- if (nodes.length === 0) {
488
- return { x: 0, y: 0, width: 0, height: 0 };
489
- }
490
- const box = nodes.reduce((currentBox, node) => {
491
- const { x, y } = getNodePositionWithOrigin(node, nodeOrigin).positionAbsolute;
492
- const nextBox = rectToBox({
493
- x,
494
- y,
495
- width: node.width || 0,
496
- height: node.height || 0,
497
- });
498
- return getBoundsOfBoxes(currentBox, nextBox);
499
- }, { x: Infinity, y: Infinity, x2: -Infinity, y2: -Infinity });
500
- return boxToRect(box);
501
- };
502
-
503
- function isParentSelected(node, nodeInternals) {
504
- if (!node.parentNode) {
505
- return false;
506
- }
507
- const parentNode = nodeInternals.get(node.parentNode);
508
- if (!parentNode) {
509
- return false;
510
- }
511
- if (parentNode.selected) {
512
- return true;
513
- }
514
- return isParentSelected(parentNode, nodeInternals);
515
- }
516
- const getDragItems = (nodeInternals, nodesDraggable, mousePosition, nodeId) => {
517
- const filteredNode = Array.from(nodeInternals.values()).filter((n) => {
518
- const hasSize = n.width && n.height;
519
- const isSelected = n.selected || n.id === nodeId;
520
- const hasNoParent = !n.parentNode || !isParentSelected(n, nodeInternals);
521
- const isDraggable = n.draggable || (nodesDraggable && typeof n.draggable === 'undefined');
522
- return hasSize && isSelected && hasNoParent && isDraggable;
523
- });
524
- return filteredNode.map((n) => ({
525
- id: n.id,
526
- position: n.position || { x: 0, y: 0 },
527
- positionAbsolute: n.positionAbsolute || { x: 0, y: 0 },
528
- distance: {
529
- x: mousePosition.x - (n.positionAbsolute?.x ?? 0),
530
- y: mousePosition.y - (n.positionAbsolute?.y ?? 0),
531
- },
532
- extent: n.extent,
533
- parentNode: n.parentNode,
534
- width: n.width,
535
- height: n.height,
536
- }));
537
- };
538
- const calcNextPosition = (node, nextPosition, nodeInternals, nodeExtent, nodeOrigin = [0, 0], onError) => {
539
- let currentExtent = node.extent || nodeExtent;
540
- if (node.extent === 'parent') {
541
- if (node.parentNode && node.width && node.height) {
542
- const parent = nodeInternals.get(node.parentNode);
543
- const { x: parentX, y: parentY } = getNodePositionWithOrigin(parent, nodeOrigin).positionAbsolute;
544
- currentExtent =
545
- parent &&
546
- isNumeric(parentX) &&
547
- isNumeric(parentY) &&
548
- isNumeric(parent.width) &&
549
- isNumeric(parent.height)
550
- ? [
551
- [
552
- parentX + node.width * nodeOrigin[0],
553
- parentY + node.height * nodeOrigin[1],
554
- ],
555
- [
556
- parentX +
557
- parent.width -
558
- node.width +
559
- node.width * nodeOrigin[0],
560
- parentY +
561
- parent.height -
562
- node.height +
563
- node.height * nodeOrigin[1],
564
- ],
565
- ]
566
- : currentExtent;
567
- }
568
- else {
569
- onError?.('011');
570
- currentExtent = nodeExtent;
571
- }
572
- }
573
- else if (node.extent && node.parentNode) {
574
- const parent = nodeInternals.get(node.parentNode);
575
- const { x: parentX, y: parentY } = getNodePositionWithOrigin(parent, nodeOrigin).positionAbsolute;
576
- currentExtent = [
577
- [node.extent[0][0] + parentX, node.extent[0][1] + parentY],
578
- [node.extent[1][0] + parentX, node.extent[1][1] + parentY],
579
- ];
580
- }
581
- let parentPosition = { x: 0, y: 0 };
582
- if (node.parentNode) {
583
- const parentNode = nodeInternals.get(node.parentNode);
584
- parentPosition = getNodePositionWithOrigin(parentNode, nodeOrigin).positionAbsolute;
585
- }
586
- const positionAbsolute = currentExtent
587
- ? clampPosition(nextPosition, currentExtent)
588
- : nextPosition;
589
- return {
590
- position: {
591
- x: positionAbsolute.x - parentPosition.x,
592
- y: positionAbsolute.y - parentPosition.y,
593
- },
594
- positionAbsolute,
595
- };
596
- };
597
- const getEventHandlerParams = ({ nodeId, dragItems, nodeInternals, }) => {
598
- const extentedDragItems = dragItems.map((n) => {
599
- const node = nodeInternals.get(n.id);
600
- return {
601
- ...node,
602
- position: n.position,
603
- positionAbsolute: n.positionAbsolute,
604
- };
605
- });
606
- return [
607
- nodeId
608
- ? extentedDragItems.find((n) => n.id === nodeId)
609
- : extentedDragItems[0],
610
- extentedDragItems,
611
- ];
612
- };
613
- const hasSelector = (target, selector, nodeRef) => {
614
- let current = target;
615
- do {
616
- if (current?.matches(selector))
617
- return true;
618
- if (current === nodeRef.current)
619
- return false;
620
- current = current.parentElement;
621
- } while (current);
622
- return false;
623
- };
624
- const hasChangedPosition = (beforePositions, currentPosition) => beforePositions.x !== currentPosition.x ||
625
- beforePositions.y !== currentPosition.y;
626
-
627
- const has = Object.prototype.hasOwnProperty;
628
- const deepEqual = (foo, bar) => {
629
- let constructor;
630
- let length;
631
- if (foo === bar)
632
- return true;
633
- if (foo && bar && foo.constructor === bar.constructor) {
634
- constructor = foo.constructor;
635
- if (constructor === Date)
636
- return foo.getTime() === bar.getTime();
637
- if (constructor === RegExp)
638
- return foo.toString() === bar.toString();
639
- if (constructor === Array) {
640
- if ((length = foo.length) === bar.length) {
641
- while (length-- && deepEqual(foo[length], bar[length]))
642
- ;
643
- }
644
- return length === -1;
645
- }
646
- if (!constructor || typeof foo === 'object') {
647
- length = 0;
648
- for (constructor in foo) {
649
- if (has.call(foo, constructor) &&
650
- ++length &&
651
- !has.call(bar, constructor))
652
- return false;
653
- if (!(constructor in bar) ||
654
- !deepEqual(foo[constructor], bar[constructor]))
655
- return false;
656
- }
657
- return Object.keys(bar).length === length;
658
- }
659
- }
660
- return foo !== foo && bar !== bar;
661
- };
662
-
663
- function useUpdateIntersectionNodes() {
664
- const store = useStoreApi();
665
- const intersectionChanges = useRef([]);
666
- const resetIntersectedNodes = useCallback((intersectedNodes) => {
667
- const hasIntersectedNodes = intersectedNodes.length;
668
- let beforeChanges;
669
- if (hasIntersectedNodes) {
670
- beforeChanges = intersectionChanges.current
671
- .filter((beforeChange) => {
672
- return !intersectedNodes.some((intersectedNode) => beforeChange.id === intersectedNode.id);
673
- })
674
- .map((beforeChange) => ({
675
- ...beforeChange,
676
- intersected: false,
677
- }));
678
- }
679
- else {
680
- beforeChanges = intersectionChanges.current.map((beforeChange) => ({
681
- ...beforeChange,
682
- intersected: false,
683
- }));
684
- }
685
- return beforeChanges;
686
- }, []);
687
- const updateNodesIntersection = useCallback((dragItems) => {
688
- const { getNodes, triggerNodeChanges } = store.getState();
689
- const intersectedDraggingNodeIds = [];
690
- const intersectedNodes = getNodes()
691
- .filter((node) => {
692
- const { width, height, position, parentNode } = node;
693
- if (parentNode)
694
- return;
695
- if (width && height) {
696
- return dragItems.current?.some((dragItem) => {
697
- const { position: dPosition, width: dWidth, height: dHeight, } = dragItem;
698
- if (node.id === dragItem.id)
699
- return;
700
- if (dragItem.parentNode)
701
- return;
702
- if (!dWidth || !dHeight)
703
- return;
704
- const leftIn = dPosition.x + dWidth >= position.x, rightIn = position.x + width >= dPosition.x, topIn = dPosition.y + dHeight >= position.y, bottomIn = position.y + height >= dPosition.y;
705
- const isIn = leftIn && rightIn && topIn && bottomIn;
706
- if (isIn) {
707
- if (!intersectedDraggingNodeIds.includes(dragItem.id)) {
708
- intersectedDraggingNodeIds.push(dragItem.id);
709
- }
710
- }
711
- return isIn;
712
- });
713
- }
714
- })
715
- .map((node) => {
716
- return {
717
- id: node.id,
718
- type: 'intersect',
719
- intersected: true,
720
- };
721
- });
722
- const intersectedDraggingNodes = intersectedDraggingNodeIds.map((id) => {
723
- return {
724
- id,
725
- type: 'intersect',
726
- intersected: true,
727
- };
728
- });
729
- const changes = [...intersectedNodes, ...intersectedDraggingNodes];
730
- if (!deepEqual(changes, intersectionChanges.current)) {
731
- const beforeChanges = resetIntersectedNodes(changes);
732
- intersectionChanges.current = changes;
733
- triggerNodeChanges([...changes, ...beforeChanges]);
734
- }
735
- }, []);
736
- return updateNodesIntersection;
737
- }
738
-
739
- const isDragItem = (node) => 'distance' in node;
740
- function useDrag({ nodeRef, nodeId, isSelectable, noDragClassName, }) {
159
+ const useDrag = ({ disabled, nodeRef, nodeId, isSelectable, noDragClassName, }) => {
741
160
  const store = useStoreApi();
742
- const dragItems = useRef([]);
743
- const containerBounds = useRef(null);
744
- const mousePosition = useRef({ x: 0, y: 0 });
745
- const lastPosition = useRef({ x: 0, y: 0 });
746
- const dragEvent = useRef(null);
747
- const autoPanStarted = useRef(false);
748
- const autoPanId = useRef(0);
161
+ const cosmosDrag = useRef();
749
162
  const [dragging, setDragging] = useState(false);
750
- const getPointerPosition = useGetPointerPosition();
751
- const updateNodesIntersection = useUpdateIntersectionNodes();
752
- const updateNodePosition = (pointerPositions, dragEnd = false) => (dragItem) => {
753
- if (!isDragItem(dragItem))
754
- return;
755
- const { nodeInternals, nodeExtent, nodeOrigin, smoothStep, gridStep, onError, } = store.getState();
756
- const { distance, width, height } = dragItem;
757
- const { x, y, getStepPosition } = pointerPositions;
758
- let nextPosition = {
759
- x: x - distance.x,
760
- y: y - distance.y,
761
- };
762
- if (gridStep && getStepPosition) {
763
- const nodeSize = { width, height };
764
- const stepPosition = getStepPosition({
765
- position: nextPosition,
766
- nodeSize,
767
- });
768
- if (!smoothStep || (smoothStep && dragEnd)) {
769
- nextPosition = stepPosition;
770
- }
771
- }
772
- const updatedPosition = calcNextPosition(dragItem, nextPosition, nodeInternals, nodeExtent, nodeOrigin, onError);
773
- const hasChange = hasChangedPosition(dragItem.position, updatedPosition.position);
774
- if (!hasChange)
775
- return;
776
- dragItem.position = updatedPosition.position;
777
- dragItem.positionAbsolute = updatedPosition.positionAbsolute;
778
- };
779
163
  useEffect(() => {
780
- if (nodeRef?.current) {
781
- const selection = select(nodeRef.current);
782
- const updateNodes = (pointerPosition) => {
783
- const { nodeInternals, onNodeDrag, updateNodesPosition } = store.getState();
784
- const { x, y } = pointerPosition;
785
- lastPosition.current = { x, y };
786
- updateNodesPosition(dragItems.current, true, updateNodePosition(pointerPosition));
164
+ cosmosDrag.current = CosmosDrag({
165
+ getStore: () => store.getState(),
166
+ onNodeMouseDown: (id) => {
167
+ handleNodeClick({
168
+ id,
169
+ store,
170
+ nodeRef,
171
+ isSelectable,
172
+ });
173
+ },
174
+ onDrag: (e, _, node, nodes) => {
175
+ const { onNodeDrag } = store.getState();
176
+ onNodeDrag?.(e, node, nodes);
177
+ },
178
+ onDragStart: (e, _, node, nodes) => {
179
+ const { onNodeDragStart } = store.getState();
180
+ onNodeDragStart?.(e, node, nodes);
787
181
  setDragging(true);
788
- if (onNodeDrag && dragEvent.current) {
789
- const [currentNode, nodes] = getEventHandlerParams({
790
- nodeId,
791
- dragItems: dragItems.current,
792
- nodeInternals,
793
- });
794
- onNodeDrag(dragEvent.current, currentNode, nodes);
795
- }
796
- };
797
- const autoPan = () => {
798
- if (!containerBounds.current) {
799
- return;
800
- }
801
- const [xMovement, yMovement] = calcAutoPanPosition(mousePosition.current, containerBounds.current);
802
- if (xMovement !== 0 || yMovement !== 0) {
803
- const { transform, panBy } = store.getState();
804
- lastPosition.current.x -= xMovement / transform[2];
805
- lastPosition.current.y -= yMovement / transform[2];
806
- updateNodes(lastPosition.current);
807
- panBy({ x: xMovement, y: yMovement });
808
- }
809
- autoPanId.current = requestAnimationFrame(autoPan);
810
- };
811
- const dragHandle = drag()
812
- .on('start', (e) => {
813
- const { nodeInternals, nodesDraggable, domNode, onNodeDragStart, } = store.getState();
814
- if (nodeId) {
815
- handleNodeClick({
816
- id: nodeId,
817
- store,
818
- nodeRef: nodeRef,
819
- isSelectable,
820
- });
821
- }
822
- const pointerPosition = getPointerPosition(e);
823
- dragItems.current = getDragItems(nodeInternals, nodesDraggable, pointerPosition, nodeId);
824
- if (onNodeDragStart && dragItems.current) {
825
- const [currentNode, nodes] = getEventHandlerParams({
826
- nodeId,
827
- dragItems: dragItems.current,
828
- nodeInternals,
829
- });
830
- onNodeDragStart(e.sourceEvent, currentNode, nodes);
831
- }
832
- containerBounds.current =
833
- domNode?.getBoundingClientRect() || null;
834
- mousePosition.current = getEventPosition(e.sourceEvent, containerBounds.current);
835
- })
836
- .on('drag', (e) => {
837
- const pointerPosition = getPointerPosition(e);
838
- const { autoPanOnNodeDrag } = store.getState();
839
- if (!autoPanStarted.current && autoPanOnNodeDrag) {
840
- autoPanStarted.current = true;
841
- autoPan();
842
- }
843
- const isChanged = hasChangedPosition(lastPosition.current, pointerPosition.getStepPosition());
844
- if (isChanged && dragItems.current) {
845
- dragEvent.current = e.sourceEvent;
846
- mousePosition.current = getEventPosition(e.sourceEvent, containerBounds.current);
847
- updateNodes(pointerPosition);
848
- updateNodesIntersection(dragItems);
849
- }
850
- })
851
- .on('end', (event) => {
182
+ },
183
+ onDragEnd: (e, _, node, nodes) => {
184
+ const { onNodeDragEnd } = store.getState();
185
+ onNodeDragEnd?.(e, node, nodes);
852
186
  setDragging(false);
853
- autoPanStarted.current = false;
854
- cancelAnimationFrame(autoPanId.current);
855
- if (dragItems.current) {
856
- const { nodeInternals, smoothStep, gridStep, updateNodesPosition, onNodeDragEnd, } = store.getState();
857
- const isSmoothStep = !!gridStep && smoothStep;
858
- if (isSmoothStep) {
859
- const pointerPosition = getPointerPosition(event);
860
- updateNodesPosition(dragItems.current, false, updateNodePosition(pointerPosition, true));
861
- updateNodesIntersection(dragItems);
862
- }
863
- else {
864
- updateNodesPosition(dragItems.current, false);
865
- }
866
- if (onNodeDragEnd) {
867
- const [currentNode, nodes] = getEventHandlerParams({
868
- nodeId,
869
- dragItems: dragItems.current,
870
- nodeInternals,
871
- });
872
- onNodeDragEnd(event.sourceEvent, currentNode, nodes);
873
- }
874
- }
875
- })
876
- .filter((event) => {
877
- const target = event.target;
878
- const isDraggable = !event.button &&
879
- (!noDragClassName ||
880
- !hasSelector(target, `.${noDragClassName}`, nodeRef));
881
- return isDraggable;
187
+ },
188
+ });
189
+ }, []);
190
+ useEffect(() => {
191
+ if (disabled) {
192
+ cosmosDrag.current?.destroy();
193
+ }
194
+ else if (nodeRef.current) {
195
+ cosmosDrag.current?.update({
196
+ noDragClassName,
197
+ domNode: nodeRef.current,
198
+ isSelectable,
199
+ nodeId,
882
200
  });
883
- selection.call(dragHandle);
884
201
  return () => {
885
- selection.on('.drag', null);
202
+ cosmosDrag.current?.destroy();
886
203
  };
887
204
  }
888
- }, [
889
- store,
890
- nodeRef,
891
- nodeId,
892
- isSelectable,
893
- noDragClassName,
894
- getPointerPosition,
895
- ]);
205
+ }, [noDragClassName, disabled, isSelectable, nodeRef, nodeId]);
896
206
  return dragging;
897
- }
207
+ };
898
208
 
899
209
  function SelectionBox({ rect, transform }) {
900
210
  const nodeRef = useRef(null);
@@ -923,7 +233,7 @@ const handleParentExpand = (res, updateItem) => {
923
233
  extendHeight > 0 ||
924
234
  updateItem.position.x < 0 ||
925
235
  updateItem.position.y < 0) {
926
- parent.style = { ...parent.style } || {};
236
+ parent.style = { ...parent.style };
927
237
  parent.style.width = parent.style.width ?? parent.width;
928
238
  parent.style.height = parent.style.height ?? parent.height;
929
239
  if (extendWidth > 0) {
@@ -1056,7 +366,7 @@ const selector$6 = (s) => {
1056
366
  selectionBoxActive,
1057
367
  };
1058
368
  };
1059
- function DragSelection({ children, dragSelectionKeyPressed, }) {
369
+ function DragSelection({ dragSelectionKeyPressed, children, }) {
1060
370
  const store = useStoreApi();
1061
371
  const dragSelection = useRef(null);
1062
372
  const prevSelectedNodesCount = useRef(0);
@@ -1074,6 +384,9 @@ function DragSelection({ children, dragSelectionKeyPressed, }) {
1074
384
  });
1075
385
  const [dragBoxActive, setDragBoxActive] = useState(false);
1076
386
  const resetDragBox = () => {
387
+ store.setState({
388
+ selectionBoxActive: prevSelectedNodesCount.current > 0,
389
+ });
1077
390
  setDragBoxStartPosition({
1078
391
  x: 0,
1079
392
  y: 0,
@@ -1105,7 +418,7 @@ function DragSelection({ children, dragSelectionKeyPressed, }) {
1105
418
  !dragSelectionKeyPressed) {
1106
419
  return;
1107
420
  }
1108
- const { x, y } = getEventPosition(event, containerBounds.current);
421
+ const { x, y } = getEventPosition(event.nativeEvent, containerBounds.current);
1109
422
  resetSelectedElements();
1110
423
  setDragBoxRect({
1111
424
  width: 0,
@@ -1123,16 +436,16 @@ function DragSelection({ children, dragSelectionKeyPressed, }) {
1123
436
  const hasDragBoxStartPosition = dragBoxStartPosition.x > 0 && dragBoxStartPosition.y > 0;
1124
437
  if (
1125
438
  // !hasDragBoxPosition ||
439
+ // !dragSelectionKeyPressed ||
1126
440
  !hasDragBoxStartPosition ||
1127
- !containerBounds.current ||
1128
- !dragSelectionKeyPressed) {
441
+ !containerBounds.current) {
1129
442
  return;
1130
443
  }
1131
444
  store.setState({
1132
445
  selectionBoxActive: false,
1133
446
  });
1134
447
  setDragBoxActive(true);
1135
- const mousePos = getEventPosition(event, containerBounds.current);
448
+ const mousePos = getEventPosition(event.nativeEvent, containerBounds.current);
1136
449
  const startX = dragBoxStartPosition.x ?? 0;
1137
450
  const startY = dragBoxStartPosition.y ?? 0;
1138
451
  const rect = {
@@ -1157,33 +470,20 @@ function DragSelection({ children, dragSelectionKeyPressed, }) {
1157
470
  if (event.button !== 0) {
1158
471
  return;
1159
472
  }
1160
- store.setState({
1161
- selectionBoxActive: prevSelectedNodesCount.current > 0,
1162
- });
1163
473
  resetDragBox();
1164
474
  };
1165
475
  const onMouseLeave = () => {
1166
- store.setState({
1167
- selectionBoxActive: prevSelectedNodesCount.current > 0,
1168
- });
1169
476
  resetDragBox();
1170
477
  };
1171
- const isPossibleDragSelection = elementsSelectable && dragSelectionKeyPressed;
1172
- return (jsxs("div", { ref: dragSelection, className: "react-diagram__container react-diagram__drag-selection", onClick: onClick, onMouseDown: isPossibleDragSelection ? onMouseDown : undefined, onMouseMove: isPossibleDragSelection ? onMouseMove : undefined, onMouseUp: elementsSelectable && dragBoxRect ? onMouseUp : undefined, onMouseLeave: isPossibleDragSelection ? onMouseLeave : undefined, children: [children, dragBoxActive && jsx(DragBox, { rect: dragBoxRect }), selectionBoxActive && (jsx(SelectionBox$1, { rect: selectionBoxRect, transform: transformString }))] }));
478
+ const isPossibleDragSelection = elementsSelectable;
479
+ return (jsxs("div", { ref: dragSelection, className: cc([
480
+ 'react-diagram__container react-diagram__drag-selection',
481
+ ]), onClick: onClick, onMouseDown: isPossibleDragSelection ? onMouseDown : undefined, onMouseMove: isPossibleDragSelection ? onMouseMove : undefined, onMouseUp: elementsSelectable ? onMouseUp : undefined, onMouseLeave: isPossibleDragSelection ? onMouseLeave : undefined, children: [children, dragBoxActive && jsx(DragBox, { rect: dragBoxRect }), selectionBoxActive && (jsx(SelectionBox$1, { rect: selectionBoxRect, transform: transformString }))] }));
1173
482
  }
1174
483
 
1175
- const selector$5 = (s) => {
1176
- const { minZoom, maxZoom, translateExtent } = s;
1177
- return {
1178
- minZoom,
1179
- maxZoom,
1180
- translateExtent,
1181
- };
1182
- };
1183
- function DiagramRenderer({ children, multiSelectionKeyCode, dragSelectionKeyCode, noPanClassName, panning, defaultViewport, onMove, onMoveStart, onMoveEnd, }) {
1184
- const { minZoom, maxZoom, translateExtent } = useStore(selector$5);
484
+ const useDragSelectionKeyPress = (dragSelectionKeyCode) => {
1185
485
  const [dragSelectionKeyPressed, setDragSelectionKeyPressed] = useState(false);
1186
- useGlobalKeyHandler(multiSelectionKeyCode);
486
+ // useKeyPress
1187
487
  const handleKeyDown = (e) => {
1188
488
  if (e.key === dragSelectionKeyCode) {
1189
489
  setDragSelectionKeyPressed(true);
@@ -1200,7 +500,25 @@ function DiagramRenderer({ children, multiSelectionKeyCode, dragSelectionKeyCode
1200
500
  document.removeEventListener('keyup', handleKeyUp);
1201
501
  };
1202
502
  }, []);
1203
- return (jsx(Pane, { noPanClassName: noPanClassName, panning: panning && !dragSelectionKeyPressed, minZoom: minZoom, maxZoom: maxZoom, translateExtent: translateExtent, defaultViewport: defaultViewport, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd, children: jsx(DragSelection, { dragSelectionKeyPressed: dragSelectionKeyPressed, children: jsx(Viewport, { children: children }) }) }));
503
+ return dragSelectionKeyPressed;
504
+ };
505
+
506
+ const selector$5 = (s) => {
507
+ const { minZoom, maxZoom, translateExtent } = s;
508
+ return {
509
+ minZoom,
510
+ maxZoom,
511
+ translateExtent,
512
+ };
513
+ };
514
+ function DiagramRenderer({ children, multiSelectionKeyCode, dragSelectionKeyCode, noPanClassName, panning, defaultViewport, onMove, onMoveStart, onMoveEnd, }) {
515
+ const { minZoom, maxZoom, translateExtent } = useStore(selector$5);
516
+ useGlobalKeyHandler(multiSelectionKeyCode);
517
+ const dragSelectionKeyPressed = useDragSelectionKeyPress(dragSelectionKeyCode);
518
+ // useKeyPress
519
+ const isSelecting = dragSelectionKeyPressed;
520
+ const isPanning = panning && !isSelecting;
521
+ return (jsx(Fragment, { children: jsx(Pane, { noPanClassName: noPanClassName, panning: isPanning, selection: isSelecting, minZoom: minZoom, maxZoom: maxZoom, translateExtent: translateExtent, defaultViewport: defaultViewport, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd, children: jsx(DragSelection, { dragSelectionKeyPressed: dragSelectionKeyPressed, children: jsx(Viewport, { children: children }) }) }) }));
1204
522
  }
1205
523
  DiagramRenderer.displayName = 'DiagramRenderer';
1206
524
  var DiagramRenderer$1 = memo(DiagramRenderer);
@@ -1210,19 +528,6 @@ function useVisibleNodes() {
1210
528
  return nodes;
1211
529
  }
1212
530
 
1213
- var Position;
1214
- (function (Position) {
1215
- Position["Left"] = "left";
1216
- Position["Top"] = "top";
1217
- Position["Right"] = "right";
1218
- Position["Bottom"] = "bottom";
1219
- })(Position || (Position = {}));
1220
-
1221
- var MarkerType;
1222
- (function (MarkerType) {
1223
- MarkerType["Arrow"] = "arrow";
1224
- })(MarkerType || (MarkerType = {}));
1225
-
1226
531
  const selector$4 = (s) => ({
1227
532
  nodesDraggable: s.nodesDraggable,
1228
533
  elementsSelectable: s.elementsSelectable,
@@ -1270,8 +575,8 @@ function NodeRenderer({ nodeTypes, onNodeClick, onNodeMouseEnter, onNodeMouseMov
1270
575
  id,
1271
576
  className,
1272
577
  style,
1273
- width,
1274
- height,
578
+ width: nodeType === 'default' && width ? 120 : undefined,
579
+ height: nodeType === 'default' && height ? 60 : undefined,
1275
580
  ariaLabel,
1276
581
  };
1277
582
  const events = {
@@ -1294,10 +599,10 @@ function NodeRenderer({ nodeTypes, onNodeClick, onNodeMouseEnter, onNodeMouseMov
1294
599
  isSelectable,
1295
600
  isDraggable,
1296
601
  hidden,
1297
- isParent: !!node[internalsSymbol]?.isParent,
602
+ isParent: !!node[internalsSymbol$1]?.isParent,
1298
603
  initialized: !!node.width && !!node.height,
1299
604
  };
1300
- return (jsx(NodeComponent, { ...props, ...elProps, ...position, ...events, ...booleanProps, zIndex: node[internalsSymbol]?.z ?? 0, type: nodeType, data: data, resizeObserver: resizeObserver }, id));
605
+ return (jsx(NodeComponent, { ...props, ...elProps, ...position, ...events, ...booleanProps, zIndex: node[internalsSymbol$1]?.z ?? 0, type: nodeType, data: data, resizeObserver: resizeObserver }, id));
1301
606
  }) }));
1302
607
  }
1303
608
  NodeRenderer.displayName = 'NodeRenderer';
@@ -1388,47 +693,6 @@ function BaseEdge({ path, labelX, labelY, label, labelStyle, labelShowBg, labelB
1388
693
  }
1389
694
  BaseEdge.displayName = 'BaseEdge';
1390
695
 
1391
- const getEdgeCenter = ({ sourceX, sourceY, targetX, targetY, }) => {
1392
- const xOffset = Math.abs(targetX - sourceX) / 2;
1393
- const centerX = targetX < sourceX ? targetX + xOffset : targetX - xOffset;
1394
- const yOffset = Math.abs(targetY - sourceY) / 2;
1395
- const centerY = targetY < sourceY ? targetY + yOffset : targetY - yOffset;
1396
- return [centerX, centerY, xOffset, yOffset];
1397
- };
1398
- const getBezierEdgeCenter = ({ sourceX, sourceY, targetX, targetY, sourceControlX, sourceControlY, targetControlX, targetControlY, }) => {
1399
- // cubic bezier t=0.5 mid point, not the actual mid point, but easy to calculate
1400
- // https://stackoverflow.com/questions/67516101/how-to-find-distance-mid-point-of-bezier-curve
1401
- const midPoint = 0.5;
1402
- const point = 0.125;
1403
- const controlPoint = midPoint - point;
1404
- const centerX = sourceX * point +
1405
- sourceControlX * controlPoint +
1406
- targetControlX * controlPoint +
1407
- targetX * point;
1408
- const centerY = sourceY * point +
1409
- sourceControlY * controlPoint +
1410
- targetControlY * controlPoint +
1411
- targetY * point;
1412
- const offsetX = Math.abs(centerX - sourceX);
1413
- const offsetY = Math.abs(centerY - sourceY);
1414
- return [centerX, centerY, offsetX, offsetY];
1415
- };
1416
-
1417
- const getStraightPath = ({ sourceX, sourceY, targetX, targetY, }) => {
1418
- const [labelX, labelY, offsetX, offsetY] = getEdgeCenter({
1419
- sourceX,
1420
- sourceY,
1421
- targetX,
1422
- targetY,
1423
- });
1424
- return [
1425
- `M ${sourceX},${sourceY}L ${targetX},${targetY}`,
1426
- labelX,
1427
- labelY,
1428
- offsetX,
1429
- offsetY,
1430
- ];
1431
- };
1432
696
  const StraightEdge = memo(({ sourceX, sourceY, targetX, targetY, label, labelStyle, labelShowBg, labelBgStyle, labelBgPadding, labelBgBorderRadius, style, markerEnd, markerStart, }) => {
1433
697
  const [path, labelX, labelY] = getStraightPath({
1434
698
  sourceX,
@@ -1440,109 +704,6 @@ const StraightEdge = memo(({ sourceX, sourceY, targetX, targetY, label, labelSty
1440
704
  });
1441
705
  StraightEdge.displayName = 'StraightEdge';
1442
706
 
1443
- const HANDLE_DIRECTIONS = {
1444
- [Position.Left]: { x: -1, y: 0 },
1445
- [Position.Right]: { x: 1, y: 0 },
1446
- [Position.Top]: { x: 0, y: -1 },
1447
- [Position.Bottom]: { x: 0, y: 1 },
1448
- };
1449
- const getDirection = ({ source, sourcePosition = Position.Bottom, target, }) => {
1450
- if (sourcePosition === Position.Left || sourcePosition === Position.Right) {
1451
- // when source Node position is on the left side of a Port of target Node => x = 1
1452
- return source.x < target.x ? { x: 1, y: 0 } : { x: -1, y: 0 };
1453
- }
1454
- //when source Node position is above of a Port of target Node => y = 1
1455
- return source.y < target.y ? { x: 0, y: 1 } : { x: 0, y: -1 };
1456
- };
1457
- const distance = (a, b) => Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
1458
- function getPoints({ source, sourcePosition = Position.Bottom, target, targetPosition = Position.Top, center, offset, }) {
1459
- const sourceDir = HANDLE_DIRECTIONS[sourcePosition];
1460
- const targetDir = HANDLE_DIRECTIONS[targetPosition];
1461
- const sourceGapped = {
1462
- x: source.x + sourceDir.x * offset,
1463
- y: source.y + sourceDir.y * offset,
1464
- };
1465
- const targetGapped = {
1466
- x: target.x + targetDir.x * offset,
1467
- y: target.y + targetDir.y * offset,
1468
- };
1469
- const direction = getDirection({
1470
- source: sourceGapped,
1471
- sourcePosition,
1472
- target: targetGapped,
1473
- });
1474
- const dirAccessor = direction.x !== 0 ? 'x' : 'y';
1475
- const currentDirection = direction[dirAccessor];
1476
- let points = [];
1477
- let centerX = 0, centerY = 0;
1478
- const [defaultCenterX, defaultCenterY, defaultOffsetX, defaultOffsetY] = getEdgeCenter({
1479
- sourceX: source.x,
1480
- sourceY: source.y,
1481
- targetX: target.x,
1482
- targetY: target.y,
1483
- });
1484
- const isSourceAndTargetPositionsParallel = sourceDir[dirAccessor] * targetDir[dirAccessor] === -1;
1485
- if (isSourceAndTargetPositionsParallel) {
1486
- centerX = center.x || defaultCenterX;
1487
- centerY = center.y || defaultCenterY;
1488
- const verticalSplit = [
1489
- { x: centerX, y: sourceGapped.y },
1490
- { x: centerX, y: targetGapped.y },
1491
- ];
1492
- const horizontalSplit = [
1493
- { x: sourceGapped.x, y: centerY },
1494
- { x: targetGapped.x, y: centerY },
1495
- ];
1496
- const centerLineIsBent = sourceDir[dirAccessor] !== currentDirection;
1497
- if (centerLineIsBent) {
1498
- points = dirAccessor === 'x' ? horizontalSplit : verticalSplit;
1499
- }
1500
- else {
1501
- points = dirAccessor === 'x' ? verticalSplit : horizontalSplit;
1502
- }
1503
- }
1504
- const pathPoints = [source, sourceGapped, ...points, targetGapped, target];
1505
- return [pathPoints, centerX, centerY, defaultOffsetX, defaultOffsetY];
1506
- }
1507
- function getBend(a, b, c, size) {
1508
- const bendSize = Math.min(distance(a, b) / 2, distance(b, c) / 2, size);
1509
- const { x, y } = b;
1510
- // no bend
1511
- if ((a.x === x && x === c.x) || (a.y === y && y === c.y)) {
1512
- return `L${x} ${y}`;
1513
- }
1514
- // first segment is horizontal
1515
- if (a.y === y) {
1516
- const xDir = a.x < c.x ? -1 : 1;
1517
- const yDir = a.y < c.y ? 1 : -1;
1518
- return `L ${x + bendSize * xDir},${y}Q ${x},${y} ${x},${y + bendSize * yDir}`;
1519
- }
1520
- const xDir = a.x < c.x ? 1 : -1;
1521
- const yDir = a.y < c.y ? -1 : 1;
1522
- return `L ${x},${y + bendSize * yDir}Q ${x},${y} ${x + bendSize * xDir},${y}`;
1523
- }
1524
- function getStepPath({ sourceX, sourceY, sourcePosition = Position.Bottom, targetX, targetY, targetPosition = Position.Top, borderRadius = 5, centerX, centerY, offset = 20, }) {
1525
- const [points, labelX, labelY, offsetX, offsetY] = getPoints({
1526
- source: { x: sourceX, y: sourceY },
1527
- sourcePosition,
1528
- target: { x: targetX, y: targetY },
1529
- targetPosition,
1530
- center: { x: centerX, y: centerY },
1531
- offset,
1532
- });
1533
- const path = points.reduce((res, p, i) => {
1534
- let segment = '';
1535
- if (i > 0 && i < points.length - 1) {
1536
- segment = getBend(points[i - 1], p, points[i + 1], borderRadius);
1537
- }
1538
- else {
1539
- segment = `${i === 0 ? 'M' : 'L'}${p.x} ${p.y}`;
1540
- }
1541
- res += segment;
1542
- return res;
1543
- }, '');
1544
- return [path, labelX, labelY, offsetX, offsetY];
1545
- }
1546
707
  const StepEdge = memo(({ sourceX, sourceY, targetX, targetY, label, labelStyle, labelShowBg, labelBgStyle, labelBgPadding, labelBgBorderRadius, style, sourcePosition = Position.Bottom, targetPosition = Position.Top, markerEnd, markerStart, pathOptions, }) => {
1547
708
  const [path, labelX, labelY] = getStepPath({
1548
709
  sourceX,
@@ -1558,59 +719,6 @@ const StepEdge = memo(({ sourceX, sourceY, targetX, targetY, label, labelStyle,
1558
719
  });
1559
720
  StepEdge.displayName = 'StepEdge';
1560
721
 
1561
- const calculateControlOffset = (distance, curvature) => {
1562
- if (distance >= 0) {
1563
- return 0.5 * distance;
1564
- }
1565
- return curvature * 25 * Math.sqrt(-distance);
1566
- };
1567
- const getControlWithCurvature = ({ pos, x1, y1, x2, y2, c, }) => {
1568
- switch (pos) {
1569
- case Position.Left:
1570
- return [x1 - calculateControlOffset(x1 - x2, c), y1];
1571
- case Position.Right:
1572
- return [x1 + calculateControlOffset(x2 - x1, c), y1];
1573
- case Position.Top:
1574
- return [x1, y1 - calculateControlOffset(y1 - y2, c)];
1575
- case Position.Bottom:
1576
- return [x1, y1 + calculateControlOffset(y2 - y1, c)];
1577
- }
1578
- };
1579
- const getBezierPath = ({ sourceX, sourceY, sourcePosition = Position.Bottom, targetX, targetY, targetPosition = Position.Top, curvature = 0.25, }) => {
1580
- const [sourceControlX, sourceControlY] = getControlWithCurvature({
1581
- pos: sourcePosition,
1582
- x1: sourceX,
1583
- y1: sourceY,
1584
- x2: targetX,
1585
- y2: targetY,
1586
- c: curvature,
1587
- });
1588
- const [targetControlX, targetControlY] = getControlWithCurvature({
1589
- pos: targetPosition,
1590
- x1: targetX,
1591
- y1: targetY,
1592
- x2: sourceX,
1593
- y2: sourceY,
1594
- c: curvature,
1595
- });
1596
- const [labelX, labelY, offsetX, offsetY] = getBezierEdgeCenter({
1597
- sourceX,
1598
- sourceY,
1599
- targetX,
1600
- targetY,
1601
- sourceControlX,
1602
- sourceControlY,
1603
- targetControlX,
1604
- targetControlY,
1605
- });
1606
- return [
1607
- `M${sourceX},${sourceY} C${sourceControlX},${sourceControlY} ${targetControlX},${targetControlY} ${targetX},${targetY}`,
1608
- labelX,
1609
- labelY,
1610
- offsetX,
1611
- offsetY,
1612
- ];
1613
- };
1614
722
  const BezierEdge = memo(({ sourceX, sourceY, targetX, targetY, sourcePosition = Position.Bottom, targetPosition = Position.Top, label, labelStyle, labelShowBg, labelBgStyle, labelBgPadding, labelBgBorderRadius, style, markerEnd, markerStart, pathOptions, }) => {
1615
723
  const [path, labelX, labelY] = getBezierPath({
1616
724
  sourceX,
@@ -1628,171 +736,6 @@ BezierEdge.displayName = 'BezierEdge';
1628
736
  const ARIA_NODE_DESC_KEY = 'react-diagram__node-desc';
1629
737
  const ARIA_EDGE_DESC_KEY = 'react-diagram__edge-desc';
1630
738
 
1631
- const getHostForElement = (element) => element.getRootNode?.() || window?.document;
1632
- const getPortType = (PortDomNode) => {
1633
- if (PortDomNode?.classList.contains('target')) {
1634
- return 'target';
1635
- }
1636
- else if (PortDomNode?.classList.contains('source')) {
1637
- return 'source';
1638
- }
1639
- return null;
1640
- };
1641
- const getConnection = (event, port, fromNodeId, fromType, doc) => {
1642
- const isTarget = fromType === 'target';
1643
- const result = {
1644
- isValid: false,
1645
- connection: {
1646
- source: null,
1647
- target: null,
1648
- },
1649
- };
1650
- const PortDomNode = doc.querySelector(`.react-diagram__port[data-id="${port?.nodeId}-${port?.type}"]`);
1651
- const { x, y } = getEventPosition(event);
1652
- const ElementFromPoint = doc.elementFromPoint(x, y);
1653
- const Port = ElementFromPoint?.classList.contains('react-diagram__port')
1654
- ? ElementFromPoint
1655
- : PortDomNode;
1656
- if (Port) {
1657
- const portType = getPortType(Port);
1658
- const toNodeId = Port.getAttribute('data-nodeid');
1659
- const connection = {
1660
- source: isTarget ? toNodeId : fromNodeId,
1661
- target: isTarget ? fromNodeId : toNodeId,
1662
- };
1663
- result.connection = connection;
1664
- const isValid = (isTarget && portType === 'source') ||
1665
- (!isTarget && portType === 'target');
1666
- if (isValid) {
1667
- result.isValid = true;
1668
- }
1669
- }
1670
- return result;
1671
- };
1672
- const getPorts = (node, portBounds, type, currentPort) => (portBounds[type] || []).reduce((res, h) => {
1673
- if (`${node.id}-${type}` !== currentPort) {
1674
- res.push({
1675
- type,
1676
- nodeId: node.id,
1677
- x: (node.positionAbsolute?.x ?? 0) + h.x + h.width / 2,
1678
- y: (node.positionAbsolute?.y ?? 0) + h.y + h.height / 2,
1679
- });
1680
- }
1681
- return res;
1682
- }, []);
1683
- const getAllPort = ({ nodes, nodeId, portType }) => nodes.reduce((res, node) => {
1684
- if (node[internalsSymbol]) {
1685
- const { portBounds } = node[internalsSymbol];
1686
- let sourcePorts = [];
1687
- let targetPorts = [];
1688
- if (portBounds) {
1689
- sourcePorts = getPorts(node, portBounds, 'source', `${nodeId}-${portType}`);
1690
- targetPorts = getPorts(node, portBounds, 'target', `${nodeId}-${portType}`);
1691
- }
1692
- res.push(...sourcePorts, ...targetPorts);
1693
- }
1694
- return res;
1695
- }, []);
1696
- const getClosestPort = (pos, connectionRadius, ports) => {
1697
- let closestPort = null;
1698
- let minDistance = Infinity;
1699
- ports.forEach((port) => {
1700
- const distance = Math.sqrt(Math.pow(port.x - pos.x, 2) + Math.pow(port.y - pos.y, 2));
1701
- if (distance <= connectionRadius && distance < minDistance) {
1702
- minDistance = distance;
1703
- closestPort = port;
1704
- }
1705
- });
1706
- return closestPort;
1707
- };
1708
- const pointToRendererPoint = ({ x, y }, [tx, ty, tScale]) => {
1709
- const position = {
1710
- x: (x - tx) / tScale,
1711
- y: (y - ty) / tScale,
1712
- };
1713
- return position;
1714
- };
1715
- const rendererPointToPoint = ({ x, y }, [tx, ty, tScale]) => {
1716
- return {
1717
- x: x * tScale + tx,
1718
- y: y * tScale + ty,
1719
- };
1720
- };
1721
- const handlePointerDown = ({ isAnchor = false, event, nodeId, portType, getState, setState, onConnect, onEdgeUpdateEnd, }) => {
1722
- const doc = getHostForElement(event.target);
1723
- const { domNode, autoPanOnConnect, connectionRadius, getNodes, cancelConnection, onConnectStart, onConnectEnd, panBy, } = getState();
1724
- const containerBounds = domNode?.getBoundingClientRect();
1725
- const { x, y } = getEventPosition(event);
1726
- const clickedPort = doc?.elementFromPoint(x, y);
1727
- const clickedPortType = isAnchor ? portType : getPortType(clickedPort);
1728
- const allPort = getAllPort({
1729
- nodes: getNodes(),
1730
- nodeId,
1731
- portType,
1732
- });
1733
- let connectionPosition = getEventPosition(event, containerBounds);
1734
- let closestPort = null;
1735
- let isValid = false;
1736
- let connection = null;
1737
- let autoPanId = 0;
1738
- let autoPanStarted = false;
1739
- if (!containerBounds || !portType) {
1740
- return;
1741
- }
1742
- const autoPan = () => {
1743
- if (!autoPanOnConnect) {
1744
- return;
1745
- }
1746
- const [xMovement, yMovement] = calcAutoPanPosition(connectionPosition, containerBounds);
1747
- panBy({ x: xMovement, y: yMovement });
1748
- autoPanId = requestAnimationFrame(autoPan);
1749
- };
1750
- setState({
1751
- connectionPosition,
1752
- connectionNodeId: nodeId,
1753
- connectionPortType: clickedPortType,
1754
- });
1755
- onConnectStart?.(event, { nodeId, portType });
1756
- const onPointerMove = (event) => {
1757
- const { transform } = getState();
1758
- connectionPosition = getEventPosition(event, containerBounds);
1759
- closestPort = getClosestPort(pointToRendererPoint(connectionPosition, transform), connectionRadius, allPort);
1760
- if (!autoPanStarted) {
1761
- autoPan();
1762
- autoPanStarted = true;
1763
- }
1764
- const result = getConnection(event, closestPort, nodeId, portType, doc);
1765
- isValid = result.isValid;
1766
- connection = result.connection;
1767
- setState({
1768
- connectionPosition: closestPort && isValid
1769
- ? rendererPointToPoint(closestPort, transform)
1770
- : connectionPosition,
1771
- });
1772
- };
1773
- const onPointerUp = (event) => {
1774
- if (isValid && connection)
1775
- onConnect?.(connection);
1776
- onConnectEnd?.(event);
1777
- if (portType) {
1778
- onEdgeUpdateEnd?.(event);
1779
- }
1780
- cancelConnection();
1781
- cancelAnimationFrame(autoPanId);
1782
- isValid = false;
1783
- connection = null;
1784
- autoPanStarted = false;
1785
- doc.removeEventListener('mousemove', onPointerMove);
1786
- doc.removeEventListener('mouseup', onPointerUp);
1787
- doc.removeEventListener('touchmove', onPointerMove);
1788
- doc.removeEventListener('touchend', onPointerUp);
1789
- };
1790
- doc.addEventListener('mousemove', onPointerMove);
1791
- doc.addEventListener('mouseup', onPointerUp);
1792
- doc.addEventListener('touchmove', onPointerMove);
1793
- doc.addEventListener('touchend', onPointerUp);
1794
- };
1795
-
1796
739
  const portPositionX = (x, shift, position) => {
1797
740
  if (position === Position.Left)
1798
741
  return x - shift;
@@ -1874,9 +817,10 @@ const wrapEdge = (EdgeComponent) => {
1874
817
  if (event.button !== 0) {
1875
818
  return;
1876
819
  }
1877
- const { edges } = store.getState();
820
+ const { edges, domNode, autoPanOnConnect, connectionRadius, transform, getNodes, cancelConnection, updateConnection, onConnectStart, onConnectEnd, panBy, } = store.getState();
1878
821
  const nodeId = props[fromPortType];
1879
822
  const edge = edges.find((e) => e.id === id);
823
+ const portId = (fromPortType === 'source' ? sourcePort : targetPort) || null;
1880
824
  setUpdating(true);
1881
825
  onEdgeUpdateStart?.(event, edge, fromPortType);
1882
826
  const onConnectEdge = (connection) => onEdgeUpdate?.(edge, connection);
@@ -1884,15 +828,24 @@ const wrapEdge = (EdgeComponent) => {
1884
828
  setUpdating(false);
1885
829
  onEdgeUpdateEnd?.(evt, edge, fromPortType);
1886
830
  };
1887
- handlePointerDown({
831
+ CosmosPort.onPointerDown({
1888
832
  isAnchor: true,
1889
- event,
833
+ event: event.nativeEvent,
1890
834
  nodeId,
835
+ portId,
1891
836
  portType: fromPortType,
1892
- getState: store.getState,
1893
- setState: store.setState,
1894
- onConnect: onConnectEdge,
837
+ domNode,
838
+ autoPanOnConnect,
839
+ connectionRadius,
840
+ nodes: getNodes(),
1895
841
  onEdgeUpdateEnd: handleEdgeUpdateEnd,
842
+ cancelConnection,
843
+ updateConnection,
844
+ onConnect: onConnectEdge,
845
+ onConnectStart,
846
+ onConnectEnd,
847
+ panBy,
848
+ getTransform: () => transform,
1896
849
  });
1897
850
  };
1898
851
  const onEdgeClick = (event) => {
@@ -2016,7 +969,7 @@ const getEdgePositions = (sourceNodeRect, sourcePort, sourcePosition, targetNode
2016
969
  };
2017
970
  };
2018
971
  function getNodeData(node) {
2019
- const portBounds = node?.[internalsSymbol]?.portBounds || null;
972
+ const portBounds = node?.[internalsSymbol$1]?.portBounds || null;
2020
973
  const isValid = portBounds &&
2021
974
  node?.width &&
2022
975
  node?.height &&
@@ -2123,17 +1076,19 @@ const oppositePosition = {
2123
1076
  [Position.Bottom]: Position.Top,
2124
1077
  };
2125
1078
  function ConnectionPath({ nodeId, portType, edge, Component, EdgeWrapper, }) {
2126
- const { fromNode, toX, toY } = useStore(useCallback((s) => ({
1079
+ const { fromNode, toX, toY, startPort } = useStore(useCallback((s) => ({
2127
1080
  fromNode: s.nodeInternals.get(nodeId),
1081
+ startPort: s.connectionStartPort,
2128
1082
  toX: (s.connectionPosition.x - s.transform[0]) / s.transform[2],
2129
1083
  toY: (s.connectionPosition.y - s.transform[1]) / s.transform[2],
2130
1084
  }), [nodeId]), shallow);
2131
- const fromPortBounds = fromNode?.[internalsSymbol]?.portBounds;
1085
+ const fromPortBounds = fromNode?.[internalsSymbol$1]?.portBounds;
2132
1086
  const portBounds = fromPortBounds?.[portType];
2133
1087
  if (!fromNode || !portBounds) {
2134
1088
  return null;
2135
1089
  }
2136
- const fromPort = portBounds[0];
1090
+ const fromPort = portBounds.find((bound) => bound.id === startPort?.portId) ||
1091
+ portBounds[0];
2137
1092
  const fromPortX = fromPort
2138
1093
  ? fromPort.x + fromPort.width / 2
2139
1094
  : (fromNode.width ?? 0) / 2;
@@ -2160,11 +1115,13 @@ ConnectionPath.displayName = 'ConnectionPath';
2160
1115
 
2161
1116
  const selector$2 = (s) => ({
2162
1117
  edges: s.edges,
2163
- nodeId: s.connectionNodeId,
2164
- portType: s.connectionPortType,
1118
+ startPort: s.connectionStartPort,
2165
1119
  });
2166
1120
  function ConnectionLineRenderer({ containerStyle, edgeTypes, component, }) {
2167
- const { nodeId, portType, edges } = useStore(selector$2, shallow);
1121
+ const { startPort, edges } = useStore(selector$2, shallow);
1122
+ if (!startPort)
1123
+ return null;
1124
+ const { nodeId, portType } = startPort;
2168
1125
  const isValid = !!(nodeId && portType);
2169
1126
  if (!isValid) {
2170
1127
  return null;
@@ -2180,16 +1137,19 @@ function DiagramView({ rfId,
2180
1137
  // DiagramRenderer props
2181
1138
  noPanClassName, panning, defaultViewport, multiSelectionKeyCode, dragSelectionKeyCode, onMove, onMoveStart, onMoveEnd,
2182
1139
  // NodeRenderer props
2183
- onlyRenderVisibleElements, disableKeyboardA11y, noDragClassName, nodeOrigin, nodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave,
1140
+ onlyRenderVisibleElements, disableKeyboardA11y, noDragClassName, nodeOrigin, nodeExtent, nodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave,
2184
1141
  // EdgeRenderer props
2185
1142
  edgeTypes, edgeUpdaterRadius, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd,
2186
1143
  // ConnectionLineWrapper
2187
1144
  ConnectionLineContainerStyle, ConnectionLineComponent, }) {
2188
- return (jsxs(DiagramRenderer$1, { multiSelectionKeyCode: multiSelectionKeyCode, dragSelectionKeyCode: dragSelectionKeyCode, noPanClassName: noPanClassName, panning: panning, defaultViewport: defaultViewport, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd, children: [jsx(NodeRenderer$1, { rfId: rfId, nodeTypes: nodeTypes, onlyRenderVisibleElements: onlyRenderVisibleElements, disableKeyboardA11y: disableKeyboardA11y, nodeOrigin: nodeOrigin, noDragClassName: noDragClassName, noPanClassName: noPanClassName, onNodeClick: onNodeClick, onNodeDoubleClick: onNodeDoubleClick, onNodeContextMenu: onNodeContextMenu, onNodeMouseEnter: onNodeMouseEnter, onNodeMouseMove: onNodeMouseMove, onNodeMouseLeave: onNodeMouseLeave }), jsx(EdgeRenderer$1, { rfId: rfId, edgeTypes: edgeTypes, noPanClassName: noPanClassName, edgeUpdaterRadius: edgeUpdaterRadius, onEdgeClick: onEdgeClick, onEdgeDoubleClick: onEdgeDoubleClick, onEdgeContextMenu: onEdgeContextMenu, onEdgeMouseEnter: onEdgeMouseEnter, onEdgeMouseMove: onEdgeMouseMove, onEdgeMouseLeave: onEdgeMouseLeave, onEdgeUpdate: onEdgeUpdate, onEdgeUpdateStart: onEdgeUpdateStart, onEdgeUpdateEnd: onEdgeUpdateEnd }), jsx(ConnectionLineRenderer, { edgeTypes: edgeTypes, containerStyle: ConnectionLineContainerStyle, component: ConnectionLineComponent })] }));
1145
+ return (jsxs(DiagramRenderer$1, { multiSelectionKeyCode: multiSelectionKeyCode, dragSelectionKeyCode: dragSelectionKeyCode, noPanClassName: noPanClassName, panning: panning, defaultViewport: defaultViewport, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd, children: [jsx(NodeRenderer$1, { rfId: rfId, nodeTypes: nodeTypes, onlyRenderVisibleElements: onlyRenderVisibleElements, disableKeyboardA11y: disableKeyboardA11y, nodeOrigin: nodeOrigin, nodeExtent: nodeExtent, noDragClassName: noDragClassName, noPanClassName: noPanClassName, onNodeClick: onNodeClick, onNodeDoubleClick: onNodeDoubleClick, onNodeContextMenu: onNodeContextMenu, onNodeMouseEnter: onNodeMouseEnter, onNodeMouseMove: onNodeMouseMove, onNodeMouseLeave: onNodeMouseLeave }), jsx(EdgeRenderer$1, { rfId: rfId, edgeTypes: edgeTypes, noPanClassName: noPanClassName, edgeUpdaterRadius: edgeUpdaterRadius, onEdgeClick: onEdgeClick, onEdgeDoubleClick: onEdgeDoubleClick, onEdgeContextMenu: onEdgeContextMenu, onEdgeMouseEnter: onEdgeMouseEnter, onEdgeMouseMove: onEdgeMouseMove, onEdgeMouseLeave: onEdgeMouseLeave, onEdgeUpdate: onEdgeUpdate, onEdgeUpdateStart: onEdgeUpdateStart, onEdgeUpdateEnd: onEdgeUpdateEnd }), jsx(ConnectionLineRenderer, { edgeTypes: edgeTypes, containerStyle: ConnectionLineContainerStyle, component: ConnectionLineComponent })] }));
2189
1146
  }
2190
1147
  DiagramView.displayName = 'DiagramView';
2191
1148
  var DiagramView$1 = memo(DiagramView);
2192
1149
 
1150
+ const internalsSymbol = Symbol.for('internals');
1151
+ const onErrorWrapper = (onError) => (id, value = '') => onError?.(id, errorMessages[id](value));
1152
+
2193
1153
  const selector$1 = (s) => {
2194
1154
  const { setNodes, setEdges, setNodeExtent, setTranslateExtent, setMinZoom, setMaxZoom, } = s;
2195
1155
  return {
@@ -2216,15 +1176,17 @@ function useDirectStoreUpdater(key, value, setState) {
2216
1176
  }
2217
1177
  }, [value]);
2218
1178
  }
2219
- const StoreUpdater = ({ nodes, onNodesChange, onNodeDrag, onNodeDragStart, onNodeDragEnd, edges, onEdgesChange, smoothStep, centerStep, gridStep, elevateNodesOnSelect, nodesDraggable, autoPanOnNodeDrag, autoPanOnConnect, connectionRadius, onConnect, onConnectStart, onConnectEnd, onError, nodeExtent, translateExtent, minZoom, maxZoom, }) => {
1179
+ const StoreUpdater = ({ nodes, onNodesChange, onNodeDrag, onNodeDragStart, onNodeDragEnd, edges, onEdgesChange, nodeOrigin, smoothStep, centerStep, gridStep, elevateNodesOnSelect, nodesDraggable, autoPanOnNodeDrag, autoPanOnConnect, connectionRadius, onConnect, onConnectStart, onConnectEnd, onError, nodeExtent, translateExtent, minZoom, maxZoom, }) => {
2220
1180
  const { setNodes, setEdges, setNodeExtent, setTranslateExtent, setMinZoom, setMaxZoom, } = useStore(selector$1, shallow);
2221
1181
  const store = useStoreApi();
2222
1182
  useStoreUpdater(nodes, setNodes);
2223
1183
  useStoreUpdater(edges, setEdges);
2224
1184
  useStoreUpdater(nodeExtent, setNodeExtent);
1185
+ useStoreUpdater(nodeExtent, setNodeExtent);
2225
1186
  useStoreUpdater(translateExtent, setTranslateExtent);
2226
1187
  useStoreUpdater(minZoom, setMinZoom);
2227
1188
  useStoreUpdater(maxZoom, setMaxZoom);
1189
+ useDirectStoreUpdater('nodeOrigin', nodeOrigin, store.setState);
2228
1190
  useDirectStoreUpdater('smoothStep', smoothStep, store.setState);
2229
1191
  useDirectStoreUpdater('centerStep', centerStep, store.setState);
2230
1192
  useDirectStoreUpdater('gridStep', gridStep, store.setState);
@@ -2268,7 +1230,8 @@ const useNodeId = () => {
2268
1230
  return nodeId;
2269
1231
  };
2270
1232
 
2271
- function Port({ type, position }) {
1233
+ function Port({ id, type, position }) {
1234
+ const portId = id || null;
2272
1235
  const store = useStoreApi();
2273
1236
  const nodeId = useNodeId();
2274
1237
  if (!nodeId)
@@ -2282,19 +1245,30 @@ function Port({ type, position }) {
2282
1245
  onConnect?.(edgeParams);
2283
1246
  };
2284
1247
  const onPointerDown = (event) => {
2285
- const isMouseTriggered = isMouseEvent(event);
2286
- if ((isMouseTriggered && event.button === 0) || !isMouseTriggered) {
2287
- handlePointerDown({
2288
- event,
1248
+ const isMouseTriggered = isMouseEvent(event.nativeEvent);
1249
+ const { button } = event;
1250
+ if ((isMouseTriggered && button === 0) || !isMouseTriggered) {
1251
+ const { domNode, autoPanOnConnect, connectionRadius, transform, getNodes, cancelConnection, updateConnection, onConnectStart, onConnectEnd, panBy, } = store.getState();
1252
+ CosmosPort.onPointerDown({
1253
+ event: event.nativeEvent,
2289
1254
  nodeId,
1255
+ portId,
2290
1256
  portType: type,
2291
- getState: store.getState,
2292
- setState: store.setState,
1257
+ domNode,
1258
+ autoPanOnConnect,
1259
+ connectionRadius,
1260
+ nodes: getNodes(),
1261
+ cancelConnection,
1262
+ updateConnection,
2293
1263
  onConnect: handleOnConnect,
1264
+ onConnectStart,
1265
+ onConnectEnd,
1266
+ panBy,
1267
+ getTransform: () => transform,
2294
1268
  });
2295
1269
  }
2296
1270
  };
2297
- return (jsx("div", { "data-nodeid": nodeId, "data-id": `${nodeId}-${type}`, "data-port-position": position, className: `react-diagram__port react-diagram__port-${position} ${type} nodrag`, onMouseDown: onPointerDown, onTouchStart: onPointerDown }));
1271
+ return (jsx("div", { "data-nodeid": nodeId, "data-id": `${nodeId}-${portId}-${type}`, "data-portid": portId, "data-port-position": position, className: `react-diagram__port react-diagram__port-${position} ${type} nodrag`, onMouseDown: onPointerDown, onTouchStart: onPointerDown }));
2298
1272
  }
2299
1273
  Port.displayName = 'Port';
2300
1274
  var Port$1 = memo(Port);
@@ -2304,8 +1278,9 @@ function Nodes({ data }) {
2304
1278
  }
2305
1279
 
2306
1280
  const wrapNode = (NodeComponent) => {
2307
- function NodeWrapper({ id, type, data, positionX, positionY, sourcePosition, targetPosition, onClick, onMouseEnter, onMouseMove, onMouseLeave, onContextMenu, onDoubleClick, style, width, height, className, selected, isSelectable, isDraggable, intersected, hidden, resizeObserver, dragHandle, zIndex, isParent, initialized, disableKeyboardA11y, ariaLabel, rfId, noDragClassName, noPanClassName, }) {
1281
+ function NodeWrapper({ id, type, data, positionX, positionY, sourcePosition, targetPosition, onClick, onMouseEnter, onMouseMove, onMouseLeave, onContextMenu, onDoubleClick, style, width, height, className, selected, isSelectable, isDraggable, intersected, nodeOrigin, nodeExtent, hidden, resizeObserver, dragHandle, zIndex, isParent, initialized, disableKeyboardA11y, ariaLabel, rfId, noDragClassName, noPanClassName, }) {
2308
1282
  const store = useStoreApi();
1283
+ const node = store.getState().nodeInternals.get(id);
2309
1284
  const nodeRef = useRef(null);
2310
1285
  const prevSourcePosition = useRef(sourcePosition);
2311
1286
  const prevTargetPosition = useRef(targetPosition);
@@ -2317,10 +1292,10 @@ const wrapNode = (NodeComponent) => {
2317
1292
  id,
2318
1293
  store,
2319
1294
  nodeRef,
1295
+ isSelectable,
2320
1296
  });
2321
1297
  }
2322
1298
  if (onClick) {
2323
- const node = store.getState().nodeInternals.get(id);
2324
1299
  onClick(event, { ...node });
2325
1300
  }
2326
1301
  };
@@ -2354,9 +1329,14 @@ const wrapNode = (NodeComponent) => {
2354
1329
  ]);
2355
1330
  }
2356
1331
  }, [id, type, sourcePosition, targetPosition]);
1332
+ const clampedPosition = nodeExtent
1333
+ ? clampPosition(node.positionAbsolute, nodeExtent)
1334
+ : node.positionAbsolute;
1335
+ const positionWithOrigin = getNodePositionWithOrigin({ ...node, ...clampedPosition }, nodeOrigin);
2357
1336
  const dragging = useDrag({
2358
1337
  nodeRef,
2359
1338
  nodeId: id,
1339
+ disabled: hidden || !isDraggable,
2360
1340
  isSelectable,
2361
1341
  noDragClassName,
2362
1342
  });
@@ -2379,7 +1359,7 @@ const wrapNode = (NodeComponent) => {
2379
1359
  ]);
2380
1360
  const wrapperStyle = {
2381
1361
  zIndex,
2382
- transform: `translate(${positionX}px,${positionY}px)`,
1362
+ transform: `translate(${positionWithOrigin.x}px,${positionWithOrigin.y}px)`,
2383
1363
  pointerEvents: hasPointerEvents ? 'all' : 'none',
2384
1364
  visibility: initialized ? 'visible' : 'hidden',
2385
1365
  width,
@@ -2423,12 +1403,6 @@ const createNodeTypes = (nodeTypes) => {
2423
1403
  };
2424
1404
  };
2425
1405
 
2426
- // import { StoreApi } from 'zustand';
2427
- // type UpdateNodesParams = {
2428
- // changedNodes: NodeSelectionChange[] | null;
2429
- // get: StoreApi<ReactDiagramState>['getState'];
2430
- // set: StoreApi<ReactDiagramState>['setState'];
2431
- // };
2432
1406
  function calculateXYZPosition(node, nodeInternals, result, nodeOrigin) {
2433
1407
  if (!node.parentNode) {
2434
1408
  return result;
@@ -2438,8 +1412,8 @@ function calculateXYZPosition(node, nodeInternals, result, nodeOrigin) {
2438
1412
  return calculateXYZPosition(parentNode, nodeInternals, {
2439
1413
  x: (result.x ?? 0) + parentNodePosition.x,
2440
1414
  y: (result.y ?? 0) + parentNodePosition.y,
2441
- z: (parentNode[internalsSymbol]?.z ?? 0) > (result.z ?? 0)
2442
- ? parentNode[internalsSymbol]?.z ?? 0
1415
+ z: (parentNode[internalsSymbol$1]?.z ?? 0) > (result.z ?? 0)
1416
+ ? parentNode[internalsSymbol$1]?.z ?? 0
2443
1417
  : result.z ?? 0,
2444
1418
  }, nodeOrigin);
2445
1419
  }
@@ -2451,15 +1425,15 @@ function updateAbsoluteNodePositions(nodeInternals, nodeOrigin, parentNodes) {
2451
1425
  if (node.parentNode || parentNodes?.[node.id]) {
2452
1426
  const { x, y, z } = calculateXYZPosition(node, nodeInternals, {
2453
1427
  ...node.position,
2454
- z: node[internalsSymbol]?.z ?? 0,
1428
+ z: node[internalsSymbol$1]?.z ?? 0,
2455
1429
  }, nodeOrigin);
2456
1430
  node.positionAbsolute = {
2457
1431
  x,
2458
1432
  y,
2459
1433
  };
2460
- node[internalsSymbol].z = z;
1434
+ node[internalsSymbol$1].z = z;
2461
1435
  if (parentNodes?.[node.id]) {
2462
- node[internalsSymbol].isParent = true;
1436
+ node[internalsSymbol$1].isParent = true;
2463
1437
  }
2464
1438
  }
2465
1439
  });
@@ -2485,56 +1459,42 @@ function createNodeInternals(nodes, nodeInternals, nodeOrigin, elevateNodesOnSel
2485
1459
  internals.parentNode = node.parentNode;
2486
1460
  parentNodes[node.parentNode] = true;
2487
1461
  }
2488
- Object.defineProperty(internals, internalsSymbol, {
1462
+ Object.defineProperty(internals, internalsSymbol$1, {
2489
1463
  enumerable: false,
2490
1464
  value: {
2491
- portBounds: currInternals?.[internalsSymbol]?.portBounds,
1465
+ portBounds: currInternals?.[internalsSymbol$1]?.portBounds,
2492
1466
  z,
2493
1467
  },
2494
1468
  });
2495
- // console.log('create', currInternals, node);
2496
1469
  nextNodeInternals.set(node.id, internals);
2497
1470
  });
2498
1471
  updateAbsoluteNodePositions(nextNodeInternals, nodeOrigin, parentNodes);
2499
1472
  return nextNodeInternals;
2500
1473
  }
2501
- // export function handleControlledNodeSelectionChange(
2502
- // nodeChanges: NodeSelectionChange[],
2503
- // nodeInternals: NodeInternals,
2504
- // ) {
2505
- // nodeChanges.forEach((change) => {
2506
- // const node = nodeInternals.get(change.id);
2507
- // if (node) {
2508
- // nodeInternals.set(node.id, {
2509
- // ...node,
2510
- // [internalsSymbol]: node[internalsSymbol],
2511
- // selected: change.selected,
2512
- // });
2513
- // }
2514
- // });
2515
- // return new Map(nodeInternals);
2516
- // }
2517
- // export function handleControlledEdgeSelectionChange(
2518
- // edgeChanges: EdgeSelectionChange[],
2519
- // edges: Edge[],
2520
- // ) {
2521
- // return edges.map((e) => {
2522
- // const change = edgeChanges.find((change) => change.id === e.id);
2523
- // if (change) {
2524
- // e.selected = change.selected;
2525
- // }
2526
- // return e;
2527
- // });
2528
- // }
2529
- // export function updateNodesSelections({
2530
- // changedNodes,
2531
- // get,
2532
- // }: UpdateNodesParams) {
2533
- // const { onNodesChange } = get();
2534
- // if (changedNodes?.length) {
2535
- // onNodesChange?.(changedNodes);
2536
- // }
2537
- // }
1474
+ const isIntersected = (targetNode, nodeInternals) => {
1475
+ const { id, width, height, positionAbsolute } = targetNode;
1476
+ if (!width || !height)
1477
+ return false;
1478
+ let intersected = false;
1479
+ for (const [key, sourceNode] of nodeInternals) {
1480
+ if (id === key)
1481
+ continue;
1482
+ const { positionAbsolute: sPositionAbsolute, width: sWidth, height: sHeight, } = sourceNode;
1483
+ if (!sWidth || !sHeight)
1484
+ continue;
1485
+ if (!sPositionAbsolute || !positionAbsolute)
1486
+ continue;
1487
+ // if (sourceNode.parentNode === targetNode.id) continue;
1488
+ // if (targetNode.parentNode === sourceNode.id) continue;
1489
+ const leftIn = sPositionAbsolute.x + sWidth >= positionAbsolute.x, rightIn = positionAbsolute.x + width >= sPositionAbsolute.x, topIn = sPositionAbsolute.y + sHeight >= positionAbsolute.y, bottomIn = positionAbsolute.y + height >= sPositionAbsolute.y;
1490
+ const isIn = leftIn && rightIn && topIn && bottomIn;
1491
+ if (isIn) {
1492
+ intersected = true;
1493
+ break;
1494
+ }
1495
+ }
1496
+ return intersected;
1497
+ };
2538
1498
 
2539
1499
  const infiniteExtent = [
2540
1500
  [Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
@@ -2563,8 +1523,8 @@ const initialState = {
2563
1523
  minZoom: 0.5,
2564
1524
  maxZoom: 2,
2565
1525
  connectionPosition: { x: 0, y: 0 },
2566
- connectionNodeId: null,
2567
- connectionPortType: 'source',
1526
+ connectionStartPort: null,
1527
+ connectionEndPort: null,
2568
1528
  autoPanOnNodeDrag: true,
2569
1529
  autoPanOnConnect: true,
2570
1530
  nodeExtent: infiniteExtent,
@@ -2573,7 +1533,7 @@ const initialState = {
2573
1533
  onError: devWarn,
2574
1534
  };
2575
1535
 
2576
- const createRFStore = () => createStore((set, get) => ({
1536
+ const createRCDStore = () => createStore((set, get) => ({
2577
1537
  ...initialState,
2578
1538
  setNodes: (nodes) => {
2579
1539
  const { nodeInternals, nodeOrigin, elevateNodesOnSelect } = get();
@@ -2587,7 +1547,7 @@ const createRFStore = () => createStore((set, get) => ({
2587
1547
  set({ edges: edges.map((e) => ({ ...defaultEdgeOptions, ...e })) });
2588
1548
  },
2589
1549
  updateNodeDimensions: (updates) => {
2590
- const { onNodesChange, nodeInternals, domNode, nodeOrigin } = get();
1550
+ const { onNodesChange, updateNodesIntersection, nodeInternals, domNode, nodeOrigin, } = get();
2591
1551
  const viewportNode = domNode?.querySelector('.react-diagram__viewport');
2592
1552
  if (!viewportNode) {
2593
1553
  return;
@@ -2606,9 +1566,10 @@ const createRFStore = () => createStore((set, get) => ({
2606
1566
  if (doUpdate) {
2607
1567
  nodeInternals.set(node.id, {
2608
1568
  ...node,
2609
- [internalsSymbol]: {
2610
- ...node[internalsSymbol],
1569
+ [internalsSymbol$1]: {
1570
+ ...node[internalsSymbol$1],
2611
1571
  portBounds: {
1572
+ id: node[internalsSymbol$1]?.portBounds?.id || null,
2612
1573
  source: getPortBounds('.source', update.nodeElement, zoom, nodeOrigin),
2613
1574
  target: getPortBounds('.target', update.nodeElement, zoom, nodeOrigin),
2614
1575
  },
@@ -2624,6 +1585,7 @@ const createRFStore = () => createStore((set, get) => ({
2624
1585
  }
2625
1586
  return res;
2626
1587
  }, []);
1588
+ updateNodesIntersection();
2627
1589
  updateAbsoluteNodePositions(nodeInternals, nodeOrigin);
2628
1590
  set({
2629
1591
  nodeInternals: new Map(nodeInternals),
@@ -2658,6 +1620,33 @@ const createRFStore = () => createStore((set, get) => ({
2658
1620
  onNodesChange?.(changes);
2659
1621
  }
2660
1622
  },
1623
+ updateNodesIntersection: () => {
1624
+ const { nodeInternals, triggerNodeChanges } = get();
1625
+ const nodes = Array.from(nodeInternals.values());
1626
+ const unIntersectNodes = () => {
1627
+ return nodes
1628
+ .filter((node) => node.intersected && !isIntersected(node, nodeInternals))
1629
+ .map((node) => ({
1630
+ id: node.id,
1631
+ type: 'intersect',
1632
+ intersected: false,
1633
+ }));
1634
+ };
1635
+ const addIntersectNodes = () => {
1636
+ return nodes
1637
+ .filter((node) => isIntersected(node, nodeInternals))
1638
+ .map((node) => {
1639
+ return {
1640
+ id: node.id,
1641
+ type: 'intersect',
1642
+ intersected: true,
1643
+ };
1644
+ });
1645
+ };
1646
+ const intersectedNodes = addIntersectNodes();
1647
+ const unIntersectedNodes = unIntersectNodes();
1648
+ triggerNodeChanges([...intersectedNodes, ...unIntersectedNodes]);
1649
+ },
2661
1650
  addSelectedNodes: (selectedNodeIds) => {
2662
1651
  const { multiSelectionActive, getNodes, triggerNodeChanges } = get();
2663
1652
  let changedNodes;
@@ -2687,9 +1676,17 @@ const createRFStore = () => createStore((set, get) => ({
2687
1676
  triggerNodeChanges(nodesToUnselect);
2688
1677
  },
2689
1678
  cancelConnection: () => set({
2690
- connectionNodeId: initialState.connectionNodeId,
2691
- connectionPortType: initialState.connectionPortType,
1679
+ connectionStartPort: null,
1680
+ connectionEndPort: null,
2692
1681
  }),
1682
+ updateConnection: (params) => {
1683
+ const { connectionPosition } = get();
1684
+ const currentConnection = {
1685
+ ...params,
1686
+ connectionPosition: params.connectionPosition ?? connectionPosition,
1687
+ };
1688
+ set(currentConnection);
1689
+ },
2693
1690
  panBy: (delta) => {
2694
1691
  const { transform, width, height, d3Zoom, d3Selection } = get();
2695
1692
  if (!d3Zoom || !d3Selection || (!delta.x && !delta.y)) {
@@ -2734,7 +1731,7 @@ const createRFStore = () => createStore((set, get) => ({
2734
1731
  const ReactDiagramProvider = ({ children }) => {
2735
1732
  const storeRef = useRef(null);
2736
1733
  if (!storeRef.current) {
2737
- storeRef.current = createRFStore();
1734
+ storeRef.current = createRCDStore();
2738
1735
  }
2739
1736
  return jsx(Provider$1, { value: storeRef.current, children: children });
2740
1737
  };
@@ -2759,13 +1756,13 @@ const defaultEdgeTypes = {
2759
1756
  };
2760
1757
  const ReactDiagram = forwardRef(({ children, id,
2761
1758
  // DiagramView props
2762
- panning = true, minZoom, maxZoom, translateExtent, nodeExtent, defaultViewport = initViewport, multiSelectionKeyCode, dragSelectionKeyCode, onlyRenderVisibleElements = false, disableKeyboardA11y = false, noDragClassName = 'nodrag', noPanClassName = 'nopan', nodeOrigin = initNodeOrigin, nodeTypes = defaultNodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave, edgeTypes = defaultEdgeTypes, edgeUpdaterRadius, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd, onMove, onMoveStart, onMoveEnd, ConnectionLineContainerStyle, ConnectionLineComponent,
1759
+ panning = true, minZoom, maxZoom, translateExtent, nodeExtent = infiniteExtent, defaultViewport = initViewport, multiSelectionKeyCode = 'Meta', dragSelectionKeyCode = 'Shift', onlyRenderVisibleElements = false, disableKeyboardA11y = false, noDragClassName = 'nodrag', noPanClassName = 'nopan', nodeOrigin = initNodeOrigin, nodeTypes = defaultNodeTypes, onNodeClick, onNodeDoubleClick, onNodeContextMenu, onNodeMouseEnter, onNodeMouseMove, onNodeMouseLeave, edgeTypes = defaultEdgeTypes, edgeUpdaterRadius, onEdgeClick, onEdgeDoubleClick, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeUpdate, onEdgeUpdateStart, onEdgeUpdateEnd, onMove, onMoveStart, onMoveEnd, ConnectionLineContainerStyle, ConnectionLineComponent,
2763
1760
  // StoreUpdater props
2764
- nodes, edges, nodesDraggable, elevateNodesOnSelect, autoPanOnNodeDrag, autoPanOnConnect, connectionRadius, smoothStep, centerStep, gridStep, onNodesChange, onNodeDrag, onNodeDragStart, onNodeDragEnd, onEdgesChange, onConnect, onConnectStart, onConnectEnd, onError, }, ref) => {
1761
+ nodes, edges, nodesDraggable, elevateNodesOnSelect, autoPanOnNodeDrag, autoPanOnConnect, connectionRadius, smoothStep, centerStep, gridStep, onNodesChange, onNodeDrag, onNodeDragStart, onNodeDragEnd, onEdgesChange, onConnect, onConnectStart, onConnectEnd, onError, ...rest }, ref) => {
2765
1762
  const rfId = id || '1';
2766
1763
  const nodeTypesWrapped = useNodeOrEdgeTypes(nodeTypes, createNodeTypes);
2767
1764
  const edgeTypesWrapped = useNodeOrEdgeTypes(edgeTypes, createEdgeTypes);
2768
- return (jsx("div", { ref: ref, className: "react-diagram", children: jsxs(Wrapper, { children: [jsx(DiagramView$1, { rfId: rfId, panning: panning, defaultViewport: defaultViewport, multiSelectionKeyCode: multiSelectionKeyCode, dragSelectionKeyCode: dragSelectionKeyCode, onlyRenderVisibleElements: onlyRenderVisibleElements, disableKeyboardA11y: disableKeyboardA11y, noDragClassName: noDragClassName, noPanClassName: noPanClassName, nodeOrigin: nodeOrigin, nodeTypes: nodeTypesWrapped, edgeTypes: edgeTypesWrapped, edgeUpdaterRadius: edgeUpdaterRadius, ConnectionLineContainerStyle: ConnectionLineContainerStyle, ConnectionLineComponent: ConnectionLineComponent, onNodeClick: onNodeClick, onNodeDoubleClick: onNodeDoubleClick, onNodeContextMenu: onNodeContextMenu, onNodeMouseEnter: onNodeMouseEnter, onNodeMouseMove: onNodeMouseMove, onNodeMouseLeave: onNodeMouseLeave, onEdgeClick: onEdgeClick, onEdgeDoubleClick: onEdgeDoubleClick, onEdgeContextMenu: onEdgeContextMenu, onEdgeMouseEnter: onEdgeMouseEnter, onEdgeMouseMove: onEdgeMouseMove, onEdgeMouseLeave: onEdgeMouseLeave, onEdgeUpdate: onEdgeUpdate, onEdgeUpdateStart: onEdgeUpdateStart, onEdgeUpdateEnd: onEdgeUpdateEnd, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd }), jsx(StoreUpdater, { rfId: rfId, nodes: nodes, edges: edges, nodesDraggable: nodesDraggable, elevateNodesOnSelect: elevateNodesOnSelect, autoPanOnNodeDrag: autoPanOnNodeDrag, autoPanOnConnect: autoPanOnConnect, connectionRadius: connectionRadius, nodeExtent: nodeExtent, translateExtent: translateExtent, minZoom: minZoom, maxZoom: maxZoom, smoothStep: smoothStep, centerStep: centerStep, gridStep: gridStep, onNodesChange: onNodesChange, onNodeDrag: onNodeDrag, onNodeDragStart: onNodeDragStart, onNodeDragEnd: onNodeDragEnd, onEdgesChange: onEdgesChange, onConnect: onConnect, onConnectStart: onConnectStart, onConnectEnd: onConnectEnd, onError: onError }), children] }) }));
1765
+ return (jsx("div", { ...rest, ref: ref, className: "react-diagram", children: jsxs(Wrapper, { children: [jsx(DiagramView$1, { rfId: rfId, panning: panning, defaultViewport: defaultViewport, multiSelectionKeyCode: multiSelectionKeyCode, dragSelectionKeyCode: dragSelectionKeyCode, onlyRenderVisibleElements: onlyRenderVisibleElements, disableKeyboardA11y: disableKeyboardA11y, noDragClassName: noDragClassName, noPanClassName: noPanClassName, nodeOrigin: nodeOrigin, nodeExtent: nodeExtent, nodeTypes: nodeTypesWrapped, edgeTypes: edgeTypesWrapped, edgeUpdaterRadius: edgeUpdaterRadius, ConnectionLineContainerStyle: ConnectionLineContainerStyle, ConnectionLineComponent: ConnectionLineComponent, onNodeClick: onNodeClick, onNodeDoubleClick: onNodeDoubleClick, onNodeContextMenu: onNodeContextMenu, onNodeMouseEnter: onNodeMouseEnter, onNodeMouseMove: onNodeMouseMove, onNodeMouseLeave: onNodeMouseLeave, onEdgeClick: onEdgeClick, onEdgeDoubleClick: onEdgeDoubleClick, onEdgeContextMenu: onEdgeContextMenu, onEdgeMouseEnter: onEdgeMouseEnter, onEdgeMouseMove: onEdgeMouseMove, onEdgeMouseLeave: onEdgeMouseLeave, onEdgeUpdate: onEdgeUpdate, onEdgeUpdateStart: onEdgeUpdateStart, onEdgeUpdateEnd: onEdgeUpdateEnd, onMove: onMove, onMoveStart: onMoveStart, onMoveEnd: onMoveEnd }), jsx(StoreUpdater, { rfId: rfId, nodes: nodes, edges: edges, nodesDraggable: nodesDraggable, elevateNodesOnSelect: elevateNodesOnSelect, autoPanOnNodeDrag: autoPanOnNodeDrag, autoPanOnConnect: autoPanOnConnect, connectionRadius: connectionRadius, nodeOrigin: nodeOrigin, nodeExtent: nodeExtent, translateExtent: translateExtent, minZoom: minZoom, maxZoom: maxZoom, smoothStep: smoothStep, centerStep: centerStep, gridStep: gridStep, onNodesChange: onNodesChange, onNodeDrag: onNodeDrag, onNodeDragStart: onNodeDragStart, onNodeDragEnd: onNodeDragEnd, onEdgesChange: onEdgesChange, onConnect: onConnect, onConnectStart: onConnectStart, onConnectEnd: onConnectEnd, onError: onError }), children] }) }));
2769
1766
  });
2770
1767
  ReactDiagram.displayName = 'ReactDiagram';
2771
1768
 
@@ -2810,4 +1807,4 @@ function Background({ gap, lineWidth = 1, color = '#000000', }) {
2810
1807
  Background.displayName = 'Background';
2811
1808
  var index = memo(Background);
2812
1809
 
2813
- export { index as Background, BaseEdge, BezierEdge, MarkerType, Port$1 as Port, Position, ReactDiagramProvider, StepEdge, addEdge, boxToRect, clamp, ReactDiagram as default, getBezierPath, getStepPath, internalsSymbol, isEdge, isNode, rectToBox, updateEdge, useEdgesState, useNodesState };
1810
+ export { index as Background, BaseEdge, BezierEdge, Port$1 as Port, ReactDiagramProvider, StepEdge, ReactDiagram as default, internalsSymbol, useEdgesState, useNodesState };