@babylonjs/shared-ui-components 5.28.0 → 5.29.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.
- package/colorPicker/colorComponentEntry.d.ts +18 -18
- package/colorPicker/colorComponentEntry.js +36 -36
- package/colorPicker/colorPicker.d.ts +43 -43
- package/colorPicker/colorPicker.js +136 -136
- package/colorPicker/hexColor.d.ts +20 -20
- package/colorPicker/hexColor.js +42 -42
- package/components/Button.d.ts +10 -10
- package/components/Button.js +6 -6
- package/components/Icon.d.ts +6 -6
- package/components/Icon.js +6 -6
- package/components/Label.d.ts +7 -7
- package/components/Label.js +6 -6
- package/components/MessageDialog.d.ts +7 -7
- package/components/MessageDialog.js +22 -22
- package/components/Toggle.d.ts +8 -8
- package/components/Toggle.js +15 -15
- package/components/bars/CommandBarComponent.d.ts +16 -16
- package/components/bars/CommandBarComponent.js +68 -68
- package/components/bars/CommandButtonComponent.d.ts +11 -11
- package/components/bars/CommandButtonComponent.js +6 -6
- package/components/bars/CommandDropdownComponent.d.ts +26 -26
- package/components/bars/CommandDropdownComponent.js +48 -48
- package/components/classNames.d.ts +2 -2
- package/components/classNames.js +18 -18
- package/components/colorPicker/ColorComponentEntry.d.ts +18 -18
- package/components/colorPicker/ColorComponentEntry.js +37 -37
- package/components/colorPicker/ColorPicker.d.ts +43 -43
- package/components/colorPicker/ColorPicker.js +137 -137
- package/components/colorPicker/HexColor.d.ts +20 -20
- package/components/colorPicker/HexColor.js +45 -45
- package/components/layout/DraggableIcon.d.ts +23 -0
- package/components/layout/DraggableIcon.js +18 -0
- package/components/layout/DraggableIcon.js.map +1 -0
- package/components/layout/FlexibleColumn.d.ts +17 -0
- package/components/layout/FlexibleColumn.js +12 -0
- package/components/layout/FlexibleColumn.js.map +1 -0
- package/components/layout/FlexibleDragHandler.d.ts +18 -0
- package/components/layout/FlexibleDragHandler.js +88 -0
- package/components/layout/FlexibleDragHandler.js.map +1 -0
- package/components/layout/FlexibleDropZone.d.ts +19 -0
- package/components/layout/FlexibleDropZone.js +12 -0
- package/components/layout/FlexibleDropZone.js.map +1 -0
- package/components/layout/FlexibleGridContainer.d.ts +10 -0
- package/components/layout/FlexibleGridContainer.js +23 -0
- package/components/layout/FlexibleGridContainer.js.map +1 -0
- package/components/layout/FlexibleGridLayout.d.ts +16 -0
- package/components/layout/FlexibleGridLayout.js +24 -0
- package/components/layout/FlexibleGridLayout.js.map +1 -0
- package/components/layout/FlexibleResizeBar.d.ts +40 -0
- package/components/layout/FlexibleResizeBar.js +21 -0
- package/components/layout/FlexibleResizeBar.js.map +1 -0
- package/components/layout/FlexibleTab.d.ts +34 -0
- package/components/layout/FlexibleTab.js +36 -0
- package/components/layout/FlexibleTab.js.map +1 -0
- package/components/layout/FlexibleTabsContainer.d.ts +28 -0
- package/components/layout/FlexibleTabsContainer.js +54 -0
- package/components/layout/FlexibleTabsContainer.js.map +1 -0
- package/components/layout/LayoutContext.d.ts +12 -0
- package/components/layout/LayoutContext.js +3 -0
- package/components/layout/LayoutContext.js.map +1 -0
- package/components/layout/types.d.ts +78 -0
- package/components/layout/types.js +13 -0
- package/components/layout/types.js.map +1 -0
- package/components/layout/utils.d.ts +25 -0
- package/components/layout/utils.js +68 -0
- package/components/layout/utils.js.map +1 -0
- package/components/lines/ColorLineComponent.d.ts +40 -40
- package/components/lines/ColorLineComponent.js +145 -145
- package/components/lines/ColorPickerLineComponent.d.ts +33 -33
- package/components/lines/ColorPickerLineComponent.js +61 -61
- package/components/lines/FileButtonLineComponent.d.ts +16 -16
- package/components/lines/FileButtonLineComponent.js +21 -21
- package/components/lines/NumericInputComponent.d.ts +31 -31
- package/components/lines/NumericInputComponent.js +86 -86
- package/lines/booleanLineComponent.d.ts +11 -11
- package/lines/booleanLineComponent.js +14 -14
- package/lines/buttonLineComponent.d.ts +12 -12
- package/lines/buttonLineComponent.js +10 -10
- package/lines/checkBoxLineComponent.d.ts +36 -36
- package/lines/checkBoxLineComponent.js +88 -88
- package/lines/color3LineComponent.d.ts +18 -18
- package/lines/color3LineComponent.js +9 -9
- package/lines/color4LineComponent.d.ts +18 -18
- package/lines/color4LineComponent.js +9 -9
- package/lines/colorLineComponent.d.ts +40 -40
- package/lines/colorLineComponent.js +144 -144
- package/lines/colorPickerComponent.d.ts +31 -31
- package/lines/colorPickerComponent.js +60 -60
- package/lines/draggableLineComponent.d.ts +9 -9
- package/lines/draggableLineComponent.js +12 -12
- package/lines/fileButtonLineComponent.d.ts +17 -17
- package/lines/fileButtonLineComponent.js +20 -20
- package/lines/fileMultipleButtonLineComponent.d.ts +17 -17
- package/lines/fileMultipleButtonLineComponent.js +20 -20
- package/lines/floatLineComponent.d.ts +50 -50
- package/lines/floatLineComponent.js +175 -175
- package/lines/hexLineComponent.d.ts +40 -40
- package/lines/hexLineComponent.js +121 -121
- package/lines/iSelectedLineContainer.d.ts +4 -4
- package/lines/iSelectedLineContainer.js +1 -1
- package/lines/iconButtonLineComponent.d.ts +11 -11
- package/lines/iconButtonLineComponent.js +10 -10
- package/lines/iconComponent.d.ts +9 -9
- package/lines/iconComponent.js +7 -7
- package/lines/indentedTextLineComponent.d.ts +16 -16
- package/lines/indentedTextLineComponent.js +26 -26
- package/lines/inputArrowsComponent.d.ts +13 -13
- package/lines/inputArrowsComponent.js +37 -37
- package/lines/lineContainerComponent.d.ts +19 -19
- package/lines/lineContainerComponent.js +49 -49
- package/lines/linkButtonComponent.d.ts +16 -16
- package/lines/linkButtonComponent.js +20 -20
- package/lines/matrixLineComponent.d.ts +36 -36
- package/lines/matrixLineComponent.js +102 -102
- package/lines/messageLineComponent.d.ts +12 -12
- package/lines/messageLineComponent.js +14 -14
- package/lines/numericInputComponent.d.ts +31 -31
- package/lines/numericInputComponent.js +85 -85
- package/lines/optionsLineComponent.d.ts +48 -48
- package/lines/optionsLineComponent.js +118 -118
- package/lines/popup.d.ts +4 -4
- package/lines/popup.js +67 -67
- package/lines/radioLineComponent.d.ts +21 -21
- package/lines/radioLineComponent.js +26 -26
- package/lines/sliderLineComponent.d.ts +37 -37
- package/lines/sliderLineComponent.js +89 -89
- package/lines/targetsProxy.d.ts +11 -11
- package/lines/targetsProxy.js +42 -42
- package/lines/textInputLineComponent.d.ts +47 -47
- package/lines/textInputLineComponent.js +154 -154
- package/lines/textLineComponent.d.ts +21 -21
- package/lines/textLineComponent.js +30 -30
- package/lines/unitButton.d.ts +8 -8
- package/lines/unitButton.js +7 -7
- package/lines/valueLineComponent.d.ts +15 -15
- package/lines/valueLineComponent.js +12 -12
- package/lines/vector2LineComponent.d.ts +36 -36
- package/lines/vector2LineComponent.js +63 -63
- package/lines/vector3LineComponent.d.ts +41 -41
- package/lines/vector3LineComponent.js +74 -74
- package/lines/vector4LineComponent.d.ts +42 -42
- package/lines/vector4LineComponent.js +81 -81
- package/nodeGraphSystem/displayLedger.d.ts +5 -5
- package/nodeGraphSystem/displayLedger.js +3 -3
- package/nodeGraphSystem/frameNodePort.d.ts +25 -25
- package/nodeGraphSystem/frameNodePort.js +59 -59
- package/nodeGraphSystem/graphCanvas.d.ts +111 -111
- package/nodeGraphSystem/graphCanvas.js +1131 -1131
- package/nodeGraphSystem/graphFrame.d.ts +153 -153
- package/nodeGraphSystem/graphFrame.js +1328 -1328
- package/nodeGraphSystem/graphNode.d.ts +79 -79
- package/nodeGraphSystem/graphNode.js +459 -459
- package/nodeGraphSystem/interfaces/displayManager.d.ts +13 -13
- package/nodeGraphSystem/interfaces/displayManager.js +1 -1
- package/nodeGraphSystem/interfaces/nodeContainer.d.ts +6 -6
- package/nodeGraphSystem/interfaces/nodeContainer.js +1 -1
- package/nodeGraphSystem/interfaces/nodeData.d.ts +15 -15
- package/nodeGraphSystem/interfaces/nodeData.js +1 -1
- package/nodeGraphSystem/interfaces/nodeLocationInfo.d.ts +26 -26
- package/nodeGraphSystem/interfaces/nodeLocationInfo.js +1 -1
- package/nodeGraphSystem/interfaces/portData.d.ts +28 -28
- package/nodeGraphSystem/interfaces/portData.js +7 -7
- package/nodeGraphSystem/interfaces/propertyComponentProps.d.ts +6 -6
- package/nodeGraphSystem/interfaces/propertyComponentProps.js +1 -1
- package/nodeGraphSystem/interfaces/selectionChangedOptions.d.ts +11 -11
- package/nodeGraphSystem/interfaces/selectionChangedOptions.js +1 -1
- package/nodeGraphSystem/nodeLink.d.ts +31 -31
- package/nodeGraphSystem/nodeLink.js +182 -182
- package/nodeGraphSystem/nodePort.d.ts +35 -35
- package/nodeGraphSystem/nodePort.js +128 -128
- package/nodeGraphSystem/propertyLedger.d.ts +8 -8
- package/nodeGraphSystem/propertyLedger.js +3 -3
- package/nodeGraphSystem/stateManager.d.ts +45 -45
- package/nodeGraphSystem/stateManager.js +18 -18
- package/nodeGraphSystem/tools.d.ts +5 -5
- package/nodeGraphSystem/tools.js +36 -36
- package/nodeGraphSystem/typeLedger.d.ts +8 -8
- package/nodeGraphSystem/typeLedger.js +2 -2
- package/nodeGraphSystem/types/framePortData.d.ts +7 -7
- package/nodeGraphSystem/types/framePortData.js +1 -1
- package/package.json +4 -3
- package/propertyChangedEvent.d.ts +7 -7
- package/propertyChangedEvent.js +2 -2
- package/stories/Button.stories.d.ts +10 -10
- package/stories/Button.stories.js +19 -19
- package/stories/Icon.stories.d.ts +9 -9
- package/stories/Icon.stories.js +16 -16
- package/stories/Label.stories.d.ts +8 -8
- package/stories/Label.stories.js +10 -10
- package/stories/MessageDialog.stories.d.ts +9 -9
- package/stories/MessageDialog.stories.js +19 -19
- package/stories/Toggle.stories.d.ts +9 -9
- package/stories/Toggle.stories.js +17 -17
- package/stories/bars/CommandBarComponent.stories.d.ts +11 -11
- package/stories/bars/CommandBarComponent.stories.js +12 -12
- package/stories/bars/CommandButtonComponent.stories.d.ts +6 -6
- package/stories/bars/CommandButtonComponent.stories.js +6 -6
- package/stories/colorPicker/ColorPicker.stories.d.ts +11 -11
- package/stories/colorPicker/ColorPicker.stories.js +4 -4
- package/stories/layout/FlexibleGridLayout.stories.d.ts +46 -0
- package/stories/layout/FlexibleGridLayout.stories.js +48 -0
- package/stories/layout/FlexibleGridLayout.stories.js.map +1 -0
- package/stories/lines/ColorLineComponent.stories.d.ts +21 -21
- package/stories/lines/ColorLineComponent.stories.js +9 -9
- package/stories/lines/ColorPickerLineComponent.stories.d.ts +14 -14
- package/stories/lines/ColorPickerLineComponent.stories.js +10 -10
- package/stories/lines/FileButtonLineComponent.stories.d.ts +6 -6
- package/stories/lines/FileButtonLineComponent.stories.js +5 -5
- package/stories/lines/NumericInputComponent.stories.d.ts +11 -11
- package/stories/lines/NumericInputComponent.stories.js +5 -5
- package/stringTools.d.ts +11 -11
- package/stringTools.js +88 -88
- package/tabs/propertyGrids/gui/checkboxPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/checkboxPropertyGridComponent.js +15 -15
- package/tabs/propertyGrids/gui/colorPickerPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/colorPickerPropertyGridComponent.js +14 -14
- package/tabs/propertyGrids/gui/commonControlPropertyGridComponent.d.ts +17 -17
- package/tabs/propertyGrids/gui/commonControlPropertyGridComponent.js +55 -55
- package/tabs/propertyGrids/gui/controlPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/controlPropertyGridComponent.js +12 -12
- package/tabs/propertyGrids/gui/ellipsePropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/ellipsePropertyGridComponent.js +15 -15
- package/tabs/propertyGrids/gui/gridPropertyGridComponent.d.ts +17 -17
- package/tabs/propertyGrids/gui/gridPropertyGridComponent.js +38 -38
- package/tabs/propertyGrids/gui/imageBasedSliderPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/imageBasedSliderPropertyGridComponent.js +16 -16
- package/tabs/propertyGrids/gui/imagePropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/imagePropertyGridComponent.js +25 -25
- package/tabs/propertyGrids/gui/inputTextPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/inputTextPropertyGridComponent.js +17 -17
- package/tabs/propertyGrids/gui/linePropertyGridComponent.d.ts +16 -16
- package/tabs/propertyGrids/gui/linePropertyGridComponent.js +27 -27
- package/tabs/propertyGrids/gui/radioButtonPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/radioButtonPropertyGridComponent.js +17 -17
- package/tabs/propertyGrids/gui/rectanglePropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/rectanglePropertyGridComponent.js +15 -15
- package/tabs/propertyGrids/gui/scrollViewerPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/scrollViewerPropertyGridComponent.js +15 -15
- package/tabs/propertyGrids/gui/sliderPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/sliderPropertyGridComponent.js +16 -16
- package/tabs/propertyGrids/gui/stackPanelPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/stackPanelPropertyGridComponent.js +14 -14
- package/tabs/propertyGrids/gui/textBlockPropertyGridComponent.d.ts +15 -15
- package/tabs/propertyGrids/gui/textBlockPropertyGridComponent.js +34 -34
- package/tabs/propertyGrids/lockObject.d.ts +9 -9
- package/tabs/propertyGrids/lockObject.js +11 -11
@@ -1,1132 +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;
|
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
1132
|
//# sourceMappingURL=graphCanvas.js.map
|