@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,183 +1,183 @@
|
|
1
|
-
import { Observable } from "@babylonjs/core/Misc/observable.js";
|
2
|
-
import { RefreshNode } from "./tools.js";
|
3
|
-
import commonStyles from "./common.modules.scss";
|
4
|
-
import styles from "./nodeLink.modules.scss";
|
5
|
-
export class NodeLink {
|
6
|
-
constructor(graphCanvas, portA, nodeA, portB, nodeB) {
|
7
|
-
this._isVisible = true;
|
8
|
-
this._isTargetCandidate = false;
|
9
|
-
this.onDisposedObservable = new Observable();
|
10
|
-
this._portA = portA;
|
11
|
-
this._portB = portB;
|
12
|
-
this._nodeA = nodeA;
|
13
|
-
this._nodeB = nodeB;
|
14
|
-
this._graphCanvas = graphCanvas;
|
15
|
-
const document = portA.element.ownerDocument;
|
16
|
-
const svg = graphCanvas.svgCanvas;
|
17
|
-
// Create path
|
18
|
-
this._path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
19
|
-
this._path.setAttribute("fill", "none");
|
20
|
-
this._path.classList.add(styles["link"]);
|
21
|
-
svg.appendChild(this._path);
|
22
|
-
this._selectionPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
23
|
-
this._selectionPath.setAttribute("fill", "none");
|
24
|
-
this._selectionPath.classList.add(styles["selection-link"]);
|
25
|
-
svg.appendChild(this._selectionPath);
|
26
|
-
this._selectionPath.onmousedown = (evt) => this.onClick(evt);
|
27
|
-
if (this._portB) {
|
28
|
-
// Update
|
29
|
-
this.update();
|
30
|
-
}
|
31
|
-
this._onSelectionChangedObserver = this._graphCanvas.stateManager.onSelectionChangedObservable.add((options) => {
|
32
|
-
const { selection } = options || {};
|
33
|
-
if (selection === this) {
|
34
|
-
this._path.classList.add(styles["selected"]);
|
35
|
-
this._selectionPath.classList.add(styles["selected"]);
|
36
|
-
}
|
37
|
-
else {
|
38
|
-
this._path.classList.remove(styles["selected"]);
|
39
|
-
this._selectionPath.classList.remove(styles["selected"]);
|
40
|
-
}
|
41
|
-
});
|
42
|
-
}
|
43
|
-
get isTargetCandidate() {
|
44
|
-
return this._isTargetCandidate;
|
45
|
-
}
|
46
|
-
set isTargetCandidate(value) {
|
47
|
-
if (this._isTargetCandidate === value) {
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
this._isTargetCandidate = value;
|
51
|
-
if (value) {
|
52
|
-
this._path.classList.add(styles["target-candidate"]);
|
53
|
-
}
|
54
|
-
else {
|
55
|
-
this._path.classList.remove(styles["target-candidate"]);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
get isVisible() {
|
59
|
-
return this._isVisible;
|
60
|
-
}
|
61
|
-
set isVisible(value) {
|
62
|
-
this._isVisible = value;
|
63
|
-
if (!value) {
|
64
|
-
this._path.classList.add(commonStyles["hidden"]);
|
65
|
-
this._selectionPath.classList.add(commonStyles["hidden"]);
|
66
|
-
}
|
67
|
-
else {
|
68
|
-
this._path.classList.remove(commonStyles["hidden"]);
|
69
|
-
this._selectionPath.classList.remove(commonStyles["hidden"]);
|
70
|
-
}
|
71
|
-
this.update();
|
72
|
-
}
|
73
|
-
get portA() {
|
74
|
-
return this._portA;
|
75
|
-
}
|
76
|
-
get portB() {
|
77
|
-
return this._portB;
|
78
|
-
}
|
79
|
-
get nodeA() {
|
80
|
-
return this._nodeA;
|
81
|
-
}
|
82
|
-
get nodeB() {
|
83
|
-
return this._nodeB;
|
84
|
-
}
|
85
|
-
intersectsWith(rect) {
|
86
|
-
const locatRect = this._path.getBoundingClientRect();
|
87
|
-
if (rect.left > locatRect.right || rect.right < locatRect.left || rect.top > locatRect.bottom || rect.bottom < locatRect.top) {
|
88
|
-
return false;
|
89
|
-
}
|
90
|
-
const svg = this._graphCanvas.svgCanvas;
|
91
|
-
const rootRect = svg.getBoundingClientRect();
|
92
|
-
const left = rect.x - rootRect.x;
|
93
|
-
const top = rect.y - rootRect.y;
|
94
|
-
const right = left + rect.width;
|
95
|
-
const bottom = top + rect.height;
|
96
|
-
const sampleRate = 10; // Checking 10 times on the path should be enough
|
97
|
-
for (let index = 0; index < 1; index += 1 / sampleRate) {
|
98
|
-
const point = this._path.getPointAtLength(index * this._path.getTotalLength());
|
99
|
-
if (left < point.x && right > point.x && top < point.y && bottom > point.y) {
|
100
|
-
return true;
|
101
|
-
}
|
102
|
-
}
|
103
|
-
return false;
|
104
|
-
}
|
105
|
-
update(endX = 0, endY = 0, straight = false) {
|
106
|
-
const rectA = this._portA.element.getBoundingClientRect();
|
107
|
-
const rootRect = this._graphCanvas.canvasContainer.getBoundingClientRect();
|
108
|
-
const zoom = this._graphCanvas.zoom;
|
109
|
-
const xOffset = rootRect.left;
|
110
|
-
const yOffset = rootRect.top;
|
111
|
-
const startX = (rectA.left - xOffset + 0.5 * rectA.width) / zoom;
|
112
|
-
const startY = (rectA.top - yOffset + 0.5 * rectA.height) / zoom;
|
113
|
-
if (this._portB) {
|
114
|
-
const rectB = this._portB.element.getBoundingClientRect();
|
115
|
-
endX = (rectB.left - xOffset + 0.5 * rectB.width) / zoom;
|
116
|
-
endY = (rectB.top - yOffset + 0.5 * rectB.height) / zoom;
|
117
|
-
}
|
118
|
-
if (straight) {
|
119
|
-
this._path.setAttribute("d", `M${startX},${startY} L${endX},${endY}`);
|
120
|
-
this._path.setAttribute("stroke-dasharray", "10, 10");
|
121
|
-
this._path.setAttribute("stroke-linecap", "round");
|
122
|
-
}
|
123
|
-
else {
|
124
|
-
const deltaX = endX - startX;
|
125
|
-
const deltaY = endY - startY;
|
126
|
-
const tangentLength = Math.min(Math.sqrt(deltaX * deltaX + deltaY * deltaY) * 0.5, 300);
|
127
|
-
this._path.setAttribute("d", `M${startX},${startY} C${startX + tangentLength},${startY} ${endX - tangentLength},${endY} ${endX},${endY}`);
|
128
|
-
this._selectionPath.setAttribute("d", `M${startX},${startY} C${startX + tangentLength},${startY} ${endX - tangentLength},${endY} ${endX},${endY}`);
|
129
|
-
}
|
130
|
-
this._path.setAttribute("stroke", this._portA.element.style.backgroundColor);
|
131
|
-
}
|
132
|
-
onClick(evt) {
|
133
|
-
const stateManager = this._graphCanvas.stateManager;
|
134
|
-
if (evt.altKey) {
|
135
|
-
const nodeA = this._nodeA;
|
136
|
-
const pointA = this._portA.portData;
|
137
|
-
const nodeB = this._nodeB;
|
138
|
-
const pointB = this._portB.portData;
|
139
|
-
if (!stateManager.isElbowConnectionAllowed(this._portA, this._portB)) {
|
140
|
-
return;
|
141
|
-
}
|
142
|
-
// Create an elbow at the clicked location
|
143
|
-
stateManager.onNewNodeCreatedObservable.addOnce((newNode) => {
|
144
|
-
const newElbowBlock = newNode.content.data;
|
145
|
-
// Delete previous link
|
146
|
-
this.dispose();
|
147
|
-
// Connect to Elbow block
|
148
|
-
this._graphCanvas.connectNodes(nodeA, pointA, newNode, newNode.getPortDataForPortDataContent(newElbowBlock.input));
|
149
|
-
this._graphCanvas.connectNodes(newNode, newNode.getPortDataForPortDataContent(newElbowBlock.output), nodeB, pointB);
|
150
|
-
stateManager.onRebuildRequiredObservable.notifyObservers(true);
|
151
|
-
});
|
152
|
-
stateManager.onNewBlockRequiredObservable.notifyObservers({
|
153
|
-
type: "ElbowBlock",
|
154
|
-
targetX: evt.clientX,
|
155
|
-
targetY: evt.clientY,
|
156
|
-
needRepositioning: true,
|
157
|
-
});
|
158
|
-
return;
|
159
|
-
}
|
160
|
-
stateManager.onSelectionChangedObservable.notifyObservers({ selection: this });
|
161
|
-
}
|
162
|
-
dispose(notify = true) {
|
163
|
-
this._graphCanvas.stateManager.onSelectionChangedObservable.remove(this._onSelectionChangedObserver);
|
164
|
-
if (this._path.parentElement) {
|
165
|
-
this._path.parentElement.removeChild(this._path);
|
166
|
-
}
|
167
|
-
if (this._selectionPath.parentElement) {
|
168
|
-
this._selectionPath.parentElement.removeChild(this._selectionPath);
|
169
|
-
}
|
170
|
-
if (this._nodeB) {
|
171
|
-
this._nodeA.links.splice(this._nodeA.links.indexOf(this), 1);
|
172
|
-
this._nodeB.links.splice(this._nodeB.links.indexOf(this), 1);
|
173
|
-
this._graphCanvas.links.splice(this._graphCanvas.links.indexOf(this), 1);
|
174
|
-
this._portA.portData.disconnectFrom(this._portB.portData);
|
175
|
-
RefreshNode(this._nodeB);
|
176
|
-
}
|
177
|
-
if (notify) {
|
178
|
-
this.onDisposedObservable.notifyObservers(this);
|
179
|
-
this.onDisposedObservable.clear();
|
180
|
-
}
|
181
|
-
}
|
182
|
-
}
|
1
|
+
import { Observable } from "@babylonjs/core/Misc/observable.js";
|
2
|
+
import { RefreshNode } from "./tools.js";
|
3
|
+
import commonStyles from "./common.modules.scss";
|
4
|
+
import styles from "./nodeLink.modules.scss";
|
5
|
+
export class NodeLink {
|
6
|
+
constructor(graphCanvas, portA, nodeA, portB, nodeB) {
|
7
|
+
this._isVisible = true;
|
8
|
+
this._isTargetCandidate = false;
|
9
|
+
this.onDisposedObservable = new Observable();
|
10
|
+
this._portA = portA;
|
11
|
+
this._portB = portB;
|
12
|
+
this._nodeA = nodeA;
|
13
|
+
this._nodeB = nodeB;
|
14
|
+
this._graphCanvas = graphCanvas;
|
15
|
+
const document = portA.element.ownerDocument;
|
16
|
+
const svg = graphCanvas.svgCanvas;
|
17
|
+
// Create path
|
18
|
+
this._path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
19
|
+
this._path.setAttribute("fill", "none");
|
20
|
+
this._path.classList.add(styles["link"]);
|
21
|
+
svg.appendChild(this._path);
|
22
|
+
this._selectionPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
23
|
+
this._selectionPath.setAttribute("fill", "none");
|
24
|
+
this._selectionPath.classList.add(styles["selection-link"]);
|
25
|
+
svg.appendChild(this._selectionPath);
|
26
|
+
this._selectionPath.onmousedown = (evt) => this.onClick(evt);
|
27
|
+
if (this._portB) {
|
28
|
+
// Update
|
29
|
+
this.update();
|
30
|
+
}
|
31
|
+
this._onSelectionChangedObserver = this._graphCanvas.stateManager.onSelectionChangedObservable.add((options) => {
|
32
|
+
const { selection } = options || {};
|
33
|
+
if (selection === this) {
|
34
|
+
this._path.classList.add(styles["selected"]);
|
35
|
+
this._selectionPath.classList.add(styles["selected"]);
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
this._path.classList.remove(styles["selected"]);
|
39
|
+
this._selectionPath.classList.remove(styles["selected"]);
|
40
|
+
}
|
41
|
+
});
|
42
|
+
}
|
43
|
+
get isTargetCandidate() {
|
44
|
+
return this._isTargetCandidate;
|
45
|
+
}
|
46
|
+
set isTargetCandidate(value) {
|
47
|
+
if (this._isTargetCandidate === value) {
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
this._isTargetCandidate = value;
|
51
|
+
if (value) {
|
52
|
+
this._path.classList.add(styles["target-candidate"]);
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
this._path.classList.remove(styles["target-candidate"]);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
get isVisible() {
|
59
|
+
return this._isVisible;
|
60
|
+
}
|
61
|
+
set isVisible(value) {
|
62
|
+
this._isVisible = value;
|
63
|
+
if (!value) {
|
64
|
+
this._path.classList.add(commonStyles["hidden"]);
|
65
|
+
this._selectionPath.classList.add(commonStyles["hidden"]);
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
this._path.classList.remove(commonStyles["hidden"]);
|
69
|
+
this._selectionPath.classList.remove(commonStyles["hidden"]);
|
70
|
+
}
|
71
|
+
this.update();
|
72
|
+
}
|
73
|
+
get portA() {
|
74
|
+
return this._portA;
|
75
|
+
}
|
76
|
+
get portB() {
|
77
|
+
return this._portB;
|
78
|
+
}
|
79
|
+
get nodeA() {
|
80
|
+
return this._nodeA;
|
81
|
+
}
|
82
|
+
get nodeB() {
|
83
|
+
return this._nodeB;
|
84
|
+
}
|
85
|
+
intersectsWith(rect) {
|
86
|
+
const locatRect = this._path.getBoundingClientRect();
|
87
|
+
if (rect.left > locatRect.right || rect.right < locatRect.left || rect.top > locatRect.bottom || rect.bottom < locatRect.top) {
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
const svg = this._graphCanvas.svgCanvas;
|
91
|
+
const rootRect = svg.getBoundingClientRect();
|
92
|
+
const left = rect.x - rootRect.x;
|
93
|
+
const top = rect.y - rootRect.y;
|
94
|
+
const right = left + rect.width;
|
95
|
+
const bottom = top + rect.height;
|
96
|
+
const sampleRate = 10; // Checking 10 times on the path should be enough
|
97
|
+
for (let index = 0; index < 1; index += 1 / sampleRate) {
|
98
|
+
const point = this._path.getPointAtLength(index * this._path.getTotalLength());
|
99
|
+
if (left < point.x && right > point.x && top < point.y && bottom > point.y) {
|
100
|
+
return true;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
update(endX = 0, endY = 0, straight = false) {
|
106
|
+
const rectA = this._portA.element.getBoundingClientRect();
|
107
|
+
const rootRect = this._graphCanvas.canvasContainer.getBoundingClientRect();
|
108
|
+
const zoom = this._graphCanvas.zoom;
|
109
|
+
const xOffset = rootRect.left;
|
110
|
+
const yOffset = rootRect.top;
|
111
|
+
const startX = (rectA.left - xOffset + 0.5 * rectA.width) / zoom;
|
112
|
+
const startY = (rectA.top - yOffset + 0.5 * rectA.height) / zoom;
|
113
|
+
if (this._portB) {
|
114
|
+
const rectB = this._portB.element.getBoundingClientRect();
|
115
|
+
endX = (rectB.left - xOffset + 0.5 * rectB.width) / zoom;
|
116
|
+
endY = (rectB.top - yOffset + 0.5 * rectB.height) / zoom;
|
117
|
+
}
|
118
|
+
if (straight) {
|
119
|
+
this._path.setAttribute("d", `M${startX},${startY} L${endX},${endY}`);
|
120
|
+
this._path.setAttribute("stroke-dasharray", "10, 10");
|
121
|
+
this._path.setAttribute("stroke-linecap", "round");
|
122
|
+
}
|
123
|
+
else {
|
124
|
+
const deltaX = endX - startX;
|
125
|
+
const deltaY = endY - startY;
|
126
|
+
const tangentLength = Math.min(Math.sqrt(deltaX * deltaX + deltaY * deltaY) * 0.5, 300);
|
127
|
+
this._path.setAttribute("d", `M${startX},${startY} C${startX + tangentLength},${startY} ${endX - tangentLength},${endY} ${endX},${endY}`);
|
128
|
+
this._selectionPath.setAttribute("d", `M${startX},${startY} C${startX + tangentLength},${startY} ${endX - tangentLength},${endY} ${endX},${endY}`);
|
129
|
+
}
|
130
|
+
this._path.setAttribute("stroke", this._portA.element.style.backgroundColor);
|
131
|
+
}
|
132
|
+
onClick(evt) {
|
133
|
+
const stateManager = this._graphCanvas.stateManager;
|
134
|
+
if (evt.altKey) {
|
135
|
+
const nodeA = this._nodeA;
|
136
|
+
const pointA = this._portA.portData;
|
137
|
+
const nodeB = this._nodeB;
|
138
|
+
const pointB = this._portB.portData;
|
139
|
+
if (!stateManager.isElbowConnectionAllowed(this._portA, this._portB)) {
|
140
|
+
return;
|
141
|
+
}
|
142
|
+
// Create an elbow at the clicked location
|
143
|
+
stateManager.onNewNodeCreatedObservable.addOnce((newNode) => {
|
144
|
+
const newElbowBlock = newNode.content.data;
|
145
|
+
// Delete previous link
|
146
|
+
this.dispose();
|
147
|
+
// Connect to Elbow block
|
148
|
+
this._graphCanvas.connectNodes(nodeA, pointA, newNode, newNode.getPortDataForPortDataContent(newElbowBlock.input));
|
149
|
+
this._graphCanvas.connectNodes(newNode, newNode.getPortDataForPortDataContent(newElbowBlock.output), nodeB, pointB);
|
150
|
+
stateManager.onRebuildRequiredObservable.notifyObservers(true);
|
151
|
+
});
|
152
|
+
stateManager.onNewBlockRequiredObservable.notifyObservers({
|
153
|
+
type: "ElbowBlock",
|
154
|
+
targetX: evt.clientX,
|
155
|
+
targetY: evt.clientY,
|
156
|
+
needRepositioning: true,
|
157
|
+
});
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
stateManager.onSelectionChangedObservable.notifyObservers({ selection: this });
|
161
|
+
}
|
162
|
+
dispose(notify = true) {
|
163
|
+
this._graphCanvas.stateManager.onSelectionChangedObservable.remove(this._onSelectionChangedObserver);
|
164
|
+
if (this._path.parentElement) {
|
165
|
+
this._path.parentElement.removeChild(this._path);
|
166
|
+
}
|
167
|
+
if (this._selectionPath.parentElement) {
|
168
|
+
this._selectionPath.parentElement.removeChild(this._selectionPath);
|
169
|
+
}
|
170
|
+
if (this._nodeB) {
|
171
|
+
this._nodeA.links.splice(this._nodeA.links.indexOf(this), 1);
|
172
|
+
this._nodeB.links.splice(this._nodeB.links.indexOf(this), 1);
|
173
|
+
this._graphCanvas.links.splice(this._graphCanvas.links.indexOf(this), 1);
|
174
|
+
this._portA.portData.disconnectFrom(this._portB.portData);
|
175
|
+
RefreshNode(this._nodeB);
|
176
|
+
}
|
177
|
+
if (notify) {
|
178
|
+
this.onDisposedObservable.notifyObservers(this);
|
179
|
+
this.onDisposedObservable.clear();
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
183
|
//# sourceMappingURL=nodeLink.js.map
|
@@ -1,35 +1,35 @@
|
|
1
|
-
import type { Nullable } from "@babylonjs/core/types.js";
|
2
|
-
import type { Observer } from "@babylonjs/core/Misc/observable.js";
|
3
|
-
import type { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
|
4
|
-
import type { GraphNode } from "./graphNode";
|
5
|
-
import type { StateManager } from "./stateManager";
|
6
|
-
import type { ISelectionChangedOptions } from "./interfaces/selectionChangedOptions";
|
7
|
-
import type { FrameNodePort } from "./frameNodePort";
|
8
|
-
import type { IDisplayManager } from "./interfaces/displayManager";
|
9
|
-
import type { IPortData } from "./interfaces/portData";
|
10
|
-
export declare class NodePort {
|
11
|
-
portData: IPortData;
|
12
|
-
node: GraphNode;
|
13
|
-
protected _element: HTMLDivElement;
|
14
|
-
protected _img: HTMLImageElement;
|
15
|
-
protected _stateManager: StateManager;
|
16
|
-
protected _portLabelElement: Element;
|
17
|
-
protected _onCandidateLinkMovedObserver: Nullable<Observer<Nullable<Vector2>>>;
|
18
|
-
protected _onSelectionChangedObserver: Nullable<Observer<Nullable<ISelectionChangedOptions>>>;
|
19
|
-
protected _exposedOnFrame: boolean;
|
20
|
-
delegatedPort: Nullable<FrameNodePort>;
|
21
|
-
get element(): HTMLDivElement;
|
22
|
-
get portName(): string;
|
23
|
-
set portName(newName: string);
|
24
|
-
get disabled(): boolean;
|
25
|
-
hasLabel(): boolean;
|
26
|
-
get exposedOnFrame(): boolean;
|
27
|
-
set exposedOnFrame(value: boolean);
|
28
|
-
get exposedPortPosition(): number;
|
29
|
-
set exposedPortPosition(value: number);
|
30
|
-
private _isConnectedToNodeOutsideOfFrame;
|
31
|
-
refresh(): void;
|
32
|
-
constructor(portContainer: HTMLElement, portData: IPortData, node: GraphNode, stateManager: StateManager);
|
33
|
-
dispose(): void;
|
34
|
-
static CreatePortElement(portData: IPortData, node: GraphNode, root: HTMLElement, displayManager: Nullable<IDisplayManager>, stateManager: StateManager): NodePort;
|
35
|
-
}
|
1
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
2
|
+
import type { Observer } from "@babylonjs/core/Misc/observable.js";
|
3
|
+
import type { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
|
4
|
+
import type { GraphNode } from "./graphNode";
|
5
|
+
import type { StateManager } from "./stateManager";
|
6
|
+
import type { ISelectionChangedOptions } from "./interfaces/selectionChangedOptions";
|
7
|
+
import type { FrameNodePort } from "./frameNodePort";
|
8
|
+
import type { IDisplayManager } from "./interfaces/displayManager";
|
9
|
+
import type { IPortData } from "./interfaces/portData";
|
10
|
+
export declare class NodePort {
|
11
|
+
portData: IPortData;
|
12
|
+
node: GraphNode;
|
13
|
+
protected _element: HTMLDivElement;
|
14
|
+
protected _img: HTMLImageElement;
|
15
|
+
protected _stateManager: StateManager;
|
16
|
+
protected _portLabelElement: Element;
|
17
|
+
protected _onCandidateLinkMovedObserver: Nullable<Observer<Nullable<Vector2>>>;
|
18
|
+
protected _onSelectionChangedObserver: Nullable<Observer<Nullable<ISelectionChangedOptions>>>;
|
19
|
+
protected _exposedOnFrame: boolean;
|
20
|
+
delegatedPort: Nullable<FrameNodePort>;
|
21
|
+
get element(): HTMLDivElement;
|
22
|
+
get portName(): string;
|
23
|
+
set portName(newName: string);
|
24
|
+
get disabled(): boolean;
|
25
|
+
hasLabel(): boolean;
|
26
|
+
get exposedOnFrame(): boolean;
|
27
|
+
set exposedOnFrame(value: boolean);
|
28
|
+
get exposedPortPosition(): number;
|
29
|
+
set exposedPortPosition(value: number);
|
30
|
+
private _isConnectedToNodeOutsideOfFrame;
|
31
|
+
refresh(): void;
|
32
|
+
constructor(portContainer: HTMLElement, portData: IPortData, node: GraphNode, stateManager: StateManager);
|
33
|
+
dispose(): void;
|
34
|
+
static CreatePortElement(portData: IPortData, node: GraphNode, root: HTMLElement, displayManager: Nullable<IDisplayManager>, stateManager: StateManager): NodePort;
|
35
|
+
}
|