@babylonjs/shared-ui-components 5.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/colorPicker/colorComponentEntry.d.ts +18 -0
  2. package/colorPicker/colorComponentEntry.js +37 -0
  3. package/colorPicker/colorComponentEntry.js.map +1 -0
  4. package/colorPicker/colorPicker.d.ts +43 -0
  5. package/colorPicker/colorPicker.js +137 -0
  6. package/colorPicker/colorPicker.js.map +1 -0
  7. package/colorPicker/hexColor.d.ts +20 -0
  8. package/colorPicker/hexColor.js +43 -0
  9. package/colorPicker/hexColor.js.map +1 -0
  10. package/components/Button.d.ts +10 -0
  11. package/components/Button.js +7 -0
  12. package/components/Button.js.map +1 -0
  13. package/components/Icon.d.ts +6 -0
  14. package/components/Icon.js +7 -0
  15. package/components/Icon.js.map +1 -0
  16. package/components/Label.d.ts +7 -0
  17. package/components/Label.js +7 -0
  18. package/components/Label.js.map +1 -0
  19. package/components/MessageDialog.d.ts +7 -0
  20. package/components/MessageDialog.js +23 -0
  21. package/components/MessageDialog.js.map +1 -0
  22. package/components/Toggle.d.ts +8 -0
  23. package/components/Toggle.js +16 -0
  24. package/components/Toggle.js.map +1 -0
  25. package/components/bars/CommandBarComponent.d.ts +16 -0
  26. package/components/bars/CommandBarComponent.js +69 -0
  27. package/components/bars/CommandBarComponent.js.map +1 -0
  28. package/components/bars/CommandButtonComponent.d.ts +11 -0
  29. package/components/bars/CommandButtonComponent.js +7 -0
  30. package/components/bars/CommandButtonComponent.js.map +1 -0
  31. package/components/bars/CommandDropdownComponent.d.ts +26 -0
  32. package/components/bars/CommandDropdownComponent.js +49 -0
  33. package/components/bars/CommandDropdownComponent.js.map +1 -0
  34. package/components/classNames.d.ts +2 -0
  35. package/components/classNames.js +19 -0
  36. package/components/classNames.js.map +1 -0
  37. package/components/colorPicker/ColorComponentEntry.d.ts +18 -0
  38. package/components/colorPicker/ColorComponentEntry.js +38 -0
  39. package/components/colorPicker/ColorComponentEntry.js.map +1 -0
  40. package/components/colorPicker/ColorPicker.d.ts +43 -0
  41. package/components/colorPicker/ColorPicker.js +138 -0
  42. package/components/colorPicker/ColorPicker.js.map +1 -0
  43. package/components/colorPicker/HexColor.d.ts +20 -0
  44. package/components/colorPicker/HexColor.js +46 -0
  45. package/components/colorPicker/HexColor.js.map +1 -0
  46. package/components/lines/ColorLineComponent.d.ts +40 -0
  47. package/components/lines/ColorLineComponent.js +146 -0
  48. package/components/lines/ColorLineComponent.js.map +1 -0
  49. package/components/lines/ColorPickerLineComponent.d.ts +33 -0
  50. package/components/lines/ColorPickerLineComponent.js +62 -0
  51. package/components/lines/ColorPickerLineComponent.js.map +1 -0
  52. package/components/lines/FileButtonLineComponent.d.ts +16 -0
  53. package/components/lines/FileButtonLineComponent.js +22 -0
  54. package/components/lines/FileButtonLineComponent.js.map +1 -0
  55. package/components/lines/NumericInputComponent.d.ts +31 -0
  56. package/components/lines/NumericInputComponent.js +87 -0
  57. package/components/lines/NumericInputComponent.js.map +1 -0
  58. package/license.md +71 -0
  59. package/lines/booleanLineComponent.d.ts +11 -0
  60. package/lines/booleanLineComponent.js +15 -0
  61. package/lines/booleanLineComponent.js.map +1 -0
  62. package/lines/buttonLineComponent.d.ts +12 -0
  63. package/lines/buttonLineComponent.js +11 -0
  64. package/lines/buttonLineComponent.js.map +1 -0
  65. package/lines/checkBoxLineComponent.d.ts +36 -0
  66. package/lines/checkBoxLineComponent.js +89 -0
  67. package/lines/checkBoxLineComponent.js.map +1 -0
  68. package/lines/color3LineComponent.d.ts +18 -0
  69. package/lines/color3LineComponent.js +10 -0
  70. package/lines/color3LineComponent.js.map +1 -0
  71. package/lines/color4LineComponent.d.ts +18 -0
  72. package/lines/color4LineComponent.js +10 -0
  73. package/lines/color4LineComponent.js.map +1 -0
  74. package/lines/colorLineComponent.d.ts +40 -0
  75. package/lines/colorLineComponent.js +145 -0
  76. package/lines/colorLineComponent.js.map +1 -0
  77. package/lines/colorPickerComponent.d.ts +31 -0
  78. package/lines/colorPickerComponent.js +61 -0
  79. package/lines/colorPickerComponent.js.map +1 -0
  80. package/lines/draggableLineComponent.d.ts +9 -0
  81. package/lines/draggableLineComponent.js +13 -0
  82. package/lines/draggableLineComponent.js.map +1 -0
  83. package/lines/fileButtonLineComponent.d.ts +17 -0
  84. package/lines/fileButtonLineComponent.js +21 -0
  85. package/lines/fileButtonLineComponent.js.map +1 -0
  86. package/lines/fileMultipleButtonLineComponent.d.ts +17 -0
  87. package/lines/fileMultipleButtonLineComponent.js +21 -0
  88. package/lines/fileMultipleButtonLineComponent.js.map +1 -0
  89. package/lines/floatLineComponent.d.ts +50 -0
  90. package/lines/floatLineComponent.js +176 -0
  91. package/lines/floatLineComponent.js.map +1 -0
  92. package/lines/hexLineComponent.d.ts +40 -0
  93. package/lines/hexLineComponent.js +122 -0
  94. package/lines/hexLineComponent.js.map +1 -0
  95. package/lines/iSelectedLineContainer.d.ts +4 -0
  96. package/lines/iSelectedLineContainer.js +2 -0
  97. package/lines/iSelectedLineContainer.js.map +1 -0
  98. package/lines/iconButtonLineComponent.d.ts +11 -0
  99. package/lines/iconButtonLineComponent.js +11 -0
  100. package/lines/iconButtonLineComponent.js.map +1 -0
  101. package/lines/iconComponent.d.ts +9 -0
  102. package/lines/iconComponent.js +8 -0
  103. package/lines/iconComponent.js.map +1 -0
  104. package/lines/indentedTextLineComponent.d.ts +16 -0
  105. package/lines/indentedTextLineComponent.js +27 -0
  106. package/lines/indentedTextLineComponent.js.map +1 -0
  107. package/lines/inputArrowsComponent.d.ts +13 -0
  108. package/lines/inputArrowsComponent.js +38 -0
  109. package/lines/inputArrowsComponent.js.map +1 -0
  110. package/lines/lineContainerComponent.d.ts +19 -0
  111. package/lines/lineContainerComponent.js +50 -0
  112. package/lines/lineContainerComponent.js.map +1 -0
  113. package/lines/linkButtonComponent.d.ts +16 -0
  114. package/lines/linkButtonComponent.js +21 -0
  115. package/lines/linkButtonComponent.js.map +1 -0
  116. package/lines/matrixLineComponent.d.ts +36 -0
  117. package/lines/matrixLineComponent.js +103 -0
  118. package/lines/matrixLineComponent.js.map +1 -0
  119. package/lines/messageLineComponent.d.ts +12 -0
  120. package/lines/messageLineComponent.js +15 -0
  121. package/lines/messageLineComponent.js.map +1 -0
  122. package/lines/numericInputComponent.d.ts +31 -0
  123. package/lines/numericInputComponent.js +86 -0
  124. package/lines/numericInputComponent.js.map +1 -0
  125. package/lines/optionsLineComponent.d.ts +48 -0
  126. package/lines/optionsLineComponent.js +119 -0
  127. package/lines/optionsLineComponent.js.map +1 -0
  128. package/lines/popup.d.ts +4 -0
  129. package/lines/popup.js +68 -0
  130. package/lines/popup.js.map +1 -0
  131. package/lines/radioLineComponent.d.ts +21 -0
  132. package/lines/radioLineComponent.js +27 -0
  133. package/lines/radioLineComponent.js.map +1 -0
  134. package/lines/sliderLineComponent.d.ts +37 -0
  135. package/lines/sliderLineComponent.js +90 -0
  136. package/lines/sliderLineComponent.js.map +1 -0
  137. package/lines/targetsProxy.d.ts +11 -0
  138. package/lines/targetsProxy.js +43 -0
  139. package/lines/targetsProxy.js.map +1 -0
  140. package/lines/textInputLineComponent.d.ts +47 -0
  141. package/lines/textInputLineComponent.js +155 -0
  142. package/lines/textInputLineComponent.js.map +1 -0
  143. package/lines/textLineComponent.d.ts +21 -0
  144. package/lines/textLineComponent.js +31 -0
  145. package/lines/textLineComponent.js.map +1 -0
  146. package/lines/unitButton.d.ts +8 -0
  147. package/lines/unitButton.js +8 -0
  148. package/lines/unitButton.js.map +1 -0
  149. package/lines/valueLineComponent.d.ts +15 -0
  150. package/lines/valueLineComponent.js +13 -0
  151. package/lines/valueLineComponent.js.map +1 -0
  152. package/lines/vector2LineComponent.d.ts +36 -0
  153. package/lines/vector2LineComponent.js +64 -0
  154. package/lines/vector2LineComponent.js.map +1 -0
  155. package/lines/vector3LineComponent.d.ts +41 -0
  156. package/lines/vector3LineComponent.js +75 -0
  157. package/lines/vector3LineComponent.js.map +1 -0
  158. package/lines/vector4LineComponent.d.ts +42 -0
  159. package/lines/vector4LineComponent.js +82 -0
  160. package/lines/vector4LineComponent.js.map +1 -0
  161. package/nodeGraphSystem/displayLedger.d.ts +5 -0
  162. package/nodeGraphSystem/displayLedger.js +4 -0
  163. package/nodeGraphSystem/displayLedger.js.map +1 -0
  164. package/nodeGraphSystem/frameNodePort.d.ts +25 -0
  165. package/nodeGraphSystem/frameNodePort.js +60 -0
  166. package/nodeGraphSystem/frameNodePort.js.map +1 -0
  167. package/nodeGraphSystem/graphCanvas.d.ts +111 -0
  168. package/nodeGraphSystem/graphCanvas.js +1132 -0
  169. package/nodeGraphSystem/graphCanvas.js.map +1 -0
  170. package/nodeGraphSystem/graphFrame.d.ts +153 -0
  171. package/nodeGraphSystem/graphFrame.js +1329 -0
  172. package/nodeGraphSystem/graphFrame.js.map +1 -0
  173. package/nodeGraphSystem/graphNode.d.ts +79 -0
  174. package/nodeGraphSystem/graphNode.js +460 -0
  175. package/nodeGraphSystem/graphNode.js.map +1 -0
  176. package/nodeGraphSystem/interfaces/displayManager.d.ts +13 -0
  177. package/nodeGraphSystem/interfaces/displayManager.js +2 -0
  178. package/nodeGraphSystem/interfaces/displayManager.js.map +1 -0
  179. package/nodeGraphSystem/interfaces/nodeContainer.d.ts +6 -0
  180. package/nodeGraphSystem/interfaces/nodeContainer.js +2 -0
  181. package/nodeGraphSystem/interfaces/nodeContainer.js.map +1 -0
  182. package/nodeGraphSystem/interfaces/nodeData.d.ts +15 -0
  183. package/nodeGraphSystem/interfaces/nodeData.js +2 -0
  184. package/nodeGraphSystem/interfaces/nodeData.js.map +1 -0
  185. package/nodeGraphSystem/interfaces/nodeLocationInfo.d.ts +26 -0
  186. package/nodeGraphSystem/interfaces/nodeLocationInfo.js +2 -0
  187. package/nodeGraphSystem/interfaces/nodeLocationInfo.js.map +1 -0
  188. package/nodeGraphSystem/interfaces/portData.d.ts +28 -0
  189. package/nodeGraphSystem/interfaces/portData.js +8 -0
  190. package/nodeGraphSystem/interfaces/portData.js.map +1 -0
  191. package/nodeGraphSystem/interfaces/propertyComponentProps.d.ts +6 -0
  192. package/nodeGraphSystem/interfaces/propertyComponentProps.js +2 -0
  193. package/nodeGraphSystem/interfaces/propertyComponentProps.js.map +1 -0
  194. package/nodeGraphSystem/interfaces/selectionChangedOptions.d.ts +11 -0
  195. package/nodeGraphSystem/interfaces/selectionChangedOptions.js +2 -0
  196. package/nodeGraphSystem/interfaces/selectionChangedOptions.js.map +1 -0
  197. package/nodeGraphSystem/nodeLink.d.ts +31 -0
  198. package/nodeGraphSystem/nodeLink.js +183 -0
  199. package/nodeGraphSystem/nodeLink.js.map +1 -0
  200. package/nodeGraphSystem/nodePort.d.ts +35 -0
  201. package/nodeGraphSystem/nodePort.js +129 -0
  202. package/nodeGraphSystem/nodePort.js.map +1 -0
  203. package/nodeGraphSystem/propertyLedger.d.ts +8 -0
  204. package/nodeGraphSystem/propertyLedger.js +4 -0
  205. package/nodeGraphSystem/propertyLedger.js.map +1 -0
  206. package/nodeGraphSystem/stateManager.d.ts +45 -0
  207. package/nodeGraphSystem/stateManager.js +19 -0
  208. package/nodeGraphSystem/stateManager.js.map +1 -0
  209. package/nodeGraphSystem/tools.d.ts +5 -0
  210. package/nodeGraphSystem/tools.js +37 -0
  211. package/nodeGraphSystem/tools.js.map +1 -0
  212. package/nodeGraphSystem/typeLedger.d.ts +8 -0
  213. package/nodeGraphSystem/typeLedger.js +3 -0
  214. package/nodeGraphSystem/typeLedger.js.map +1 -0
  215. package/nodeGraphSystem/types/framePortData.d.ts +7 -0
  216. package/nodeGraphSystem/types/framePortData.js +2 -0
  217. package/nodeGraphSystem/types/framePortData.js.map +1 -0
  218. package/package.json +55 -0
  219. package/propertyChangedEvent.d.ts +7 -0
  220. package/propertyChangedEvent.js +3 -0
  221. package/propertyChangedEvent.js.map +1 -0
  222. package/readme.md +6 -0
  223. package/stories/Button.stories.d.ts +10 -0
  224. package/stories/Button.stories.js +20 -0
  225. package/stories/Button.stories.js.map +1 -0
  226. package/stories/Icon.stories.d.ts +9 -0
  227. package/stories/Icon.stories.js +17 -0
  228. package/stories/Icon.stories.js.map +1 -0
  229. package/stories/Label.stories.d.ts +8 -0
  230. package/stories/Label.stories.js +11 -0
  231. package/stories/Label.stories.js.map +1 -0
  232. package/stories/MessageDialog.stories.d.ts +9 -0
  233. package/stories/MessageDialog.stories.js +20 -0
  234. package/stories/MessageDialog.stories.js.map +1 -0
  235. package/stories/Toggle.stories.d.ts +9 -0
  236. package/stories/Toggle.stories.js +18 -0
  237. package/stories/Toggle.stories.js.map +1 -0
  238. package/stories/bars/CommandBarComponent.stories.d.ts +11 -0
  239. package/stories/bars/CommandBarComponent.stories.js +13 -0
  240. package/stories/bars/CommandBarComponent.stories.js.map +1 -0
  241. package/stories/bars/CommandButtonComponent.stories.d.ts +6 -0
  242. package/stories/bars/CommandButtonComponent.stories.js +7 -0
  243. package/stories/bars/CommandButtonComponent.stories.js.map +1 -0
  244. package/stories/colorPicker/ColorPicker.stories.d.ts +11 -0
  245. package/stories/colorPicker/ColorPicker.stories.js +5 -0
  246. package/stories/colorPicker/ColorPicker.stories.js.map +1 -0
  247. package/stories/lines/ColorLineComponent.stories.d.ts +21 -0
  248. package/stories/lines/ColorLineComponent.stories.js +10 -0
  249. package/stories/lines/ColorLineComponent.stories.js.map +1 -0
  250. package/stories/lines/ColorPickerLineComponent.stories.d.ts +14 -0
  251. package/stories/lines/ColorPickerLineComponent.stories.js +11 -0
  252. package/stories/lines/ColorPickerLineComponent.stories.js.map +1 -0
  253. package/stories/lines/FileButtonLineComponent.stories.d.ts +6 -0
  254. package/stories/lines/FileButtonLineComponent.stories.js +6 -0
  255. package/stories/lines/FileButtonLineComponent.stories.js.map +1 -0
  256. package/stories/lines/NumericInputComponent.stories.d.ts +11 -0
  257. package/stories/lines/NumericInputComponent.stories.js +6 -0
  258. package/stories/lines/NumericInputComponent.stories.js.map +1 -0
  259. package/stringTools.d.ts +11 -0
  260. package/stringTools.js +89 -0
  261. package/stringTools.js.map +1 -0
  262. package/tabs/propertyGrids/gui/checkboxPropertyGridComponent.d.ts +15 -0
  263. package/tabs/propertyGrids/gui/checkboxPropertyGridComponent.js +16 -0
  264. package/tabs/propertyGrids/gui/checkboxPropertyGridComponent.js.map +1 -0
  265. package/tabs/propertyGrids/gui/colorPickerPropertyGridComponent.d.ts +15 -0
  266. package/tabs/propertyGrids/gui/colorPickerPropertyGridComponent.js +15 -0
  267. package/tabs/propertyGrids/gui/colorPickerPropertyGridComponent.js.map +1 -0
  268. package/tabs/propertyGrids/gui/commonControlPropertyGridComponent.d.ts +17 -0
  269. package/tabs/propertyGrids/gui/commonControlPropertyGridComponent.js +56 -0
  270. package/tabs/propertyGrids/gui/commonControlPropertyGridComponent.js.map +1 -0
  271. package/tabs/propertyGrids/gui/controlPropertyGridComponent.d.ts +15 -0
  272. package/tabs/propertyGrids/gui/controlPropertyGridComponent.js +13 -0
  273. package/tabs/propertyGrids/gui/controlPropertyGridComponent.js.map +1 -0
  274. package/tabs/propertyGrids/gui/ellipsePropertyGridComponent.d.ts +15 -0
  275. package/tabs/propertyGrids/gui/ellipsePropertyGridComponent.js +16 -0
  276. package/tabs/propertyGrids/gui/ellipsePropertyGridComponent.js.map +1 -0
  277. package/tabs/propertyGrids/gui/gridPropertyGridComponent.d.ts +17 -0
  278. package/tabs/propertyGrids/gui/gridPropertyGridComponent.js +39 -0
  279. package/tabs/propertyGrids/gui/gridPropertyGridComponent.js.map +1 -0
  280. package/tabs/propertyGrids/gui/imageBasedSliderPropertyGridComponent.d.ts +15 -0
  281. package/tabs/propertyGrids/gui/imageBasedSliderPropertyGridComponent.js +17 -0
  282. package/tabs/propertyGrids/gui/imageBasedSliderPropertyGridComponent.js.map +1 -0
  283. package/tabs/propertyGrids/gui/imagePropertyGridComponent.d.ts +15 -0
  284. package/tabs/propertyGrids/gui/imagePropertyGridComponent.js +26 -0
  285. package/tabs/propertyGrids/gui/imagePropertyGridComponent.js.map +1 -0
  286. package/tabs/propertyGrids/gui/inputTextPropertyGridComponent.d.ts +15 -0
  287. package/tabs/propertyGrids/gui/inputTextPropertyGridComponent.js +18 -0
  288. package/tabs/propertyGrids/gui/inputTextPropertyGridComponent.js.map +1 -0
  289. package/tabs/propertyGrids/gui/linePropertyGridComponent.d.ts +16 -0
  290. package/tabs/propertyGrids/gui/linePropertyGridComponent.js +28 -0
  291. package/tabs/propertyGrids/gui/linePropertyGridComponent.js.map +1 -0
  292. package/tabs/propertyGrids/gui/radioButtonPropertyGridComponent.d.ts +15 -0
  293. package/tabs/propertyGrids/gui/radioButtonPropertyGridComponent.js +18 -0
  294. package/tabs/propertyGrids/gui/radioButtonPropertyGridComponent.js.map +1 -0
  295. package/tabs/propertyGrids/gui/rectanglePropertyGridComponent.d.ts +15 -0
  296. package/tabs/propertyGrids/gui/rectanglePropertyGridComponent.js +16 -0
  297. package/tabs/propertyGrids/gui/rectanglePropertyGridComponent.js.map +1 -0
  298. package/tabs/propertyGrids/gui/scrollViewerPropertyGridComponent.d.ts +15 -0
  299. package/tabs/propertyGrids/gui/scrollViewerPropertyGridComponent.js +16 -0
  300. package/tabs/propertyGrids/gui/scrollViewerPropertyGridComponent.js.map +1 -0
  301. package/tabs/propertyGrids/gui/sliderPropertyGridComponent.d.ts +15 -0
  302. package/tabs/propertyGrids/gui/sliderPropertyGridComponent.js +17 -0
  303. package/tabs/propertyGrids/gui/sliderPropertyGridComponent.js.map +1 -0
  304. package/tabs/propertyGrids/gui/stackPanelPropertyGridComponent.d.ts +15 -0
  305. package/tabs/propertyGrids/gui/stackPanelPropertyGridComponent.js +15 -0
  306. package/tabs/propertyGrids/gui/stackPanelPropertyGridComponent.js.map +1 -0
  307. package/tabs/propertyGrids/gui/textBlockPropertyGridComponent.d.ts +15 -0
  308. package/tabs/propertyGrids/gui/textBlockPropertyGridComponent.js +35 -0
  309. package/tabs/propertyGrids/gui/textBlockPropertyGridComponent.js.map +1 -0
  310. package/tabs/propertyGrids/lockObject.d.ts +9 -0
  311. package/tabs/propertyGrids/lockObject.js +12 -0
  312. package/tabs/propertyGrids/lockObject.js.map +1 -0
@@ -0,0 +1,1132 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { GraphNode } from "./graphNode.js";
4
+ import * as dagre from "dagre";
5
+ import { NodeLink } from "./nodeLink.js";
6
+ import { NodePort } from "./nodePort.js";
7
+ import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
8
+ import { DataStorage } from "@babylonjs/core/Misc/dataStorage.js";
9
+ import { GraphFrame } from "./graphFrame.js";
10
+ import { FrameNodePort } from "./frameNodePort.js";
11
+ import { PortDataDirection } from "./interfaces/portData.js";
12
+ import styles from "./graphCanvas.modules.scss";
13
+ import commonStyles from "./common.modules.scss";
14
+ import { TypeLedger } from "./typeLedger.js";
15
+ import { RefreshNode } from "./tools.js";
16
+ export class GraphCanvasComponent extends React.Component {
17
+ constructor(props) {
18
+ super(props);
19
+ this._minZoom = 0.1;
20
+ this._maxZoom = 4;
21
+ this._nodes = [];
22
+ this._links = [];
23
+ this._mouseStartPointX = null;
24
+ this._mouseStartPointY = null;
25
+ this._dropPointX = 0;
26
+ this._dropPointY = 0;
27
+ this._selectionStartX = 0;
28
+ this._selectionStartY = 0;
29
+ this._candidateLinkedHasMoved = false;
30
+ this._x = 0;
31
+ this._y = 0;
32
+ this._zoom = 1;
33
+ this._selectedNodes = [];
34
+ this._selectedLink = null;
35
+ this._selectedPort = null;
36
+ this._candidateLink = null;
37
+ this._candidatePort = null;
38
+ this._gridSize = 20;
39
+ this._selectionBox = null;
40
+ this._selectedFrames = [];
41
+ this._frameCandidate = null;
42
+ this._frames = [];
43
+ this._nodeDataContentList = new Array();
44
+ this._altKeyIsPressed = false;
45
+ this._multiKeyIsPressed = false;
46
+ this._oldY = -1;
47
+ this._frameIsMoving = false;
48
+ this._isLoading = false;
49
+ this._targetLinkCandidate = null;
50
+ this._copiedNodes = [];
51
+ this._copiedFrames = [];
52
+ props.stateManager.onSelectionChangedObservable.add((options) => {
53
+ const { selection, forceKeepSelection, marqueeSelection = false } = options || {};
54
+ if (!selection) {
55
+ this._selectedNodes = [];
56
+ this._selectedLink = null;
57
+ this._selectedFrames = [];
58
+ this._selectedPort = null;
59
+ }
60
+ else {
61
+ if (selection instanceof NodeLink) {
62
+ this._selectedNodes = [];
63
+ this._selectedFrames = [];
64
+ this._selectedLink = selection;
65
+ this._selectedPort = null;
66
+ }
67
+ else if (selection instanceof NodePort) {
68
+ this._selectedNodes = [];
69
+ this._selectedFrames = [];
70
+ this._selectedLink = null;
71
+ this._selectedPort = selection;
72
+ }
73
+ else if (selection instanceof FrameNodePort) {
74
+ this._selectedNodes = [];
75
+ this._selectedFrames = [];
76
+ this._selectedLink = null;
77
+ this._selectedPort = selection;
78
+ }
79
+ else if (selection instanceof GraphNode || selection instanceof GraphFrame) {
80
+ // If in marquee selection mode, always prioritize selecting nodes. Otherwise, always prioritize selecting the type of
81
+ // the selected element
82
+ if (marqueeSelection) {
83
+ if (selection instanceof GraphFrame && !this._selectedFrames.includes(selection)) {
84
+ this._selectedFrames.push(selection);
85
+ }
86
+ else if (selection instanceof GraphNode && !this._selectedNodes.includes(selection)) {
87
+ this._selectedNodes.push(selection);
88
+ }
89
+ if (this._selectedFrameAndNodesConflict(this.selectedFrames, this.selectedNodes)) {
90
+ const framesToRemove = new Set();
91
+ for (const selectedNode of this._selectedNodes) {
92
+ for (const selectedFrame of this._selectedFrames) {
93
+ if (selectedFrame.nodes.includes(selectedNode)) {
94
+ framesToRemove.add(selectedFrame);
95
+ }
96
+ }
97
+ }
98
+ this._selectedFrames = this._selectedFrames.filter((f) => !framesToRemove.has(f));
99
+ }
100
+ }
101
+ else {
102
+ if (selection instanceof GraphFrame) {
103
+ if (this._multiKeyIsPressed || forceKeepSelection) {
104
+ if (!this._selectedFrameAndNodesConflict([selection], this._selectedNodes) && !this._selectedFrames.includes(selection)) {
105
+ this._selectedFrames.push(selection);
106
+ }
107
+ }
108
+ else {
109
+ this._selectedFrames = [selection];
110
+ this._selectedNodes = [];
111
+ this._selectedLink = null;
112
+ this._selectedPort = null;
113
+ }
114
+ }
115
+ else if (selection instanceof GraphNode) {
116
+ if (this._multiKeyIsPressed || forceKeepSelection) {
117
+ if (!this._selectedFrameAndNodesConflict(this._selectedFrames, [selection]) && !this._selectedNodes.includes(selection)) {
118
+ this._selectedNodes.push(selection);
119
+ }
120
+ }
121
+ else {
122
+ this._selectedFrames = [];
123
+ this._selectedNodes = [selection];
124
+ this._selectedLink = null;
125
+ this._selectedPort = null;
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ });
132
+ props.stateManager.onCandidatePortSelectedObservable.add((port) => {
133
+ this._candidatePort = port;
134
+ });
135
+ props.stateManager.onGridSizeChanged.add(() => {
136
+ this.gridSize = DataStorage.ReadNumber("GridSize", 20);
137
+ });
138
+ this.props.stateManager.hostDocument.addEventListener("keyup", () => this.onKeyUp(), false);
139
+ this.props.stateManager.hostDocument.addEventListener("keydown", (evt) => {
140
+ this._altKeyIsPressed = evt.altKey;
141
+ this._multiKeyIsPressed = evt.ctrlKey || evt.metaKey;
142
+ }, false);
143
+ this.props.stateManager.hostDocument.defaultView.addEventListener("blur", () => {
144
+ this._altKeyIsPressed = false;
145
+ this._multiKeyIsPressed = false;
146
+ }, false);
147
+ // Store additional data to serialization object
148
+ this.props.stateManager.storeEditorData = (editorData, graphFrame) => {
149
+ editorData.frames = [];
150
+ if (graphFrame) {
151
+ editorData.frames.push(graphFrame.serialize(false));
152
+ }
153
+ else {
154
+ editorData.x = this.x;
155
+ editorData.y = this.y;
156
+ editorData.zoom = this.zoom;
157
+ for (const frame of this._frames) {
158
+ editorData.frames.push(frame.serialize(true));
159
+ }
160
+ }
161
+ };
162
+ }
163
+ get gridSize() {
164
+ return this._gridSize;
165
+ }
166
+ set gridSize(value) {
167
+ this._gridSize = value;
168
+ this.updateTransform();
169
+ }
170
+ get stateManager() {
171
+ return this.props.stateManager;
172
+ }
173
+ get nodes() {
174
+ return this._nodes;
175
+ }
176
+ get links() {
177
+ return this._links;
178
+ }
179
+ get frames() {
180
+ return this._frames;
181
+ }
182
+ get zoom() {
183
+ return this._zoom;
184
+ }
185
+ set zoom(value) {
186
+ if (this._zoom === value) {
187
+ return;
188
+ }
189
+ this._zoom = value;
190
+ this.updateTransform();
191
+ }
192
+ get x() {
193
+ return this._x;
194
+ }
195
+ set x(value) {
196
+ this._x = value;
197
+ this.updateTransform();
198
+ }
199
+ get y() {
200
+ return this._y;
201
+ }
202
+ set y(value) {
203
+ this._y = value;
204
+ this.updateTransform();
205
+ }
206
+ get selectedNodes() {
207
+ return this._selectedNodes;
208
+ }
209
+ get selectedLink() {
210
+ return this._selectedLink;
211
+ }
212
+ get selectedFrames() {
213
+ return this._selectedFrames;
214
+ }
215
+ get selectedPort() {
216
+ return this._selectedPort;
217
+ }
218
+ get canvasContainer() {
219
+ return this._graphCanvas;
220
+ }
221
+ get hostCanvas() {
222
+ return this._hostCanvas;
223
+ }
224
+ get svgCanvas() {
225
+ return this._svgCanvas;
226
+ }
227
+ get selectionContainer() {
228
+ return this._selectionContainer;
229
+ }
230
+ get frameContainer() {
231
+ return this._frameContainer;
232
+ }
233
+ // There is a selection conflict between nodes and frames if any selected node is inside any selected frame
234
+ _selectedFrameAndNodesConflict(frameSelection, nodeSelection) {
235
+ for (const frame of frameSelection) {
236
+ for (const node of nodeSelection) {
237
+ if (frame.nodes.includes(node)) {
238
+ return true;
239
+ }
240
+ }
241
+ }
242
+ return false;
243
+ }
244
+ populateConnectedEntriesBeforeRemoval(item, items, inputs, outputs) {
245
+ inputs.push(...item.content.inputs.filter((i) => i.isConnected && items.every((selected) => { var _a; return selected.content.data !== ((_a = i.connectedPort) === null || _a === void 0 ? void 0 : _a.ownerData); })).map((i) => i.connectedPort));
246
+ outputs.push(...item.content.outputs
247
+ .filter((i) => i.isConnected)
248
+ .map((i) => i.endpoints)
249
+ .flat()
250
+ .filter((i) => i && items.every((selected) => selected.content.data !== i.ownerData)));
251
+ }
252
+ automaticRewire(inputs, outputs, firstOnly = false) {
253
+ let oneConnectionFound = false;
254
+ if (outputs.length && inputs.length) {
255
+ inputs.forEach((input) => {
256
+ if (oneConnectionFound) {
257
+ return;
258
+ }
259
+ if (!input) {
260
+ return;
261
+ }
262
+ const output = outputs[0];
263
+ if (output && input.canConnectTo(output)) {
264
+ const nodeInput = this.findNodeFromData(input.ownerData);
265
+ const nodeOutput = this.findNodeFromData(output.ownerData);
266
+ this.connectNodes(nodeInput, input, nodeOutput, output);
267
+ outputs.shift();
268
+ if (firstOnly) {
269
+ oneConnectionFound = true;
270
+ return;
271
+ }
272
+ }
273
+ });
274
+ }
275
+ }
276
+ handleKeyDown(evt, onRemove, mouseLocationX, mouseLocationY, dataGenerator, rootElement) {
277
+ if ((evt.keyCode === 46 || evt.keyCode === 8) && !this.props.stateManager.lockObject.lock) {
278
+ // Delete
279
+ const selectedItems = this.selectedNodes;
280
+ const inputs = [];
281
+ const outputs = [];
282
+ if (selectedItems.length > 0) {
283
+ for (const selectedItem of selectedItems) {
284
+ if (evt.altKey) {
285
+ this.populateConnectedEntriesBeforeRemoval(selectedItem, selectedItems, inputs, outputs);
286
+ }
287
+ selectedItem.dispose();
288
+ onRemove(selectedItem.content);
289
+ this.removeDataFromCache(selectedItem.content.data);
290
+ }
291
+ }
292
+ if (this.selectedLink) {
293
+ this.selectedLink.dispose();
294
+ }
295
+ if (this.selectedFrames.length) {
296
+ for (const frame of this.selectedFrames) {
297
+ if (frame.isCollapsed) {
298
+ while (frame.nodes.length > 0) {
299
+ onRemove(frame.nodes[0].content);
300
+ this.removeDataFromCache(frame.nodes[0].content.data);
301
+ frame.nodes[0].dispose();
302
+ }
303
+ frame.isCollapsed = false;
304
+ }
305
+ else {
306
+ frame.nodes.forEach((node) => {
307
+ node.enclosingFrameId = -1;
308
+ });
309
+ }
310
+ frame.dispose();
311
+ }
312
+ }
313
+ // Reconnect if required
314
+ this.automaticRewire(inputs, outputs);
315
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers(null);
316
+ this.props.stateManager.onRebuildRequiredObservable.notifyObservers(false);
317
+ return;
318
+ }
319
+ if ((!evt.ctrlKey && !evt.metaKey) || this.props.stateManager.lockObject.lock) {
320
+ return;
321
+ }
322
+ if (evt.key === "c" || evt.key === "C") {
323
+ // Copy
324
+ this._copiedNodes = [];
325
+ this._copiedFrames = [];
326
+ if (this.selectedFrames.length) {
327
+ for (const frame of this.selectedFrames) {
328
+ frame.serialize(true);
329
+ this._copiedFrames.push(frame);
330
+ }
331
+ return;
332
+ }
333
+ const selectedItems = this.selectedNodes;
334
+ if (!selectedItems.length) {
335
+ return;
336
+ }
337
+ const selectedItem = selectedItems[0];
338
+ if (!selectedItem.content.data) {
339
+ return;
340
+ }
341
+ this._copiedNodes = selectedItems.slice(0);
342
+ }
343
+ else if (evt.key === "v" || evt.key === "V") {
344
+ // Paste
345
+ const zoomLevel = this.zoom;
346
+ let currentY = (mouseLocationY - rootElement.offsetTop - this.y - 20) / zoomLevel;
347
+ if (this._copiedFrames.length) {
348
+ for (const frame of this._copiedFrames) {
349
+ // New frame
350
+ const newFrame = new GraphFrame(null, this, true);
351
+ this.frames.push(newFrame);
352
+ newFrame.width = frame.width;
353
+ newFrame.height = frame.height;
354
+ newFrame.width / 2;
355
+ newFrame.name = frame.name;
356
+ newFrame.color = frame.color;
357
+ let currentX = (mouseLocationX - rootElement.offsetLeft - this.x) / zoomLevel;
358
+ newFrame.x = currentX - newFrame.width / 2;
359
+ newFrame.y = currentY;
360
+ // Paste nodes
361
+ if (frame.nodes.length) {
362
+ currentX = newFrame.x + frame.nodes[0].x - frame.x;
363
+ currentY = newFrame.y + frame.nodes[0].y - frame.y;
364
+ this._frameIsMoving = true;
365
+ const newNodes = this.pasteSelection(frame.nodes, currentX, currentY, dataGenerator);
366
+ if (newNodes) {
367
+ for (const node of newNodes) {
368
+ newFrame.syncNode(node);
369
+ }
370
+ }
371
+ this._frameIsMoving = false;
372
+ }
373
+ newFrame.adjustPorts();
374
+ if (frame.isCollapsed) {
375
+ newFrame.isCollapsed = true;
376
+ }
377
+ // Select
378
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers({ selection: newFrame, forceKeepSelection: true });
379
+ return;
380
+ }
381
+ }
382
+ if (!this._copiedNodes.length) {
383
+ return;
384
+ }
385
+ const currentX = (mouseLocationX - rootElement.offsetLeft - this.x - GraphCanvasComponent.NodeWidth) / zoomLevel;
386
+ this.pasteSelection(this._copiedNodes, currentX, currentY, dataGenerator, true);
387
+ }
388
+ }
389
+ pasteSelection(copiedNodes, currentX, currentY, dataGenerator, selectNew = false) {
390
+ let originalNode = null;
391
+ const newNodes = [];
392
+ // Copy to prevent recursive side effects while creating nodes.
393
+ copiedNodes = copiedNodes.slice();
394
+ // Cancel selection
395
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers(null);
396
+ // Create new nodes
397
+ for (const node of copiedNodes) {
398
+ const data = node.content.data;
399
+ if (!data) {
400
+ continue;
401
+ }
402
+ const newNode = dataGenerator(node.content);
403
+ let x = 0;
404
+ let y = 0;
405
+ if (originalNode) {
406
+ x = currentX + node.x - originalNode.x;
407
+ y = currentY + node.y - originalNode.y;
408
+ }
409
+ else {
410
+ originalNode = node;
411
+ x = currentX;
412
+ y = currentY;
413
+ }
414
+ newNode.x = x;
415
+ newNode.y = y;
416
+ newNode.cleanAccumulation();
417
+ newNodes.push(newNode);
418
+ if (selectNew) {
419
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers({ selection: newNode, forceKeepSelection: true });
420
+ }
421
+ }
422
+ // Relink
423
+ const done = new Array(newNodes.length);
424
+ for (let index = 0; index < newNodes.length; index++) {
425
+ this.reconnectNewNodes(index, newNodes, copiedNodes, done);
426
+ }
427
+ return newNodes;
428
+ }
429
+ reconnectNewNodes(nodeIndex, newNodes, sourceNodes, done) {
430
+ if (done[nodeIndex]) {
431
+ return;
432
+ }
433
+ const currentNode = newNodes[nodeIndex];
434
+ const sourceNode = sourceNodes[nodeIndex];
435
+ for (let inputIndex = 0; inputIndex < sourceNode.content.inputs.length; inputIndex++) {
436
+ const sourceInput = sourceNode.content.inputs[inputIndex];
437
+ const currentInput = currentNode.content.inputs[inputIndex];
438
+ if (!sourceInput.isConnected) {
439
+ continue;
440
+ }
441
+ const sourceContent = this.findNodeFromData(sourceInput.connectedPort.ownerData).content;
442
+ const activeNodes = sourceNodes.filter((s) => s.content === sourceContent);
443
+ if (activeNodes.length > 0) {
444
+ const activeNode = activeNodes[0];
445
+ const indexInList = sourceNodes.indexOf(activeNode);
446
+ // First make sure to connect the other one
447
+ this.reconnectNewNodes(indexInList, newNodes, sourceNodes, done);
448
+ // Then reconnect
449
+ const outputIndex = sourceContent.outputs.indexOf(sourceInput.connectedPort);
450
+ const newOutput = newNodes[indexInList].content.data.outputs[outputIndex];
451
+ newOutput.connectTo(currentInput.data);
452
+ }
453
+ else {
454
+ // Connect with outside nodes
455
+ sourceInput.connectedPort.connectTo(currentInput);
456
+ }
457
+ this.connectPorts(currentInput.connectedPort, currentInput);
458
+ }
459
+ currentNode.refresh();
460
+ done[nodeIndex] = true;
461
+ }
462
+ getCachedData() {
463
+ return this._nodeDataContentList;
464
+ }
465
+ removeDataFromCache(data) {
466
+ const dataIndex = this._nodeDataContentList.indexOf(data);
467
+ if (dataIndex > -1) {
468
+ this._nodeDataContentList.splice(dataIndex, 1);
469
+ }
470
+ }
471
+ createNodeFromObject(nodeData, onNodeCreated, recursion = true) {
472
+ if (this._nodeDataContentList.indexOf(nodeData.data) !== -1) {
473
+ // Links
474
+ if (nodeData.inputs.length && recursion) {
475
+ for (const input of nodeData.inputs) {
476
+ if (input.isConnected) {
477
+ this.connectPorts(input.connectedPort, input);
478
+ }
479
+ }
480
+ }
481
+ return this.nodes.filter((n) => n.content.data === nodeData.data)[0];
482
+ }
483
+ onNodeCreated(nodeData.data);
484
+ // Connections
485
+ if (nodeData.inputs.length) {
486
+ for (const input of nodeData.inputs) {
487
+ if (input.connectedPort && recursion) {
488
+ this.createNodeFromObject(TypeLedger.NodeDataBuilder(input.connectedPort.ownerData, this), onNodeCreated);
489
+ }
490
+ }
491
+ }
492
+ // Graph
493
+ const node = this.appendNode(nodeData);
494
+ // Links
495
+ if (nodeData.inputs.length && recursion) {
496
+ for (const input of nodeData.inputs) {
497
+ if (input.isConnected) {
498
+ this.connectPorts(input.connectedPort, input);
499
+ }
500
+ }
501
+ }
502
+ return node;
503
+ }
504
+ getGridPosition(position, useCeil = false) {
505
+ const gridSize = this.gridSize;
506
+ if (gridSize === 0) {
507
+ return position;
508
+ }
509
+ if (useCeil) {
510
+ return gridSize * Math.ceil(position / gridSize);
511
+ }
512
+ return gridSize * Math.floor(position / gridSize);
513
+ }
514
+ getGridPositionCeil(position) {
515
+ const gridSize = this.gridSize;
516
+ if (gridSize === 0) {
517
+ return position;
518
+ }
519
+ return gridSize * Math.ceil(position / gridSize);
520
+ }
521
+ updateTransform() {
522
+ this._rootContainer.style.transform = `translate(${this._x}px, ${this._y}px) scale(${this._zoom})`;
523
+ if (DataStorage.ReadBoolean("ShowGrid", true)) {
524
+ this._hostCanvas.style.backgroundSize = `${this._gridSize * this._zoom}px ${this._gridSize * this._zoom}px`;
525
+ this._hostCanvas.style.backgroundPosition = `${this._x}px ${this._y}px`;
526
+ }
527
+ else {
528
+ this._hostCanvas.style.backgroundSize = `0`;
529
+ }
530
+ }
531
+ onKeyUp() {
532
+ this._altKeyIsPressed = false;
533
+ this._multiKeyIsPressed = false;
534
+ this._oldY = -1;
535
+ }
536
+ findNodeFromData(data) {
537
+ return this.nodes.filter((n) => n.content.data === data)[0];
538
+ }
539
+ reset() {
540
+ this._nodeDataContentList = [];
541
+ for (const node of this._nodes) {
542
+ node.dispose();
543
+ }
544
+ const frames = this._frames.splice(0);
545
+ for (const frame of frames) {
546
+ frame.dispose();
547
+ }
548
+ this._nodes = [];
549
+ this._frames = [];
550
+ this._links = [];
551
+ this._graphCanvas.innerHTML = "";
552
+ this._svgCanvas.innerHTML = "";
553
+ }
554
+ connectPorts(pointA, pointB) {
555
+ if (!pointA || !pointB) {
556
+ return;
557
+ }
558
+ const ownerDataA = pointA.ownerData;
559
+ const ownerDataB = pointB.ownerData;
560
+ const nodeA = this.findNodeFromData(ownerDataA);
561
+ const nodeB = this.findNodeFromData(ownerDataB);
562
+ if (!nodeA || !nodeB) {
563
+ return;
564
+ }
565
+ const portA = nodeA.getPortForPortData(pointA);
566
+ const portB = nodeB.getPortForPortData(pointB);
567
+ if (!portA || !portB) {
568
+ return;
569
+ }
570
+ for (const currentLink of this._links) {
571
+ if (currentLink.portA === portA && currentLink.portB === portB) {
572
+ return;
573
+ }
574
+ if (currentLink.portA === portB && currentLink.portB === portA) {
575
+ return;
576
+ }
577
+ }
578
+ const link = new NodeLink(this, portA, nodeA, portB, nodeB);
579
+ this._links.push(link);
580
+ nodeA.links.push(link);
581
+ nodeB.links.push(link);
582
+ }
583
+ removeLink(link) {
584
+ const index = this._links.indexOf(link);
585
+ if (index > -1) {
586
+ this._links.splice(index, 1);
587
+ }
588
+ link.dispose();
589
+ }
590
+ appendNode(nodeData) {
591
+ const newNode = new GraphNode(nodeData, this.props.stateManager);
592
+ newNode.appendVisual(this._graphCanvas, this);
593
+ this._nodes.push(newNode);
594
+ this._nodeDataContentList.push(nodeData.data);
595
+ return newNode;
596
+ }
597
+ distributeGraph() {
598
+ this.x = 0;
599
+ this.y = 0;
600
+ this.zoom = 1;
601
+ const graph = new dagre.graphlib.Graph();
602
+ graph.setGraph({});
603
+ graph.setDefaultEdgeLabel(() => ({}));
604
+ graph.graph().rankdir = "LR";
605
+ // Build dagre graph
606
+ this._nodes.forEach((node) => {
607
+ if (this._frames.some((f) => f.nodes.indexOf(node) !== -1)) {
608
+ return;
609
+ }
610
+ graph.setNode(node.id.toString(), {
611
+ id: node.id,
612
+ type: "node",
613
+ width: node.width,
614
+ height: node.height,
615
+ });
616
+ });
617
+ this._frames.forEach((frame) => {
618
+ graph.setNode(frame.id.toString(), {
619
+ id: frame.id,
620
+ type: "frame",
621
+ width: frame.element.clientWidth,
622
+ height: frame.element.clientHeight,
623
+ });
624
+ });
625
+ this._nodes.forEach((node) => {
626
+ node.content.outputs.forEach((output) => {
627
+ if (!output.hasEndpoints) {
628
+ return;
629
+ }
630
+ output.endpoints.forEach((endpoint) => {
631
+ const sourceFrames = this._frames.filter((f) => f.nodes.indexOf(node) !== -1);
632
+ const targetFrames = this._frames.filter((f) => f.nodes.some((n) => n.content.data === endpoint.ownerData));
633
+ const sourceId = sourceFrames.length > 0 ? sourceFrames[0].id : node.id;
634
+ const targetId = targetFrames.length > 0 ? targetFrames[0].id : endpoint.ownerData.uniqueId;
635
+ graph.setEdge(sourceId.toString(), targetId.toString());
636
+ });
637
+ });
638
+ });
639
+ // Distribute
640
+ dagre.layout(graph);
641
+ // Update graph
642
+ const dagreNodes = graph.nodes().map((node) => graph.node(node));
643
+ dagreNodes.forEach((dagreNode) => {
644
+ if (!dagreNode) {
645
+ return;
646
+ }
647
+ if (dagreNode.type === "node") {
648
+ for (const node of this._nodes) {
649
+ if (node.id === dagreNode.id) {
650
+ node.x = dagreNode.x - dagreNode.width / 2;
651
+ node.y = dagreNode.y - dagreNode.height / 2;
652
+ node.cleanAccumulation();
653
+ return;
654
+ }
655
+ }
656
+ return;
657
+ }
658
+ for (const frame of this._frames) {
659
+ if (frame.id === dagreNode.id) {
660
+ this._frameIsMoving = true;
661
+ frame.move(dagreNode.x - dagreNode.width / 2, dagreNode.y - dagreNode.height / 2, false);
662
+ frame.cleanAccumulation();
663
+ this._frameIsMoving = false;
664
+ return;
665
+ }
666
+ }
667
+ });
668
+ }
669
+ componentDidMount() {
670
+ this._hostCanvas = this.props.stateManager.hostDocument.getElementById("graph-canvas");
671
+ this._rootContainer = this.props.stateManager.hostDocument.getElementById("graph-container");
672
+ this._graphCanvas = this.props.stateManager.hostDocument.getElementById("graph-canvas-container");
673
+ this._svgCanvas = this.props.stateManager.hostDocument.getElementById("graph-svg-container");
674
+ this._selectionContainer = this.props.stateManager.hostDocument.getElementById("selection-container");
675
+ this._frameContainer = this.props.stateManager.hostDocument.getElementById("frame-container");
676
+ this.gridSize = DataStorage.ReadNumber("GridSize", 20);
677
+ this.updateTransform();
678
+ }
679
+ onMove(evt) {
680
+ // Selection box
681
+ if (this._selectionBox) {
682
+ const rootRect = this.canvasContainer.getBoundingClientRect();
683
+ const localX = evt.pageX - rootRect.left;
684
+ const localY = evt.pageY - rootRect.top;
685
+ if (localX > this._selectionStartX) {
686
+ this._selectionBox.style.left = `${this._selectionStartX / this.zoom}px`;
687
+ this._selectionBox.style.width = `${(localX - this._selectionStartX) / this.zoom}px`;
688
+ }
689
+ else {
690
+ this._selectionBox.style.left = `${localX / this.zoom}px`;
691
+ this._selectionBox.style.width = `${(this._selectionStartX - localX) / this.zoom}px`;
692
+ }
693
+ if (localY > this._selectionStartY) {
694
+ this._selectionBox.style.top = `${this._selectionStartY / this.zoom}px`;
695
+ this._selectionBox.style.height = `${(localY - this._selectionStartY) / this.zoom}px`;
696
+ }
697
+ else {
698
+ this._selectionBox.style.top = `${localY / this.zoom}px`;
699
+ this._selectionBox.style.height = `${(this._selectionStartY - localY) / this.zoom}px`;
700
+ }
701
+ this.props.stateManager.onSelectionBoxMoved.notifyObservers(this._selectionBox.getBoundingClientRect());
702
+ return;
703
+ }
704
+ // Candidate frame box
705
+ if (this._frameCandidate) {
706
+ const rootRect = this.canvasContainer.getBoundingClientRect();
707
+ const localX = evt.pageX - rootRect.left;
708
+ const localY = evt.pageY - rootRect.top;
709
+ if (localX > this._selectionStartX) {
710
+ this._frameCandidate.style.left = `${this._selectionStartX / this.zoom}px`;
711
+ this._frameCandidate.style.width = `${(localX - this._selectionStartX) / this.zoom}px`;
712
+ }
713
+ else {
714
+ this._frameCandidate.style.left = `${localX / this.zoom}px`;
715
+ this._frameCandidate.style.width = `${(this._selectionStartX - localX) / this.zoom}px`;
716
+ }
717
+ if (localY > this._selectionStartY) {
718
+ this._frameCandidate.style.top = `${this._selectionStartY / this.zoom}px`;
719
+ this._frameCandidate.style.height = `${(localY - this._selectionStartY) / this.zoom}px`;
720
+ }
721
+ else {
722
+ this._frameCandidate.style.top = `${localY / this.zoom}px`;
723
+ this._frameCandidate.style.height = `${(this._selectionStartY - localY) / this.zoom}px`;
724
+ }
725
+ return;
726
+ }
727
+ // Candidate link
728
+ if (this._candidateLink) {
729
+ const rootRect = this.canvasContainer.getBoundingClientRect();
730
+ this._candidatePort = null;
731
+ this.props.stateManager.onCandidateLinkMoved.notifyObservers(new Vector2(evt.pageX, evt.pageY));
732
+ this._dropPointX = (evt.pageX - rootRect.left) / this.zoom;
733
+ this._dropPointY = (evt.pageY - rootRect.top) / this.zoom;
734
+ this._candidateLink.update(this._dropPointX, this._dropPointY, true);
735
+ this._candidateLinkedHasMoved = true;
736
+ return;
737
+ }
738
+ // Zoom with mouse + alt
739
+ if (this._altKeyIsPressed && evt.buttons === 1) {
740
+ if (this._oldY < 0) {
741
+ this._oldY = evt.pageY;
742
+ }
743
+ const zoomDelta = (evt.pageY - this._oldY) / 10;
744
+ if (Math.abs(zoomDelta) > 5) {
745
+ const oldZoom = this.zoom;
746
+ this.zoom = Math.max(Math.min(this._maxZoom, this.zoom + zoomDelta / 100), this._minZoom);
747
+ const boundingRect = evt.currentTarget.getBoundingClientRect();
748
+ const clientWidth = boundingRect.width;
749
+ const widthDiff = clientWidth * this.zoom - clientWidth * oldZoom;
750
+ const clientX = evt.clientX - boundingRect.left;
751
+ const xFactor = (clientX - this.x) / oldZoom / clientWidth;
752
+ this.x = this.x - widthDiff * xFactor;
753
+ this._oldY = evt.pageY;
754
+ }
755
+ return;
756
+ }
757
+ // Move canvas
758
+ this._rootContainer.style.cursor = "move";
759
+ if (this._mouseStartPointX === null || this._mouseStartPointY === null) {
760
+ return;
761
+ }
762
+ this.x += evt.clientX - this._mouseStartPointX;
763
+ this.y += evt.clientY - this._mouseStartPointY;
764
+ this._mouseStartPointX = evt.clientX;
765
+ this._mouseStartPointY = evt.clientY;
766
+ }
767
+ onDown(evt) {
768
+ this._rootContainer.setPointerCapture(evt.pointerId);
769
+ // Port dragging
770
+ if (evt.nativeEvent.srcElement && evt.nativeEvent.srcElement.nodeName === "IMG") {
771
+ if (!this._candidateLink) {
772
+ const portElement = evt.nativeEvent.srcElement.parentElement.port;
773
+ if (this._altKeyIsPressed && (portElement.portData.isConnected || portElement.portData.hasEndpoints)) {
774
+ const node = portElement.node;
775
+ // Delete connection
776
+ const links = node.getLinksForPortData(portElement.portData);
777
+ links.forEach((link) => {
778
+ link.dispose(false);
779
+ });
780
+ // Pick the first one as target port
781
+ const targetNode = links[0].nodeA === node ? links[0].nodeB : links[0].nodeA;
782
+ const targetPort = links[0].nodeA === node ? links[0].portB : links[0].portA;
783
+ // Start a new one
784
+ this._candidateLink = new NodeLink(this, targetPort, targetNode);
785
+ }
786
+ else if (this._multiKeyIsPressed && (portElement.portData.isConnected || portElement.portData.hasEndpoints)) {
787
+ const node = portElement.node;
788
+ const links = node.getLinksForPortData(portElement.portData);
789
+ // Pick the first one as target port
790
+ const linkToConsider = this._selectedLink || links[0];
791
+ const targetNode = linkToConsider.nodeA === node ? linkToConsider.nodeB : linkToConsider.nodeA;
792
+ const targetPort = linkToConsider.nodeA === node ? linkToConsider.portB : linkToConsider.portA;
793
+ // Start a new one
794
+ this._candidateLink = new NodeLink(this, targetPort, targetNode);
795
+ }
796
+ else {
797
+ this._candidateLink = new NodeLink(this, portElement, portElement.node);
798
+ }
799
+ this._candidateLinkedHasMoved = false;
800
+ }
801
+ return;
802
+ }
803
+ // Selection?
804
+ if (evt.currentTarget === this._hostCanvas && this._multiKeyIsPressed) {
805
+ this._selectionBox = this.props.stateManager.hostDocument.createElement("div");
806
+ this._selectionBox.classList.add(styles["selection-box"]);
807
+ this._selectionContainer.appendChild(this._selectionBox);
808
+ const rootRect = this.canvasContainer.getBoundingClientRect();
809
+ this._selectionStartX = evt.pageX - rootRect.left;
810
+ this._selectionStartY = evt.pageY - rootRect.top;
811
+ this._selectionBox.style.left = `${this._selectionStartX / this.zoom}px`;
812
+ this._selectionBox.style.top = `${this._selectionStartY / this.zoom}px`;
813
+ this._selectionBox.style.width = "0px";
814
+ this._selectionBox.style.height = "0px";
815
+ return;
816
+ }
817
+ // Frame?
818
+ if (evt.currentTarget === this._hostCanvas && evt.shiftKey) {
819
+ this._frameCandidate = this.props.stateManager.hostDocument.createElement("div");
820
+ this._frameCandidate.classList.add(commonStyles["frame-box"]);
821
+ this._frameContainer.appendChild(this._frameCandidate);
822
+ const rootRect = this.canvasContainer.getBoundingClientRect();
823
+ this._selectionStartX = evt.pageX - rootRect.left;
824
+ this._selectionStartY = evt.pageY - rootRect.top;
825
+ this._frameCandidate.style.left = `${this._selectionStartX / this.zoom}px`;
826
+ this._frameCandidate.style.top = `${this._selectionStartY / this.zoom}px`;
827
+ this._frameCandidate.style.width = "0px";
828
+ this._frameCandidate.style.height = "0px";
829
+ return;
830
+ }
831
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers(null);
832
+ this._mouseStartPointX = evt.clientX;
833
+ this._mouseStartPointY = evt.clientY;
834
+ }
835
+ onUp(evt) {
836
+ this._mouseStartPointX = null;
837
+ this._mouseStartPointY = null;
838
+ this._rootContainer.releasePointerCapture(evt.pointerId);
839
+ this._oldY = -1;
840
+ if (this._candidateLink) {
841
+ if (this._candidateLinkedHasMoved) {
842
+ this.processCandidatePort();
843
+ this.props.stateManager.onCandidateLinkMoved.notifyObservers(null);
844
+ }
845
+ else {
846
+ // is a click event on NodePort
847
+ if (this._candidateLink.portA instanceof FrameNodePort) {
848
+ //only on Frame Node Ports
849
+ const port = this._candidateLink.portA;
850
+ const frame = this.frames.find((frame) => frame.id === port.parentFrameId);
851
+ if (frame) {
852
+ const data = {
853
+ frame,
854
+ port,
855
+ };
856
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers({ selection: data });
857
+ }
858
+ }
859
+ else if (this._candidateLink.portA instanceof NodePort) {
860
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers({ selection: this._candidateLink.portA });
861
+ }
862
+ }
863
+ this._candidateLink.dispose();
864
+ this._candidateLink = null;
865
+ this._candidatePort = null;
866
+ }
867
+ if (this._selectionBox) {
868
+ this._selectionBox.parentElement.removeChild(this._selectionBox);
869
+ this._selectionBox = null;
870
+ }
871
+ if (this._frameCandidate) {
872
+ const newFrame = new GraphFrame(this._frameCandidate, this);
873
+ this._frames.push(newFrame);
874
+ this._frameCandidate.parentElement.removeChild(this._frameCandidate);
875
+ this._frameCandidate = null;
876
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers({ selection: newFrame });
877
+ }
878
+ }
879
+ onWheel(evt) {
880
+ const delta = evt.deltaY < 0 ? 0.1 : -0.1;
881
+ const oldZoom = this.zoom;
882
+ this.zoom = Math.min(Math.max(this._minZoom, this.zoom + delta * this.zoom), this._maxZoom);
883
+ const boundingRect = evt.currentTarget.getBoundingClientRect();
884
+ const clientWidth = boundingRect.width;
885
+ const clientHeight = boundingRect.height;
886
+ const widthDiff = clientWidth * this.zoom - clientWidth * oldZoom;
887
+ const heightDiff = clientHeight * this.zoom - clientHeight * oldZoom;
888
+ const clientX = evt.clientX - boundingRect.left;
889
+ const clientY = evt.clientY - boundingRect.top;
890
+ const xFactor = (clientX - this.x) / oldZoom / clientWidth;
891
+ const yFactor = (clientY - this.y) / oldZoom / clientHeight;
892
+ this.x = this.x - widthDiff * xFactor;
893
+ this.y = this.y - heightDiff * yFactor;
894
+ }
895
+ zoomToFit() {
896
+ // Get negative offset
897
+ let minX = 0;
898
+ let minY = 0;
899
+ this._nodes.forEach((node) => {
900
+ if (this._frames.some((f) => f.nodes.indexOf(node) !== -1)) {
901
+ return;
902
+ }
903
+ if (node.x < minX) {
904
+ minX = node.x;
905
+ }
906
+ if (node.y < minY) {
907
+ minY = node.y;
908
+ }
909
+ });
910
+ this._frames.forEach((frame) => {
911
+ if (frame.x < minX) {
912
+ minX = frame.x;
913
+ }
914
+ if (frame.y < minY) {
915
+ minY = frame.y;
916
+ }
917
+ });
918
+ // Restore to 0
919
+ this._frames.forEach((frame) => {
920
+ frame.x += -minX;
921
+ frame.y += -minY;
922
+ frame.cleanAccumulation();
923
+ });
924
+ this._nodes.forEach((node) => {
925
+ node.x += -minX;
926
+ node.y += -minY;
927
+ node.cleanAccumulation();
928
+ });
929
+ // Get correct zoom
930
+ const xFactor = this._rootContainer.clientWidth / this._rootContainer.scrollWidth;
931
+ const yFactor = this._rootContainer.clientHeight / this._rootContainer.scrollHeight;
932
+ const zoomFactor = xFactor < yFactor ? xFactor : yFactor;
933
+ this.zoom = zoomFactor;
934
+ this.x = 0;
935
+ this.y = 0;
936
+ }
937
+ processCandidatePort() {
938
+ let pointB = this._candidateLink.portA.portData;
939
+ let nodeB = this._candidateLink.portA.node;
940
+ let pointA;
941
+ let nodeA;
942
+ if (this._candidatePort) {
943
+ pointA = this._candidatePort.portData;
944
+ nodeA = this._candidatePort.node;
945
+ }
946
+ else {
947
+ if (pointB.direction === PortDataDirection.Output) {
948
+ return;
949
+ }
950
+ // No destination so let's spin a new input node
951
+ const newDefaultInput = this.props.stateManager.createDefaultInputData(this.props.stateManager.data, this._candidateLink.portA.portData, this);
952
+ if (!newDefaultInput) {
953
+ return;
954
+ }
955
+ const pointName = newDefaultInput.name;
956
+ const emittedNodeData = newDefaultInput.data;
957
+ pointA = emittedNodeData.getPortByName(pointName);
958
+ if (!emittedNodeData.isInput) {
959
+ nodeA = this.props.onEmitNewNode(emittedNodeData);
960
+ }
961
+ else {
962
+ nodeA = this.appendNode(emittedNodeData);
963
+ }
964
+ nodeA.x = this._dropPointX - 200;
965
+ nodeA.y = this._dropPointY - 50;
966
+ const x = nodeA.x - 250;
967
+ let y = nodeA.y;
968
+ emittedNodeData.inputs.forEach((portData) => {
969
+ if (portData.connectedPort) {
970
+ const existingNodes = this.nodes.filter((n) => {
971
+ var _a;
972
+ return n.content.data === ((_a = portData.connectedPort) === null || _a === void 0 ? void 0 : _a.ownerData);
973
+ });
974
+ const connectedNode = existingNodes[0];
975
+ if (connectedNode.x === 0 && connectedNode.y === 0) {
976
+ connectedNode.x = x;
977
+ connectedNode.y = y;
978
+ connectedNode.cleanAccumulation();
979
+ y += 80;
980
+ }
981
+ }
982
+ });
983
+ }
984
+ if (pointA.direction === PortDataDirection.Input) {
985
+ const temp = pointB;
986
+ pointB = pointA;
987
+ pointA = temp;
988
+ const tempNode = nodeA;
989
+ nodeA = nodeB;
990
+ nodeB = tempNode;
991
+ }
992
+ if (pointB.connectedPort === pointA) {
993
+ return;
994
+ }
995
+ if (pointB === pointA) {
996
+ return;
997
+ }
998
+ if (pointB.direction === pointA.direction) {
999
+ return;
1000
+ }
1001
+ if (pointB.ownerData === pointA.ownerData) {
1002
+ return;
1003
+ }
1004
+ // Check compatibility
1005
+ let compatibilityState = pointA.checkCompatibilityState(pointB);
1006
+ if ((pointA.needDualDirectionValidation || pointB.needDualDirectionValidation) && !compatibilityState) {
1007
+ compatibilityState = pointB.checkCompatibilityState(pointA);
1008
+ }
1009
+ const message = pointA.getCompatibilityIssueMessage(compatibilityState, nodeB, pointB);
1010
+ if (message) {
1011
+ this.props.stateManager.onErrorMessageDialogRequiredObservable.notifyObservers(message);
1012
+ return;
1013
+ }
1014
+ let linksToNotifyForDispose = null;
1015
+ if (pointB.isConnected) {
1016
+ const links = nodeB.getLinksForPortData(pointB);
1017
+ linksToNotifyForDispose = links.slice();
1018
+ links.forEach((link) => {
1019
+ link.dispose(false);
1020
+ });
1021
+ }
1022
+ if (pointB.ownerData.inputsAreExclusive) {
1023
+ // Disconnect all inputs if node has exclusive inputs
1024
+ pointB.ownerData.inputs.forEach((i) => {
1025
+ const links = nodeB.getLinksForPortData(i);
1026
+ if (!linksToNotifyForDispose) {
1027
+ linksToNotifyForDispose = links.slice();
1028
+ }
1029
+ else {
1030
+ linksToNotifyForDispose.push(...links.slice());
1031
+ }
1032
+ links.forEach((link) => {
1033
+ link.dispose(false);
1034
+ });
1035
+ });
1036
+ }
1037
+ this.connectNodes(nodeA, pointA, nodeB, pointB);
1038
+ linksToNotifyForDispose === null || linksToNotifyForDispose === void 0 ? void 0 : linksToNotifyForDispose.forEach((link) => {
1039
+ link.onDisposedObservable.notifyObservers(link);
1040
+ link.onDisposedObservable.clear();
1041
+ });
1042
+ this.props.stateManager.onRebuildRequiredObservable.notifyObservers(true);
1043
+ }
1044
+ connectNodes(nodeA, pointA, nodeB, pointB) {
1045
+ pointA.connectTo(pointB);
1046
+ this.connectPorts(pointA, pointB);
1047
+ // Need to potentially propagate the type of pointA to other ports of nodes connected to owner of pointB
1048
+ // We also need to check if we want to display the promotion warning
1049
+ const visitedNodes = new Set([nodeA]);
1050
+ const visitedLinks = new Set([nodeB.links[nodeB.links.length - 1]]);
1051
+ RefreshNode(nodeB, visitedNodes, visitedLinks);
1052
+ }
1053
+ drop(newNode, targetX, targetY, offsetX, offsetY) {
1054
+ let x = targetX - this.x - offsetX * this.zoom;
1055
+ let y = targetY - this.y - offsetY * this.zoom;
1056
+ newNode.x = x / this.zoom;
1057
+ newNode.y = y / this.zoom;
1058
+ newNode.cleanAccumulation();
1059
+ this.props.stateManager.onNewNodeCreatedObservable.notifyObservers(newNode);
1060
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers(null);
1061
+ this.props.stateManager.onSelectionChangedObservable.notifyObservers({ selection: newNode });
1062
+ x -= GraphCanvasComponent.NodeWidth + 150;
1063
+ newNode.content.inputs.forEach((portData) => {
1064
+ if (portData.connectedPort) {
1065
+ const existingNodes = this.nodes.filter((n) => {
1066
+ var _a;
1067
+ return n.content.data === ((_a = portData.connectedPort) === null || _a === void 0 ? void 0 : _a.ownerData);
1068
+ });
1069
+ const connectedNode = existingNodes[0];
1070
+ if (connectedNode.x === 0 && connectedNode.y === 0) {
1071
+ connectedNode.x = x / this.zoom;
1072
+ connectedNode.y = y / this.zoom;
1073
+ connectedNode.cleanAccumulation();
1074
+ y += 80;
1075
+ }
1076
+ }
1077
+ });
1078
+ }
1079
+ processEditorData(editorData) {
1080
+ const frames = this._frames.splice(0);
1081
+ for (const frame of frames) {
1082
+ frame.dispose();
1083
+ }
1084
+ this._frames = [];
1085
+ this.x = editorData.x || 0;
1086
+ this.y = editorData.y || 0;
1087
+ this.zoom = editorData.zoom || 1;
1088
+ // Frames
1089
+ if (editorData.frames) {
1090
+ for (const frameData of editorData.frames) {
1091
+ const frame = GraphFrame.Parse(frameData, this, editorData.map);
1092
+ this._frames.push(frame);
1093
+ }
1094
+ }
1095
+ }
1096
+ reOrganize(editorData = null, isImportingAFrame = false) {
1097
+ if (!editorData || !editorData.locations) {
1098
+ this.distributeGraph();
1099
+ }
1100
+ else {
1101
+ // Locations
1102
+ for (const location of editorData.locations) {
1103
+ for (const node of this.nodes) {
1104
+ const data = node.content.data;
1105
+ if (data && data.uniqueId === location.blockId) {
1106
+ node.x = location.x;
1107
+ node.y = location.y;
1108
+ node.cleanAccumulation();
1109
+ break;
1110
+ }
1111
+ }
1112
+ }
1113
+ if (!isImportingAFrame) {
1114
+ this.processEditorData(editorData);
1115
+ }
1116
+ }
1117
+ this._isLoading = false;
1118
+ for (const node of this.nodes) {
1119
+ node._refreshLinks();
1120
+ }
1121
+ }
1122
+ addFrame(frameData) {
1123
+ const frame = GraphFrame.Parse(frameData, this, this.props.stateManager.getEditorDataMap());
1124
+ this._frames.push(frame);
1125
+ this.stateManager.onSelectionChangedObservable.notifyObservers({ selection: frame });
1126
+ }
1127
+ render() {
1128
+ return (_jsx("div", { id: "graph-canvas", className: styles["graph-canvas"], onWheel: (evt) => this.onWheel(evt), onPointerMove: (evt) => this.onMove(evt), onPointerDown: (evt) => this.onDown(evt), onPointerUp: (evt) => this.onUp(evt), children: _jsxs("div", { id: "graph-container", className: styles["graph-container"], children: [_jsx("div", { id: "graph-canvas-container", className: styles["graph-canvas-container"] }), _jsx("div", { id: "frame-container", className: styles["frame-container"] }), _jsx("svg", { id: "graph-svg-container", className: styles["graph-svg-container"] }), _jsx("div", { id: "selection-container", className: styles["selection-container"] })] }) }));
1129
+ }
1130
+ }
1131
+ GraphCanvasComponent.NodeWidth = 100;
1132
+ //# sourceMappingURL=graphCanvas.js.map