orcasvn-react-diagrams 0.1.28 → 0.1.29
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/dist/cjs/index.js +412 -1530
- package/dist/cjs/types/components/paper.d.ts +6 -0
- package/dist/cjs/types/models/IEditorContext.d.ts +5 -0
- package/dist/cjs/types/models/IElementProps.d.ts +4 -4
- package/dist/cjs/types/models/IText.d.ts +1 -0
- package/dist/cjs/types/models/ITextProps.d.ts +1 -0
- package/dist/cjs/types/models/implementations/EditorContext.d.ts +5 -0
- package/dist/cjs/types/models/implementations/Text.d.ts +2 -1
- package/dist/esm/index.js +267 -1385
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/paper.d.ts +6 -0
- package/dist/esm/types/models/IEditorContext.d.ts +5 -0
- package/dist/esm/types/models/IElementProps.d.ts +4 -4
- package/dist/esm/types/models/IText.d.ts +1 -0
- package/dist/esm/types/models/ITextProps.d.ts +1 -0
- package/dist/esm/types/models/implementations/EditorContext.d.ts +5 -0
- package/dist/esm/types/models/implementations/Text.d.ts +2 -1
- package/dist/index.d.ts +18 -5
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var React
|
|
5
|
+
var React = require('react');
|
|
6
6
|
var require$$0 = require('react-dom');
|
|
7
7
|
|
|
8
8
|
exports.PositioningAnchor = void 0;
|
|
@@ -36,8 +36,6 @@ exports.TextAlign = void 0;
|
|
|
36
36
|
TextAlign[TextAlign["center"] = 2] = "center";
|
|
37
37
|
})(exports.TextAlign || (exports.TextAlign = {}));
|
|
38
38
|
|
|
39
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
40
|
-
|
|
41
39
|
function getDefaultExportFromCjs (x) {
|
|
42
40
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
43
41
|
}
|
|
@@ -622,7 +620,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
622
620
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
623
621
|
};
|
|
624
622
|
|
|
625
|
-
var ShapeWrapper = React
|
|
623
|
+
var ShapeWrapper = React.forwardRef(function (shapeProps, ref) {
|
|
626
624
|
//if direction is provided, rotation is based on direction
|
|
627
625
|
var rotation = shapeProps.rotation || 0;
|
|
628
626
|
if (shapeProps.direction) {
|
|
@@ -652,7 +650,7 @@ var ShapeWrapper = React$1.forwardRef(function (shapeProps, ref) {
|
|
|
652
650
|
position.x = position.x - shapeProps.width / 2;
|
|
653
651
|
position.y = position.y - shapeProps.height / 2;
|
|
654
652
|
}
|
|
655
|
-
var objectOfAllEventAttributes = React
|
|
653
|
+
var objectOfAllEventAttributes = React.useMemo(function () {
|
|
656
654
|
var arrayOfAllEventAttributes = Object.entries(shapeProps).filter(function (_a) {
|
|
657
655
|
var k = _a[0]; _a[1];
|
|
658
656
|
return k.startsWith('on');
|
|
@@ -662,12 +660,12 @@ var ShapeWrapper = React$1.forwardRef(function (shapeProps, ref) {
|
|
|
662
660
|
var viewboxWidth = shapeProps.width > shapeProps.height ? 100 : shapeProps.width / shapeProps.height * 100;
|
|
663
661
|
var viewBoxHeight = shapeProps.height > shapeProps.width ? 100 : shapeProps.height / shapeProps.width * 100;
|
|
664
662
|
var viewBox = shapeProps.viewBox || "0 0 ".concat(viewboxWidth, " ").concat(viewBoxHeight);
|
|
665
|
-
return (React
|
|
666
|
-
React
|
|
663
|
+
return (React.createElement("g", { transform: "rotate(".concat(rotation, ")"), style: { transformOrigin: transformOrigin, transformBox: "content-box" } },
|
|
664
|
+
React.createElement("svg", __assign({ ref: ref, style: { overflow: "visible" }, x: position.x, y: position.y, width: shapeProps.width, height: shapeProps.height, className: shapeProps.cssClass, viewBox: viewBox }, objectOfAllEventAttributes), shapeProps.children)));
|
|
667
665
|
});
|
|
668
666
|
|
|
669
|
-
var CustomShape = React
|
|
670
|
-
return (React
|
|
667
|
+
var CustomShape = React.forwardRef(function (props, ref) {
|
|
668
|
+
return (React.createElement(ShapeWrapper, __assign({}, props, { ref: ref }), props.children));
|
|
671
669
|
});
|
|
672
670
|
|
|
673
671
|
var Port$1 = /** @class */ (function () {
|
|
@@ -688,8 +686,8 @@ var Port$1 = /** @class */ (function () {
|
|
|
688
686
|
this.renderShape = shapeRenderer.shape;
|
|
689
687
|
}
|
|
690
688
|
else if (shapeRenderer && shapeRenderer.customShapeWithJSX) {
|
|
691
|
-
this.renderShape = React
|
|
692
|
-
return (React
|
|
689
|
+
this.renderShape = React.forwardRef(function (props, ref) {
|
|
690
|
+
return (React.createElement(CustomShape, { ref: ref, x: props.x, y: props.y, width: props.width, height: props.height, rotation: props.rotation, positioningAnchor: shapeRenderer.positioningAnchor, onClick: function (e) { var _a; return (_a = props.onSelected) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseDown: function (e) { var _a; return (_a = props.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseUp: function (e) { var _a; return (_a = props.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); } }, shapeRenderer.customShapeWithJSX));
|
|
693
691
|
});
|
|
694
692
|
}
|
|
695
693
|
}
|
|
@@ -742,7 +740,7 @@ var ElementLink$1 = /** @class */ (function () {
|
|
|
742
740
|
}());
|
|
743
741
|
|
|
744
742
|
var Text$2 = /** @class */ (function () {
|
|
745
|
-
function Text(content, width, height, x, y, align, fontSize, border, style) {
|
|
743
|
+
function Text(content, width, height, editable, x, y, align, fontSize, border, style) {
|
|
746
744
|
this._id = generateUniqueId();
|
|
747
745
|
this.content = content;
|
|
748
746
|
this.align = align;
|
|
@@ -750,6 +748,7 @@ var Text$2 = /** @class */ (function () {
|
|
|
750
748
|
this.border = border;
|
|
751
749
|
this.size = { width: width, height: height };
|
|
752
750
|
this.style = style;
|
|
751
|
+
this.editable = editable;
|
|
753
752
|
if (x && y) {
|
|
754
753
|
this.position = { x: x, y: y };
|
|
755
754
|
}
|
|
@@ -771,12 +770,17 @@ var EVENT_PAPER_CLICKED = 'paperClicked';
|
|
|
771
770
|
var EVENT_PAPER_MOUSE_MOVED = 'paperMouseMoved';
|
|
772
771
|
var EVENT_PAPER_MOUSE_DOWN = 'paperMouseDown';
|
|
773
772
|
var EVENT_PAPER_MOUSE_UP = 'paperMouseUp';
|
|
773
|
+
var EVENT_PORT_MOUSE_DOWN = 'portMouseDown';
|
|
774
|
+
var EVENT_PORT_MOUSE_UP = 'portMouseUp';
|
|
774
775
|
var EVENT_PORT_MOVED = 'portMoved';
|
|
775
776
|
var EVENT_PORT_SELECTED = 'portSelected';
|
|
776
777
|
var EVENT_ELEMENT_CONTEXT_MENU = 'elementContextMenu';
|
|
777
778
|
var EVENT_ELEMENT_MOVED = 'elementMoved';
|
|
778
779
|
var EVENT_ELEMENT_RESIZED = 'elementResized';
|
|
779
780
|
var EVENT_ELEMENT_SELECTED = 'elementSelected';
|
|
781
|
+
var EVENT_ELEMENT_MOUSE_MOVE = 'elementMouseMove';
|
|
782
|
+
var EVENT_ELEMENT_MOUSE_LEAVE = 'elementMouseLeave';
|
|
783
|
+
var EVENT_ELEMENT_MOUSE_UP = 'elementMouseUp';
|
|
780
784
|
var EVENT_LINK_SELECTED = 'linkSelected';
|
|
781
785
|
var EVENT_TEXT_SELECTED = 'textSelected';
|
|
782
786
|
var EditorContext = /** @class */ (function () {
|
|
@@ -885,6 +889,20 @@ var EditorContext = /** @class */ (function () {
|
|
|
885
889
|
EditorContext.prototype.onPaperMouseUpHandler = function (position) {
|
|
886
890
|
this._eventEmitter.emit(EVENT_PAPER_MOUSE_UP, position);
|
|
887
891
|
};
|
|
892
|
+
EditorContext.prototype.onPortMouseDown = function (callback) {
|
|
893
|
+
return this.addEventListener(EVENT_PORT_MOUSE_DOWN, callback);
|
|
894
|
+
};
|
|
895
|
+
/** @internal */
|
|
896
|
+
EditorContext.prototype.onPortMouseDownHandler = function (port, element) {
|
|
897
|
+
this._eventEmitter.emit(EVENT_PORT_MOUSE_DOWN, port, element);
|
|
898
|
+
};
|
|
899
|
+
EditorContext.prototype.onPortMouseUp = function (callback) {
|
|
900
|
+
return this.addEventListener(EVENT_PORT_MOUSE_UP, callback);
|
|
901
|
+
};
|
|
902
|
+
/** @internal */
|
|
903
|
+
EditorContext.prototype.onPortMouseUpHandler = function (port, element) {
|
|
904
|
+
this._eventEmitter.emit(EVENT_PORT_MOUSE_UP, port, element);
|
|
905
|
+
};
|
|
888
906
|
EditorContext.prototype.onPortMoved = function (callback) {
|
|
889
907
|
return this.addEventListener(EVENT_PORT_MOVED, callback);
|
|
890
908
|
};
|
|
@@ -927,6 +945,27 @@ var EditorContext = /** @class */ (function () {
|
|
|
927
945
|
EditorContext.prototype.onElementSelectedHandler = function (element) {
|
|
928
946
|
this._eventEmitter.emit(EVENT_ELEMENT_SELECTED, element);
|
|
929
947
|
};
|
|
948
|
+
EditorContext.prototype.onElementMouseMove = function (callback) {
|
|
949
|
+
return this.addEventListener(EVENT_ELEMENT_MOUSE_MOVE, callback);
|
|
950
|
+
};
|
|
951
|
+
/** @internal */
|
|
952
|
+
EditorContext.prototype.onElementMouseMoveHandler = function (ev, element) {
|
|
953
|
+
this._eventEmitter.emit(EVENT_ELEMENT_MOUSE_MOVE, ev, element);
|
|
954
|
+
};
|
|
955
|
+
EditorContext.prototype.onElementMouseLeave = function (callback) {
|
|
956
|
+
return this.addEventListener(EVENT_ELEMENT_MOUSE_LEAVE, callback);
|
|
957
|
+
};
|
|
958
|
+
/** @internal */
|
|
959
|
+
EditorContext.prototype.onElementMouseLeaveHandler = function (ev, element) {
|
|
960
|
+
this._eventEmitter.emit(EVENT_ELEMENT_MOUSE_LEAVE, ev, element);
|
|
961
|
+
};
|
|
962
|
+
EditorContext.prototype.onElementMouseUp = function (callback) {
|
|
963
|
+
return this.addEventListener(EVENT_ELEMENT_MOUSE_UP, callback);
|
|
964
|
+
};
|
|
965
|
+
/** @internal */
|
|
966
|
+
EditorContext.prototype.onElementMouseUpHandler = function (ev, element) {
|
|
967
|
+
this._eventEmitter.emit(EVENT_ELEMENT_MOUSE_UP, ev, element);
|
|
968
|
+
};
|
|
930
969
|
EditorContext.prototype.onLinkSelected = function (callback) {
|
|
931
970
|
return this.addEventListener(EVENT_LINK_SELECTED, callback);
|
|
932
971
|
};
|
|
@@ -956,7 +995,7 @@ var EditorContext = /** @class */ (function () {
|
|
|
956
995
|
return EditorContext;
|
|
957
996
|
}());
|
|
958
997
|
|
|
959
|
-
var Circle = React
|
|
998
|
+
var Circle = React.forwardRef(function (props, ref) {
|
|
960
999
|
var s = { height: 100, width: 100 };
|
|
961
1000
|
if (props.r) {
|
|
962
1001
|
s.height = props.r * 2;
|
|
@@ -969,11 +1008,11 @@ var Circle = React$1.forwardRef(function (props, ref) {
|
|
|
969
1008
|
s.height = props.height;
|
|
970
1009
|
s.width = props.width;
|
|
971
1010
|
}
|
|
972
|
-
return (React
|
|
973
|
-
React
|
|
1011
|
+
return (React.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height, ref: ref }),
|
|
1012
|
+
React.createElement("circle", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", cx: 50, cy: 50, r: 50, fill: props.fill || 'transparent', stroke: props.stroke || "none", strokeWidth: props.strokeWidth })));
|
|
974
1013
|
});
|
|
975
1014
|
|
|
976
|
-
var Crescent = React
|
|
1015
|
+
var Crescent = React.forwardRef(function (props, ref) {
|
|
977
1016
|
var s = { height: 100, width: 100 };
|
|
978
1017
|
if (props.r) {
|
|
979
1018
|
s.height = props.r * 2;
|
|
@@ -987,12 +1026,12 @@ var Crescent = React$1.forwardRef(function (props, ref) {
|
|
|
987
1026
|
s.width = props.width;
|
|
988
1027
|
}
|
|
989
1028
|
var sw = props.stroke ? (props.strokeWidth || 1) : 0;
|
|
990
|
-
return (React
|
|
991
|
-
React
|
|
992
|
-
React
|
|
1029
|
+
return (React.createElement(ShapeWrapper, __assign({ ref: ref, viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height }),
|
|
1030
|
+
React.createElement("rect", { width: 100, height: 100, stroke: "transparent", fill: 'transparent' }),
|
|
1031
|
+
React.createElement("path", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", d: "M 0 75 A 50 50 0 1 1 100 75 Z", fill: props.fill || 'none', stroke: props.stroke || 'none', strokeWidth: sw })));
|
|
993
1032
|
});
|
|
994
1033
|
|
|
995
|
-
var Rectangle = React
|
|
1034
|
+
var Rectangle = React.forwardRef(function (props, ref) {
|
|
996
1035
|
var scaledWidth = props.width;
|
|
997
1036
|
var scaledHeight = props.height;
|
|
998
1037
|
if (props.width > 100 || props.height > 100) {
|
|
@@ -1008,11 +1047,11 @@ var Rectangle = React$1.forwardRef(function (props, ref) {
|
|
|
1008
1047
|
}
|
|
1009
1048
|
}
|
|
1010
1049
|
var sw = props.stroke ? (props.strokeWidth || 1) : 0;
|
|
1011
|
-
return (React
|
|
1012
|
-
React
|
|
1050
|
+
return (React.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
|
|
1051
|
+
React.createElement("rect", { className: "rect-border ".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", width: scaledWidth, height: scaledHeight, fill: props.fill || "transparent", stroke: props.stroke || "none", strokeWidth: sw })));
|
|
1013
1052
|
});
|
|
1014
1053
|
|
|
1015
|
-
var RectangularFrame = React
|
|
1054
|
+
var RectangularFrame = React.forwardRef(function (props, ref) {
|
|
1016
1055
|
var scaledWidth = props.width;
|
|
1017
1056
|
var scaledHeight = props.height;
|
|
1018
1057
|
if (props.width > 100 || props.height > 100) {
|
|
@@ -1032,10 +1071,10 @@ var RectangularFrame = React$1.forwardRef(function (props, ref) {
|
|
|
1032
1071
|
var fw = props.frameColor ? (props.frameWidth || 1) : 0;
|
|
1033
1072
|
var scaledFw = scaledWidth / props.width * fw;
|
|
1034
1073
|
var sw = props.stroke ? (props.strokeWidth || 1) : 0;
|
|
1035
|
-
return (React
|
|
1036
|
-
React
|
|
1037
|
-
React
|
|
1038
|
-
React
|
|
1074
|
+
return (React.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
|
|
1075
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: "rectangular-frame-outer-border ".concat(props.portMoveableAreaCssClass), x: vbX, y: vbY, width: scaledWidth, height: scaledHeight, fill: "none", stroke: props.stroke || "none", strokeWidth: sw }),
|
|
1076
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-hallway', x: vbX + scaledFw / 2, y: vbY + scaledFw / 2, width: scaledWidth - scaledFw, height: scaledHeight - scaledFw, stroke: props.frameColor || "none", strokeWidth: fw, fill: props.fill || "transparent" }),
|
|
1077
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-inner-border', x: vbX + scaledFw, y: vbY + scaledFw, width: scaledWidth - scaledFw * 2, height: scaledHeight - scaledFw * 2, stroke: props.stroke || "none", strokeWidth: sw, fill: props.fill || "transparent" })));
|
|
1039
1078
|
});
|
|
1040
1079
|
|
|
1041
1080
|
var createRoot;
|
|
@@ -1117,17 +1156,17 @@ var PORT_DEFAULT_SIZE = 20;
|
|
|
1117
1156
|
var SelectionFrame = function (props) {
|
|
1118
1157
|
var _a;
|
|
1119
1158
|
var bbox = (_a = props.targetSVGElement) === null || _a === void 0 ? void 0 : _a.getBBox();
|
|
1120
|
-
var _b = React
|
|
1121
|
-
var _c = React
|
|
1159
|
+
var _b = React.useState(props.width || (bbox === null || bbox === void 0 ? void 0 : bbox.width) || MIN_ELEMENT_SIZE), width = _b[0], setWidth = _b[1];
|
|
1160
|
+
var _c = React.useState(props.height || (bbox === null || bbox === void 0 ? void 0 : bbox.height) || MIN_ELEMENT_SIZE), height = _c[0], setHeight = _c[1];
|
|
1122
1161
|
var x = 0;
|
|
1123
1162
|
var y = 0;
|
|
1124
1163
|
var framePadding = props.framePadding || 0;
|
|
1125
1164
|
var r = 5;
|
|
1126
|
-
var _d = React
|
|
1127
|
-
var _e = React
|
|
1128
|
-
var _f = React
|
|
1129
|
-
var _g = React
|
|
1130
|
-
var _h = React
|
|
1165
|
+
var _d = React.useState(false), draggingRect = _d[0], setDraggingRect = _d[1];
|
|
1166
|
+
var _e = React.useState(false), draggingCircle = _e[0], setDraggingCircle = _e[1];
|
|
1167
|
+
var _f = React.useState(0), startX = _f[0], setStartX = _f[1];
|
|
1168
|
+
var _g = React.useState(0), startY = _g[0], setStartY = _g[1];
|
|
1169
|
+
var _h = React.useState(0), lastMoveTime = _h[0], setLastMoveTime = _h[1];
|
|
1131
1170
|
var addRectHandleMouseDown = function (event) {
|
|
1132
1171
|
event.stopPropagation();
|
|
1133
1172
|
if (!draggingCircle) {
|
|
@@ -1137,7 +1176,7 @@ var SelectionFrame = function (props) {
|
|
|
1137
1176
|
setStartY(event.clientY);
|
|
1138
1177
|
}
|
|
1139
1178
|
};
|
|
1140
|
-
var rectHandleMouseMove = React
|
|
1179
|
+
var rectHandleMouseMove = React.useCallback(function (event) {
|
|
1141
1180
|
var mouseEvent = event;
|
|
1142
1181
|
if (draggingRect) {
|
|
1143
1182
|
var offsetX = mouseEvent.clientX - startX;
|
|
@@ -1160,7 +1199,7 @@ var SelectionFrame = function (props) {
|
|
|
1160
1199
|
}
|
|
1161
1200
|
}
|
|
1162
1201
|
}, [draggingRect, props.onMove, props.movingRate, startX, startY, lastMoveTime]);
|
|
1163
|
-
React
|
|
1202
|
+
React.useEffect(function () {
|
|
1164
1203
|
var addRectHandleMouseUp = function () {
|
|
1165
1204
|
//mouse up
|
|
1166
1205
|
setDraggingRect(false);
|
|
@@ -1185,7 +1224,7 @@ var SelectionFrame = function (props) {
|
|
|
1185
1224
|
setDraggingCircle(true);
|
|
1186
1225
|
}
|
|
1187
1226
|
};
|
|
1188
|
-
React
|
|
1227
|
+
React.useEffect(function () {
|
|
1189
1228
|
var circleHandleMouseMove = function (event) {
|
|
1190
1229
|
var mouseEvent = event;
|
|
1191
1230
|
if (draggingCircle) {
|
|
@@ -1241,15 +1280,15 @@ var SelectionFrame = function (props) {
|
|
|
1241
1280
|
leftX -= rectangleSize / 2;
|
|
1242
1281
|
topY -= rectangleSize / 2;
|
|
1243
1282
|
}
|
|
1244
|
-
return (React
|
|
1245
|
-
props.dragDropHandlerElement && React
|
|
1246
|
-
React
|
|
1283
|
+
return (React.createElement(React.Fragment, null,
|
|
1284
|
+
props.dragDropHandlerElement && React.createElement(props.dragDropHandlerElement, { dragging: draggingRect, onMouseDown: addRectHandleMouseDown }),
|
|
1285
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", x: leftX, y: topY, width: width, height: height, fill: 'none', stroke: 'blue', strokeWidth: props.strokeWidth || 5, cursor: draggingRect ? 'grabbing' : 'grab', onMouseDown: addRectHandleMouseDown }),
|
|
1247
1286
|
props.resizability.enabled ?
|
|
1248
|
-
(React
|
|
1287
|
+
(React.createElement("circle", { cursor: 'se-resize', cx: leftX + width, cy: topY + height, r: r, fill: 'blue', stroke: 'blue', onMouseDown: circleHandleMouseDown })) : null));
|
|
1249
1288
|
};
|
|
1250
1289
|
|
|
1251
1290
|
var useSelectionFrame = function (props) {
|
|
1252
|
-
React
|
|
1291
|
+
React.useEffect(function () {
|
|
1253
1292
|
if (props.targetSVGElement && props.container) {
|
|
1254
1293
|
//render SelectionFrame component to the parent element of the targetSVGElement
|
|
1255
1294
|
if (props.container) {
|
|
@@ -1258,7 +1297,7 @@ var useSelectionFrame = function (props) {
|
|
|
1258
1297
|
svg_1.style.outline = 'none';
|
|
1259
1298
|
props.targetSVGElement.appendChild(svg_1);
|
|
1260
1299
|
var root_1 = createRoot(svg_1);
|
|
1261
|
-
root_1.render(React
|
|
1300
|
+
root_1.render(React.createElement(SelectionFrame, __assign({}, props, { container: props.container })));
|
|
1262
1301
|
return function () {
|
|
1263
1302
|
root_1.unmount();
|
|
1264
1303
|
if (props.targetSVGElement) {
|
|
@@ -1475,7 +1514,7 @@ var onTextSelected = function (callback) {
|
|
|
1475
1514
|
off: off
|
|
1476
1515
|
};
|
|
1477
1516
|
};
|
|
1478
|
-
var paperEventEmitterContext = React
|
|
1517
|
+
var paperEventEmitterContext = React.createContext({
|
|
1479
1518
|
emitter: eventEmitter,
|
|
1480
1519
|
emitPaperClicked: emitPaperClicked,
|
|
1481
1520
|
onPaperClicked: onPaperClicked,
|
|
@@ -1513,13 +1552,13 @@ var paperEventEmitterContext = React$1.createContext({
|
|
|
1513
1552
|
onCommandRenderPort: onCommandRenderPort,
|
|
1514
1553
|
});
|
|
1515
1554
|
|
|
1516
|
-
var Text = React
|
|
1517
|
-
var id = _a.id, content = _a.content, x = _a.x, y = _a.y, width = _a.width, height = _a.height, _b = _a.align, align = _b === void 0 ? exports.TextAlign.left : _b, fontSizeProp = _a.fontSize, border = _a.border, container = _a.container, onSelected = _a.onSelected, onMoved = _a.onMoved, onResized = _a.onResized, onContentChanged = _a.onContentChanged;
|
|
1518
|
-
var _c = React
|
|
1519
|
-
var _d = React
|
|
1520
|
-
var svgRef = React
|
|
1521
|
-
var _e = React
|
|
1522
|
-
React
|
|
1555
|
+
var Text = React.forwardRef(function (_a, ref) {
|
|
1556
|
+
var id = _a.id, content = _a.content, x = _a.x, y = _a.y, width = _a.width, height = _a.height, editable = _a.editable, _b = _a.align, align = _b === void 0 ? exports.TextAlign.left : _b, fontSizeProp = _a.fontSize, border = _a.border, container = _a.container, onSelected = _a.onSelected, onMoved = _a.onMoved, onResized = _a.onResized, onContentChanged = _a.onContentChanged;
|
|
1557
|
+
var _c = React.useState(false), isSelected = _c[0], setIsSelected = _c[1];
|
|
1558
|
+
var _d = React.useState(false), isEditing = _d[0], setIsEditing = _d[1];
|
|
1559
|
+
var svgRef = React.useRef();
|
|
1560
|
+
var _e = React.useContext(paperEventEmitterContext), onPaperClicked = _e.onPaperClicked, emitTextSelected = _e.emitTextSelected, onPortSelected = _e.onPortSelected, onElementSelected = _e.onElementSelected, onTextSelected = _e.onTextSelected;
|
|
1561
|
+
React.useEffect(function () {
|
|
1523
1562
|
var paperClickListener = onPaperClicked(function (ev) {
|
|
1524
1563
|
var _a;
|
|
1525
1564
|
var textareaELe = (_a = svgRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('textarea');
|
|
@@ -1563,13 +1602,16 @@ var Text = React$1.forwardRef(function (_a, ref) {
|
|
|
1563
1602
|
size: {
|
|
1564
1603
|
width: width,
|
|
1565
1604
|
height: height,
|
|
1566
|
-
}
|
|
1605
|
+
},
|
|
1606
|
+
editable: editable
|
|
1567
1607
|
};
|
|
1568
1608
|
setIsSelected(true);
|
|
1569
1609
|
onSelected && onSelected(text);
|
|
1570
1610
|
emitTextSelected(text);
|
|
1571
1611
|
};
|
|
1572
1612
|
var handleChangeText = function (ev) {
|
|
1613
|
+
if (!editable)
|
|
1614
|
+
return;
|
|
1573
1615
|
onContentChanged === null || onContentChanged === void 0 ? void 0 : onContentChanged(ev, ev.target.value);
|
|
1574
1616
|
};
|
|
1575
1617
|
useSelectionFrame({
|
|
@@ -1584,7 +1626,7 @@ var Text = React$1.forwardRef(function (_a, ref) {
|
|
|
1584
1626
|
strokeWidth: 3,
|
|
1585
1627
|
movingOffsetThreshold: TEXT_MOVING_OFFSET_THRESHOLD,
|
|
1586
1628
|
});
|
|
1587
|
-
var textAlign = React
|
|
1629
|
+
var textAlign = React.useMemo(function () {
|
|
1588
1630
|
switch (align) {
|
|
1589
1631
|
case exports.TextAlign.left:
|
|
1590
1632
|
return 'left';
|
|
@@ -1598,7 +1640,7 @@ var Text = React$1.forwardRef(function (_a, ref) {
|
|
|
1598
1640
|
}, [align]);
|
|
1599
1641
|
var fontSize = fontSizeProp || TEXT_FONT_SIZE;
|
|
1600
1642
|
var borderStyle = border || 'none';
|
|
1601
|
-
return (React
|
|
1643
|
+
return (React.createElement("svg", { style: { overflow: "visible" }, x: x, y: y, ref: function (node) {
|
|
1602
1644
|
svgRef.current = node;
|
|
1603
1645
|
if (typeof ref === 'function') {
|
|
1604
1646
|
ref(node);
|
|
@@ -1607,13 +1649,13 @@ var Text = React$1.forwardRef(function (_a, ref) {
|
|
|
1607
1649
|
ref.current = node;
|
|
1608
1650
|
}
|
|
1609
1651
|
}, onClick: handleClick },
|
|
1610
|
-
React
|
|
1652
|
+
React.createElement("foreignObject", { width: width, height: height, style: {
|
|
1611
1653
|
overflow: 'visible',
|
|
1612
1654
|
userSelect: 'none',
|
|
1613
1655
|
WebkitUserSelect: 'none',
|
|
1614
1656
|
msUserSelect: 'none'
|
|
1615
1657
|
} },
|
|
1616
|
-
React
|
|
1658
|
+
React.createElement("div", { style: {
|
|
1617
1659
|
width: '100%',
|
|
1618
1660
|
height: '100%',
|
|
1619
1661
|
borderWidth: '1px',
|
|
@@ -1622,7 +1664,7 @@ var Text = React$1.forwardRef(function (_a, ref) {
|
|
|
1622
1664
|
// whiteSpace: 'pre-wrap',
|
|
1623
1665
|
boxSizing: 'border-box',
|
|
1624
1666
|
} },
|
|
1625
|
-
React
|
|
1667
|
+
React.createElement("textarea", { style: {
|
|
1626
1668
|
fontFamily: 'initial',
|
|
1627
1669
|
display: 'inline-block',
|
|
1628
1670
|
width: '100%',
|
|
@@ -1635,19 +1677,19 @@ var Text = React$1.forwardRef(function (_a, ref) {
|
|
|
1635
1677
|
textAlign: textAlign,
|
|
1636
1678
|
fontSize: fontSize,
|
|
1637
1679
|
}, readOnly: !isEditing, onDoubleClick: function () {
|
|
1638
|
-
if (
|
|
1680
|
+
if (editable) {
|
|
1639
1681
|
setIsEditing(true);
|
|
1640
1682
|
}
|
|
1641
1683
|
}, value: content, onChange: handleChangeText })))));
|
|
1642
1684
|
});
|
|
1643
|
-
var Text$1 = React
|
|
1685
|
+
var Text$1 = React.memo(Text);
|
|
1644
1686
|
|
|
1645
|
-
var Port1 = React
|
|
1687
|
+
var Port1 = React.forwardRef(function (props, ref) {
|
|
1646
1688
|
var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, container = props.container, label = props.label, onPortLabelMoved = props.onPortLabelMoved, onPortLabelResized = props.onPortLabelResized, onPortLabelContentChanged = props.onPortLabelContentChanged, onSelected = props.onSelected, onMouseDown = props.onMouseDown, onMouseUp = props.onMouseUp, onMouseEnter = props.onMouseEnter, onMouseLeave = props.onMouseLeave, onMouseMove = props.onMouseMove, calculateRotationAngle = props.calculateRotationAngle,
|
|
1647
1689
|
// onManuallyTriggerRenderHandler,
|
|
1648
1690
|
renderShape = props.renderShape;
|
|
1649
|
-
var _a = React
|
|
1650
|
-
var textRef = React
|
|
1691
|
+
var _a = React.useState(false); _a[0]; _a[1];
|
|
1692
|
+
var textRef = React.useRef(null);
|
|
1651
1693
|
// useEffect(() => {
|
|
1652
1694
|
// const off = onManuallyTriggerRenderHandler?.(() => {
|
|
1653
1695
|
// setUpdated(prev => !prev);
|
|
@@ -1656,33 +1698,33 @@ var Port1 = React$1.forwardRef(function (props, ref) {
|
|
|
1656
1698
|
// off?.();
|
|
1657
1699
|
// }
|
|
1658
1700
|
// }, [])
|
|
1659
|
-
var rotationAngle = React
|
|
1701
|
+
var rotationAngle = React.useMemo(function () {
|
|
1660
1702
|
if (!calculateRotationAngle)
|
|
1661
1703
|
return 0;
|
|
1662
1704
|
return calculateRotationAngle(x, y);
|
|
1663
1705
|
}, [calculateRotationAngle, x, y]);
|
|
1664
|
-
React
|
|
1706
|
+
React.useEffect(function () {
|
|
1665
1707
|
console.info('Testing - rendering Port ' + id);
|
|
1666
1708
|
});
|
|
1667
1709
|
var renderLabel = function (label) {
|
|
1668
1710
|
var content = label.content, size = label.size;
|
|
1669
1711
|
var position = label.position || PORT_LABEL_POSITION;
|
|
1670
|
-
return React
|
|
1712
|
+
return React.createElement(Text$1, { id: label.id, ref: textRef, x: x + position.x, y: y + position.y, width: size.width, height: size.height, editable: label.editable, content: content, fontSize: label.fontSize, border: label.border, container: container, onMoved: function (x, y) { return onPortLabelMoved === null || onPortLabelMoved === void 0 ? void 0 : onPortLabelMoved(x, y, id); }, onResized: function (width, height) { return onPortLabelResized === null || onPortLabelResized === void 0 ? void 0 : onPortLabelResized(width, height, id); }, onContentChanged: function (ev, newValue) { return onPortLabelContentChanged === null || onPortLabelContentChanged === void 0 ? void 0 : onPortLabelContentChanged(ev, newValue, id); } });
|
|
1671
1713
|
};
|
|
1672
|
-
var renderedShape = React
|
|
1714
|
+
var renderedShape = React.useMemo(function () {
|
|
1673
1715
|
if (renderShape) {
|
|
1674
1716
|
var RenderShape = renderShape;
|
|
1675
|
-
return (React
|
|
1717
|
+
return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
|
|
1676
1718
|
}
|
|
1677
1719
|
else {
|
|
1678
|
-
return React
|
|
1720
|
+
return React.createElement(Circle, { onMouseDown: function (e) { return onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(id, e); }, onMouseUp: function (e) { return onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(id, e); }, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onMouseMove: function (e) { return onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove(id, e); }, onClick: function (e) { return onSelected === null || onSelected === void 0 ? void 0 : onSelected(id, e); }, ref: ref, x: x, y: y, positioningAnchor: exports.PositioningAnchor.Center, height: height, width: width, stroke: "black", fill: "black" });
|
|
1679
1721
|
}
|
|
1680
1722
|
}, [props]);
|
|
1681
|
-
return (React
|
|
1723
|
+
return (React.createElement(React.Fragment, null,
|
|
1682
1724
|
renderedShape,
|
|
1683
1725
|
label && renderLabel(label)));
|
|
1684
1726
|
});
|
|
1685
|
-
var Port = React
|
|
1727
|
+
var Port = React.memo(Port1);
|
|
1686
1728
|
|
|
1687
1729
|
// Render the svg <path> element
|
|
1688
1730
|
function getCurvePathData(points, smoothing, closed) {
|
|
@@ -1843,14 +1885,14 @@ function calculateAngleWithOx(pStart, pEnd) {
|
|
|
1843
1885
|
//Defined remove icon for element link, shown when element link is selected.
|
|
1844
1886
|
function CloseIcon(_a) {
|
|
1845
1887
|
var onClick = _a.onClick;
|
|
1846
|
-
return (React
|
|
1847
|
-
React
|
|
1848
|
-
React
|
|
1849
|
-
React
|
|
1850
|
-
React
|
|
1851
|
-
React
|
|
1852
|
-
React
|
|
1853
|
-
React
|
|
1888
|
+
return (React.createElement("svg", { width: 20, height: 20, viewBox: "0 0 24.00 24.00", xmlns: "http://www.w3.org/2000/svg", fill: "#ff0000", transform: "rotate(0)", onMouseDown: function (ev) { ev.stopPropagation(); }, onClick: onClick, cursor: 'pointer' },
|
|
1889
|
+
React.createElement("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0", transform: "translate(3.84,3.84), scale(0.68)" },
|
|
1890
|
+
React.createElement("rect", { x: "0", y: "0", width: "24.00", height: "24.00", rx: "12", fill: "#ffffff", strokeWidth: "0" })),
|
|
1891
|
+
React.createElement("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round", stroke: "#CCCCCC", "stroke-width": "0.048" }),
|
|
1892
|
+
React.createElement("g", { id: "SVGRepo_iconCarrier" },
|
|
1893
|
+
React.createElement("g", null,
|
|
1894
|
+
React.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
|
|
1895
|
+
React.createElement("path", { d: "M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-11.414L9.172 7.757 7.757 9.172 10.586 12l-2.829 2.828 1.415 1.415L12 13.414l2.828 2.829 1.415-1.415L13.414 12l2.829-2.828-1.415-1.415L12 10.586z" })))));
|
|
1854
1896
|
}
|
|
1855
1897
|
|
|
1856
1898
|
/**
|
|
@@ -7387,6 +7429,12 @@ var flattenJs = f;
|
|
|
7387
7429
|
|
|
7388
7430
|
var Flatten$1 = /*@__PURE__*/getDefaultExportFromCjs(flattenJs);
|
|
7389
7431
|
|
|
7432
|
+
var checkPositionOnLine = function (position, line) {
|
|
7433
|
+
var point = Flatten$1.point(position.x, position.y);
|
|
7434
|
+
var _line = Flatten$1.segment(Flatten$1.point(line[0].x, line[0].y), Flatten$1.point(line[1].x, line[1].y));
|
|
7435
|
+
return _line.contains(point);
|
|
7436
|
+
};
|
|
7437
|
+
|
|
7390
7438
|
/**
|
|
7391
7439
|
* Check if position 1 is within the radius r of position 2
|
|
7392
7440
|
* @returns boolean
|
|
@@ -7457,11 +7505,12 @@ var checkPointContainsPolygon = function (position, polygonPoints) {
|
|
|
7457
7505
|
*/
|
|
7458
7506
|
var makePolygonOfElement = function (ele) {
|
|
7459
7507
|
var polygon = new Flatten$1.Polygon();
|
|
7508
|
+
var strokeWidthOffset = 1;
|
|
7460
7509
|
polygon.addFace([
|
|
7461
|
-
Flatten$1.point(ele.position.x, ele.position.y),
|
|
7462
|
-
Flatten$1.point(ele.position.x + ele.size.width, ele.position.y),
|
|
7463
|
-
Flatten$1.point(ele.position.x + ele.size.width, ele.position.y + ele.size.height),
|
|
7464
|
-
Flatten$1.point(ele.position.x, ele.position.y + ele.size.height),
|
|
7510
|
+
Flatten$1.point(ele.position.x + strokeWidthOffset, ele.position.y + strokeWidthOffset),
|
|
7511
|
+
Flatten$1.point(ele.position.x + ele.size.width - strokeWidthOffset, ele.position.y + strokeWidthOffset),
|
|
7512
|
+
Flatten$1.point(ele.position.x + ele.size.width - strokeWidthOffset, ele.position.y + ele.size.height - strokeWidthOffset),
|
|
7513
|
+
Flatten$1.point(ele.position.x + strokeWidthOffset, ele.position.y + ele.size.height - strokeWidthOffset),
|
|
7465
7514
|
]);
|
|
7466
7515
|
return polygon;
|
|
7467
7516
|
};
|
|
@@ -7503,44 +7552,53 @@ var getFirstIntersection = function (startPosition, endPosition, elements) {
|
|
|
7503
7552
|
//Find a point next to an element from a point on the element
|
|
7504
7553
|
var generateSubstitutePosition = function (intersectedPosition, targetPosition, ele) {
|
|
7505
7554
|
var translationOffset = 20;
|
|
7555
|
+
var strokeWidthOffset = 1;
|
|
7506
7556
|
var vertex1Position = {
|
|
7507
|
-
x: ele.position.x,
|
|
7508
|
-
y: ele.position.y,
|
|
7557
|
+
x: ele.position.x + strokeWidthOffset,
|
|
7558
|
+
y: ele.position.y + strokeWidthOffset,
|
|
7509
7559
|
};
|
|
7510
7560
|
var vertex2Position = {
|
|
7511
|
-
x: ele.position.x + ele.size.width,
|
|
7512
|
-
y: ele.position.y,
|
|
7561
|
+
x: ele.position.x + ele.size.width - strokeWidthOffset,
|
|
7562
|
+
y: ele.position.y + strokeWidthOffset,
|
|
7513
7563
|
};
|
|
7514
7564
|
var vertex3Position = {
|
|
7515
|
-
x: ele.position.x + ele.size.width,
|
|
7516
|
-
y: ele.position.y + ele.size.height,
|
|
7565
|
+
x: ele.position.x + ele.size.width - strokeWidthOffset,
|
|
7566
|
+
y: ele.position.y + ele.size.height - strokeWidthOffset,
|
|
7517
7567
|
};
|
|
7518
7568
|
var vertex4Position = {
|
|
7519
|
-
x: ele.position.x,
|
|
7520
|
-
y: ele.position.y + ele.size.height,
|
|
7569
|
+
x: ele.position.x + strokeWidthOffset,
|
|
7570
|
+
y: ele.position.y + ele.size.height - strokeWidthOffset,
|
|
7521
7571
|
};
|
|
7522
7572
|
var replacementPosition = null;
|
|
7523
|
-
if (checkSamePosition(vertex1Position, intersectedPosition,
|
|
7573
|
+
if (checkSamePosition(vertex1Position, intersectedPosition, 3)) {
|
|
7524
7574
|
//Cut at vertex 1 of bbox, move out a distance x,y
|
|
7525
|
-
replacementPosition
|
|
7526
|
-
|
|
7575
|
+
replacementPosition = {
|
|
7576
|
+
x: vertex1Position.x - translationOffset,
|
|
7577
|
+
y: vertex1Position.y - translationOffset,
|
|
7578
|
+
};
|
|
7527
7579
|
}
|
|
7528
|
-
else if (checkSamePosition(vertex2Position, intersectedPosition,
|
|
7580
|
+
else if (checkSamePosition(vertex2Position, intersectedPosition, 3)) {
|
|
7529
7581
|
//Cut at vertex 2 of bbox, move out a distance x,y
|
|
7530
|
-
replacementPosition
|
|
7531
|
-
|
|
7582
|
+
replacementPosition = {
|
|
7583
|
+
x: vertex2Position.x + translationOffset,
|
|
7584
|
+
y: vertex2Position.y - translationOffset,
|
|
7585
|
+
};
|
|
7532
7586
|
}
|
|
7533
|
-
else if (checkSamePosition(vertex3Position, intersectedPosition,
|
|
7587
|
+
else if (checkSamePosition(vertex3Position, intersectedPosition, 3)) {
|
|
7534
7588
|
//Cut at vertex 3 of bbox, move out a distance x,y
|
|
7535
|
-
replacementPosition
|
|
7536
|
-
|
|
7589
|
+
replacementPosition = {
|
|
7590
|
+
x: vertex3Position.x + translationOffset,
|
|
7591
|
+
y: vertex3Position.y + translationOffset,
|
|
7592
|
+
};
|
|
7537
7593
|
}
|
|
7538
|
-
else if (checkSamePosition(vertex4Position, intersectedPosition,
|
|
7594
|
+
else if (checkSamePosition(vertex4Position, intersectedPosition, 3)) {
|
|
7539
7595
|
//Cut at vertex 4 of bbox, move out a distance x,y
|
|
7540
|
-
replacementPosition
|
|
7541
|
-
|
|
7596
|
+
replacementPosition = {
|
|
7597
|
+
x: vertex4Position.x - translationOffset,
|
|
7598
|
+
y: vertex4Position.y + translationOffset,
|
|
7599
|
+
};
|
|
7542
7600
|
}
|
|
7543
|
-
else if (intersectedPosition
|
|
7601
|
+
else if (checkPositionOnLine(intersectedPosition, [vertex1Position, vertex2Position])) {
|
|
7544
7602
|
//cut top edge, move left or right
|
|
7545
7603
|
var lineOfVertex12 = Flatten$1.line(Flatten$1.point(vertex1Position.x, vertex1Position.y), Flatten$1.point(vertex2Position.x, vertex2Position.y));
|
|
7546
7604
|
//Check if the line lies on the edge of the bbox then move the starting point out 1 distance perpendicular to the edge.
|
|
@@ -7564,7 +7622,7 @@ var generateSubstitutePosition = function (intersectedPosition, targetPosition,
|
|
|
7564
7622
|
replacementPosition = findNearestPosition([leftPosition, rightPosition], targetPosition);
|
|
7565
7623
|
}
|
|
7566
7624
|
}
|
|
7567
|
-
else if (intersectedPosition
|
|
7625
|
+
else if (checkPositionOnLine(intersectedPosition, [vertex3Position, vertex4Position])) {
|
|
7568
7626
|
//cut bottom edge, move left or right
|
|
7569
7627
|
var lineOfVertex34 = Flatten$1.line(Flatten$1.point(vertex3Position.x, vertex3Position.y), Flatten$1.point(vertex4Position.x, vertex4Position.y));
|
|
7570
7628
|
if (Flatten$1.point(intersectedPosition.x, intersectedPosition.y).distanceTo(lineOfVertex34)[0] === 0 &&
|
|
@@ -7587,7 +7645,7 @@ var generateSubstitutePosition = function (intersectedPosition, targetPosition,
|
|
|
7587
7645
|
replacementPosition = findNearestPosition([leftPosition, rightPosition], targetPosition);
|
|
7588
7646
|
}
|
|
7589
7647
|
}
|
|
7590
|
-
else if (intersectedPosition
|
|
7648
|
+
else if (checkPositionOnLine(intersectedPosition, [vertex1Position, vertex4Position])) {
|
|
7591
7649
|
//cut left edge, move up or down
|
|
7592
7650
|
var lineOfVertex14 = Flatten$1.line(Flatten$1.point(vertex1Position.x, vertex1Position.y), Flatten$1.point(vertex4Position.x, vertex4Position.y));
|
|
7593
7651
|
if (Flatten$1.point(intersectedPosition.x, intersectedPosition.y).distanceTo(lineOfVertex14)[0] === 0 &&
|
|
@@ -7610,7 +7668,7 @@ var generateSubstitutePosition = function (intersectedPosition, targetPosition,
|
|
|
7610
7668
|
replacementPosition = findNearestPosition([topPosition, bottomPosition], targetPosition);
|
|
7611
7669
|
}
|
|
7612
7670
|
}
|
|
7613
|
-
else if (intersectedPosition
|
|
7671
|
+
else if (checkPositionOnLine(intersectedPosition, [vertex2Position, vertex3Position])) {
|
|
7614
7672
|
//cut right edge, move up or down
|
|
7615
7673
|
var lineOfVertex23 = Flatten$1.line(Flatten$1.point(vertex2Position.x, vertex2Position.y), Flatten$1.point(vertex3Position.x, vertex3Position.y));
|
|
7616
7674
|
if (Flatten$1.point(intersectedPosition.x, intersectedPosition.y).distanceTo(lineOfVertex23)[0] === 0 &&
|
|
@@ -7643,25 +7701,25 @@ var getRelativePosition = function (clientPosition, relativeElement) {
|
|
|
7643
7701
|
};
|
|
7644
7702
|
};
|
|
7645
7703
|
|
|
7646
|
-
var makerStart = React
|
|
7647
|
-
var makerEnd = React
|
|
7704
|
+
var makerStart = React.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
|
|
7705
|
+
var makerEnd = React.createElement("path", { d: "M0 0 L 20 10 L0 20 Z", fill: "blue" }); //<path d="M0 0 L 10 5 L0 10 Z"></path>
|
|
7648
7706
|
var IElementLink = function (_a) {
|
|
7649
7707
|
var _b, _c;
|
|
7650
7708
|
var id = _a.id, path = _a.path, stroke = _a.stroke, _d = _a.strokeWidth, strokeWidth = _d === void 0 ? 4 : _d, pointsProp = _a.points, sourcePosition = _a.sourcePosition, targetPosition = _a.targetPosition, onPathChanged = _a.onPathChanged, onClickDelete = _a.onClickDelete, onSelected = _a.onSelected, onDeselected = _a.onDeselected, container = _a.container, _e = _a.markerStart, markerStart = _e === void 0 ? makerStart : _e, _f = _a.markerEnd, markerEnd = _f === void 0 ? makerEnd : _f, _g = _a.markerDistanceFromPort, markerDistanceFromPort = _g === void 0 ? LINK_MARKER_DISTANCE_FROM_PORT : _g, _h = _a.markerSize, markerSize = _h === void 0 ? LINK_MARKER_SIZE : _h, label = _a.label, sourceLabel = _a.sourceLabel, targetLabel = _a.targetLabel, onLabelMoved = _a.onLabelMoved, onLabelResized = _a.onLabelResized, onLabelContentChanged = _a.onLabelContentChanged;
|
|
7651
|
-
var _j = React
|
|
7652
|
-
var _k = React
|
|
7653
|
-
var _l = React
|
|
7654
|
-
var _m = React
|
|
7655
|
-
var _o = React
|
|
7709
|
+
var _j = React.useState(path), pathStr = _j[0], setPathStr = _j[1];
|
|
7710
|
+
var _k = React.useState(pointsProp !== null && pointsProp !== void 0 ? pointsProp : []), points = _k[0], setPoints = _k[1];
|
|
7711
|
+
var _l = React.useState(false), isDragging = _l[0], setIsDragging = _l[1];
|
|
7712
|
+
var _m = React.useState(), draggingPointIndex = _m[0], setDraggingPointIndex = _m[1];
|
|
7713
|
+
var _o = React.useState({
|
|
7656
7714
|
current: null,
|
|
7657
7715
|
}), selectedLabelRef = _o[0], setSelectedLabelRef = _o[1];
|
|
7658
|
-
var _p = React
|
|
7659
|
-
var _q = React
|
|
7660
|
-
var pathRef = React
|
|
7661
|
-
var labelRef = React
|
|
7662
|
-
var sourceLabelRef = React
|
|
7663
|
-
var targetLabelRef = React
|
|
7664
|
-
React
|
|
7716
|
+
var _p = React.useState(false), isSelectedLink = _p[0], setIsSelectedLink = _p[1];
|
|
7717
|
+
var _q = React.useContext(paperEventEmitterContext), onPaperClicked = _q.onPaperClicked, onElementSelected = _q.onElementSelected;
|
|
7718
|
+
var pathRef = React.useRef(null);
|
|
7719
|
+
var labelRef = React.useRef(null);
|
|
7720
|
+
var sourceLabelRef = React.useRef(null);
|
|
7721
|
+
var targetLabelRef = React.useRef(null);
|
|
7722
|
+
React.useEffect(function () {
|
|
7665
7723
|
var paperClickListener = onPaperClicked(function () {
|
|
7666
7724
|
setSelectedLabelRef({
|
|
7667
7725
|
current: null,
|
|
@@ -7673,7 +7731,7 @@ var IElementLink = function (_a) {
|
|
|
7673
7731
|
paperClickListener.off();
|
|
7674
7732
|
};
|
|
7675
7733
|
}, []);
|
|
7676
|
-
React
|
|
7734
|
+
React.useEffect(function () {
|
|
7677
7735
|
var elementSelectedListener = onElementSelected(function () {
|
|
7678
7736
|
setSelectedLabelRef({
|
|
7679
7737
|
current: null,
|
|
@@ -7685,17 +7743,17 @@ var IElementLink = function (_a) {
|
|
|
7685
7743
|
elementSelectedListener.off();
|
|
7686
7744
|
};
|
|
7687
7745
|
}, []);
|
|
7688
|
-
React
|
|
7746
|
+
React.useLayoutEffect(function () {
|
|
7689
7747
|
var pointsList = __spreadArray(__spreadArray([sourcePosition], points, true), [targetPosition], false);
|
|
7690
7748
|
var _pathStr = createSmoothPathString(pointsList, undefined);
|
|
7691
7749
|
setPathStr(_pathStr);
|
|
7692
7750
|
}, [sourcePosition, points, targetPosition]);
|
|
7693
|
-
React
|
|
7751
|
+
React.useEffect(function () {
|
|
7694
7752
|
if (!pathStr)
|
|
7695
7753
|
return;
|
|
7696
7754
|
onPathChanged === null || onPathChanged === void 0 ? void 0 : onPathChanged(pathStr, id);
|
|
7697
7755
|
}, [pathStr, id]);
|
|
7698
|
-
React
|
|
7756
|
+
React.useLayoutEffect(function () {
|
|
7699
7757
|
//handle when creating and moving point
|
|
7700
7758
|
var handleMouseMove = function (ev) {
|
|
7701
7759
|
var mouseEvent = ev;
|
|
@@ -7851,7 +7909,7 @@ var IElementLink = function (_a) {
|
|
|
7851
7909
|
x: relativePosition.x + relativePositionTo.x,
|
|
7852
7910
|
y: relativePosition.y + relativePositionTo.y,
|
|
7853
7911
|
};
|
|
7854
|
-
return (React
|
|
7912
|
+
return (React.createElement(Text$1, { id: label.id, x: position.x, y: position.y, width: size.width, height: size.height, editable: label.editable, content: content, fontSize: label.fontSize, border: label.border, ref: curLabelRef, container: container, onSelected: function () { return setSelectedLabelRef(curLabelRef); }, onMoved: handleLabelMoved, onResized: handleLabelResized, onContentChanged: handleLabelContentChanged }));
|
|
7855
7913
|
};
|
|
7856
7914
|
var angleMarkerStart = '0';
|
|
7857
7915
|
var angleMarkerEnd = '0';
|
|
@@ -7869,28 +7927,28 @@ var IElementLink = function (_a) {
|
|
|
7869
7927
|
}
|
|
7870
7928
|
centerPathPosition = (_c = pathRef.current) === null || _c === void 0 ? void 0 : _c.getPointAtLength(pathRef.current.getTotalLength() / 2);
|
|
7871
7929
|
}
|
|
7872
|
-
return (React
|
|
7873
|
-
React
|
|
7874
|
-
React
|
|
7875
|
-
isSelectedLink && centerPathPosition && React
|
|
7876
|
-
React
|
|
7930
|
+
return (React.createElement("g", null,
|
|
7931
|
+
React.createElement("path", { ref: pathRef, d: pathStr, className: isSelectedLink ? CSS_CLASS_LINK_SELECTED : '', fill: "none", stroke: stroke || LINK_DEFAULT_COLOR, strokeWidth: strokeWidth }),
|
|
7932
|
+
React.createElement("path", { d: pathStr, fill: "none", stroke: 'transparent', strokeWidth: LINK_CLICKABLE_STROKE_WIDTH, onClick: handleClickPath, onMouseDown: handleMouseDownOnPath }),
|
|
7933
|
+
isSelectedLink && centerPathPosition && React.createElement("svg", { x: centerPathPosition.x - 10, y: centerPathPosition.y - 10 },
|
|
7934
|
+
React.createElement(CloseIcon, { onClick: onClickDelete })),
|
|
7877
7935
|
label && renderLabel(label, 'middle', centerPathPosition),
|
|
7878
7936
|
sourceLabel && renderLabel(sourceLabel, 'source', sourcePosition),
|
|
7879
7937
|
targetLabel && renderLabel(targetLabel, 'target', targetPosition),
|
|
7880
|
-
markerStartPosition && React
|
|
7881
|
-
React
|
|
7882
|
-
markerEndPosition && React
|
|
7883
|
-
React
|
|
7938
|
+
markerStartPosition && React.createElement("g", { transform: "rotate(".concat(angleMarkerStart, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
|
|
7939
|
+
React.createElement("svg", { x: markerStartPosition.x - markerSize / 2, y: markerStartPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerStart)),
|
|
7940
|
+
markerEndPosition && React.createElement("g", { transform: "rotate(".concat(angleMarkerEnd, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
|
|
7941
|
+
React.createElement("svg", { x: markerEndPosition.x - markerSize / 2, y: markerEndPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerEnd))));
|
|
7884
7942
|
};
|
|
7885
|
-
var ElementLink = React
|
|
7943
|
+
var ElementLink = React.memo(IElementLink);
|
|
7886
7944
|
|
|
7887
7945
|
var Ruler = function (_a) {
|
|
7888
7946
|
var squareSize = _a.squareSize, border = _a.border;
|
|
7889
7947
|
var numColumns = Math.ceil(3000 / squareSize);
|
|
7890
7948
|
var numRows = Math.ceil(3000 / squareSize);
|
|
7891
7949
|
var tableWidth = numColumns * squareSize;
|
|
7892
|
-
return (React
|
|
7893
|
-
React
|
|
7950
|
+
return (React.createElement("table", { style: { position: 'absolute', zIndex: -1, top: 0, left: 0, borderCollapse: 'collapse', width: tableWidth } },
|
|
7951
|
+
React.createElement("tbody", null, Array.from({ length: numRows }).map(function (_, rowIndex) { return (React.createElement("tr", { key: rowIndex, style: { margin: 0, padding: 0 } }, Array.from({ length: numColumns }).map(function (_, colIndex) { return (React.createElement("td", { key: colIndex, style: {
|
|
7894
7952
|
width: squareSize,
|
|
7895
7953
|
height: squareSize,
|
|
7896
7954
|
border: border,
|
|
@@ -7901,11 +7959,11 @@ var Ruler = function (_a) {
|
|
|
7901
7959
|
position: 'relative',
|
|
7902
7960
|
fontSize: 12,
|
|
7903
7961
|
} },
|
|
7904
|
-
rowIndex === 0 ? React
|
|
7905
|
-
colIndex === 0 ? React
|
|
7962
|
+
rowIndex === 0 ? React.createElement("span", { style: { marginLeft: "-12px" } }, colIndex * squareSize) : "",
|
|
7963
|
+
colIndex === 0 ? React.createElement("span", { style: { top: "-9px", position: "absolute" } }, rowIndex * squareSize) : "")); }))); }))));
|
|
7906
7964
|
};
|
|
7907
7965
|
|
|
7908
|
-
var ElementWrapper = React
|
|
7966
|
+
var ElementWrapper = React.forwardRef(function (_a, ref) {
|
|
7909
7967
|
var x = _a.x, y = _a.y, cssClass = _a.cssClass, children = _a.children; _a.portPlaceholders; _a.ports; var onClick = _a.onClick, onContextMenu = _a.onContextMenu, onMouseMove = _a.onMouseMove, onMouseLeave = _a.onMouseLeave, onMouseUp = _a.onMouseUp;
|
|
7910
7968
|
var handleMouseDown = function (ev) {
|
|
7911
7969
|
ev.stopPropagation();
|
|
@@ -7920,7 +7978,7 @@ var ElementWrapper = React$1.forwardRef(function (_a, ref) {
|
|
|
7920
7978
|
onContextMenu(ev);
|
|
7921
7979
|
}
|
|
7922
7980
|
};
|
|
7923
|
-
return (React
|
|
7981
|
+
return (React.createElement("svg", { className: cssClass, x: x, y: y, onClick: handleClick, onContextMenu: handleClick, onMouseDown: handleMouseDown, ref: ref, style: { overflow: "visible" }, onMouseMove: onMouseMove, onMouseLeave: onMouseLeave, onMouseUp: onMouseUp }, children));
|
|
7924
7982
|
});
|
|
7925
7983
|
|
|
7926
7984
|
// Calculate the position of the 4 vertices of a rectangle relative to its parent svg
|
|
@@ -7960,1275 +8018,50 @@ var getElementRotationInfo = function (element) {
|
|
|
7960
8018
|
return rotationAngle;
|
|
7961
8019
|
};
|
|
7962
8020
|
|
|
7963
|
-
var checkPositionOnLine = function (position, line) {
|
|
7964
|
-
var point = Flatten$1.point(position.x, position.y);
|
|
7965
|
-
var _line = Flatten$1.segment(Flatten$1.point(line[0].x, line[0].y), Flatten$1.point(line[1].x, line[1].y));
|
|
7966
|
-
return _line.contains(point);
|
|
7967
|
-
};
|
|
7968
|
-
|
|
7969
|
-
var bundle = {exports: {}};
|
|
7970
|
-
|
|
7971
|
-
var cssLayout = {exports: {}};
|
|
7972
|
-
|
|
7973
|
-
(function (module, exports) {
|
|
7974
|
-
// UMD (Universal Module Definition)
|
|
7975
|
-
// See https://github.com/umdjs/umd for reference
|
|
7976
|
-
//
|
|
7977
|
-
// This file uses the following specific UMD implementation:
|
|
7978
|
-
// https://github.com/umdjs/umd/blob/master/returnExports.js
|
|
7979
|
-
(function(root, factory) {
|
|
7980
|
-
{
|
|
7981
|
-
// Node. Does not work with strict CommonJS, but
|
|
7982
|
-
// only CommonJS-like environments that support module.exports,
|
|
7983
|
-
// like Node.
|
|
7984
|
-
module.exports = factory();
|
|
7985
|
-
}
|
|
7986
|
-
}(commonjsGlobal, function() {
|
|
7987
|
-
/**
|
|
7988
|
-
* Copyright (c) 2014, Facebook, Inc.
|
|
7989
|
-
* All rights reserved.
|
|
7990
|
-
*
|
|
7991
|
-
* This source code is licensed under the BSD-style license found in the
|
|
7992
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7993
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
7994
|
-
*/
|
|
7995
|
-
|
|
7996
|
-
var computeLayout = (function() {
|
|
7997
|
-
|
|
7998
|
-
var CSS_UNDEFINED;
|
|
7999
|
-
|
|
8000
|
-
var CSS_DIRECTION_INHERIT = 'inherit';
|
|
8001
|
-
var CSS_DIRECTION_LTR = 'ltr';
|
|
8002
|
-
var CSS_DIRECTION_RTL = 'rtl';
|
|
8003
|
-
|
|
8004
|
-
var CSS_FLEX_DIRECTION_ROW = 'row';
|
|
8005
|
-
var CSS_FLEX_DIRECTION_ROW_REVERSE = 'row-reverse';
|
|
8006
|
-
var CSS_FLEX_DIRECTION_COLUMN = 'column';
|
|
8007
|
-
var CSS_FLEX_DIRECTION_COLUMN_REVERSE = 'column-reverse';
|
|
8008
|
-
|
|
8009
|
-
var CSS_JUSTIFY_FLEX_START = 'flex-start';
|
|
8010
|
-
var CSS_JUSTIFY_CENTER = 'center';
|
|
8011
|
-
var CSS_JUSTIFY_FLEX_END = 'flex-end';
|
|
8012
|
-
var CSS_JUSTIFY_SPACE_BETWEEN = 'space-between';
|
|
8013
|
-
var CSS_JUSTIFY_SPACE_AROUND = 'space-around';
|
|
8014
|
-
|
|
8015
|
-
var CSS_ALIGN_FLEX_START = 'flex-start';
|
|
8016
|
-
var CSS_ALIGN_CENTER = 'center';
|
|
8017
|
-
var CSS_ALIGN_FLEX_END = 'flex-end';
|
|
8018
|
-
var CSS_ALIGN_STRETCH = 'stretch';
|
|
8019
|
-
|
|
8020
|
-
var CSS_POSITION_RELATIVE = 'relative';
|
|
8021
|
-
var CSS_POSITION_ABSOLUTE = 'absolute';
|
|
8022
|
-
|
|
8023
|
-
var leading = {
|
|
8024
|
-
'row': 'left',
|
|
8025
|
-
'row-reverse': 'right',
|
|
8026
|
-
'column': 'top',
|
|
8027
|
-
'column-reverse': 'bottom'
|
|
8028
|
-
};
|
|
8029
|
-
var trailing = {
|
|
8030
|
-
'row': 'right',
|
|
8031
|
-
'row-reverse': 'left',
|
|
8032
|
-
'column': 'bottom',
|
|
8033
|
-
'column-reverse': 'top'
|
|
8034
|
-
};
|
|
8035
|
-
var pos = {
|
|
8036
|
-
'row': 'left',
|
|
8037
|
-
'row-reverse': 'right',
|
|
8038
|
-
'column': 'top',
|
|
8039
|
-
'column-reverse': 'bottom'
|
|
8040
|
-
};
|
|
8041
|
-
var dim = {
|
|
8042
|
-
'row': 'width',
|
|
8043
|
-
'row-reverse': 'width',
|
|
8044
|
-
'column': 'height',
|
|
8045
|
-
'column-reverse': 'height'
|
|
8046
|
-
};
|
|
8047
|
-
|
|
8048
|
-
// When transpiled to Java / C the node type has layout, children and style
|
|
8049
|
-
// properties. For the JavaScript version this function adds these properties
|
|
8050
|
-
// if they don't already exist.
|
|
8051
|
-
function fillNodes(node) {
|
|
8052
|
-
if (!node.layout || node.isDirty) {
|
|
8053
|
-
node.layout = {
|
|
8054
|
-
width: undefined,
|
|
8055
|
-
height: undefined,
|
|
8056
|
-
top: 0,
|
|
8057
|
-
left: 0,
|
|
8058
|
-
right: 0,
|
|
8059
|
-
bottom: 0
|
|
8060
|
-
};
|
|
8061
|
-
}
|
|
8062
|
-
|
|
8063
|
-
if (!node.style) {
|
|
8064
|
-
node.style = {};
|
|
8065
|
-
}
|
|
8066
|
-
|
|
8067
|
-
if (!node.children) {
|
|
8068
|
-
node.children = [];
|
|
8069
|
-
}
|
|
8070
|
-
node.children.forEach(fillNodes);
|
|
8071
|
-
return node;
|
|
8072
|
-
}
|
|
8073
|
-
|
|
8074
|
-
function isUndefined(value) {
|
|
8075
|
-
return value === undefined;
|
|
8076
|
-
}
|
|
8077
|
-
|
|
8078
|
-
function isRowDirection(flexDirection) {
|
|
8079
|
-
return flexDirection === CSS_FLEX_DIRECTION_ROW ||
|
|
8080
|
-
flexDirection === CSS_FLEX_DIRECTION_ROW_REVERSE;
|
|
8081
|
-
}
|
|
8082
|
-
|
|
8083
|
-
function isColumnDirection(flexDirection) {
|
|
8084
|
-
return flexDirection === CSS_FLEX_DIRECTION_COLUMN ||
|
|
8085
|
-
flexDirection === CSS_FLEX_DIRECTION_COLUMN_REVERSE;
|
|
8086
|
-
}
|
|
8087
|
-
|
|
8088
|
-
function getLeadingMargin(node, axis) {
|
|
8089
|
-
if (node.style.marginStart !== undefined && isRowDirection(axis)) {
|
|
8090
|
-
return node.style.marginStart;
|
|
8091
|
-
}
|
|
8092
|
-
|
|
8093
|
-
var value = null;
|
|
8094
|
-
switch (axis) {
|
|
8095
|
-
case 'row': value = node.style.marginLeft; break;
|
|
8096
|
-
case 'row-reverse': value = node.style.marginRight; break;
|
|
8097
|
-
case 'column': value = node.style.marginTop; break;
|
|
8098
|
-
case 'column-reverse': value = node.style.marginBottom; break;
|
|
8099
|
-
}
|
|
8100
|
-
|
|
8101
|
-
if (value !== undefined) {
|
|
8102
|
-
return value;
|
|
8103
|
-
}
|
|
8104
|
-
|
|
8105
|
-
if (node.style.margin !== undefined) {
|
|
8106
|
-
return node.style.margin;
|
|
8107
|
-
}
|
|
8108
|
-
|
|
8109
|
-
return 0;
|
|
8110
|
-
}
|
|
8111
|
-
|
|
8112
|
-
function getTrailingMargin(node, axis) {
|
|
8113
|
-
if (node.style.marginEnd !== undefined && isRowDirection(axis)) {
|
|
8114
|
-
return node.style.marginEnd;
|
|
8115
|
-
}
|
|
8116
|
-
|
|
8117
|
-
var value = null;
|
|
8118
|
-
switch (axis) {
|
|
8119
|
-
case 'row': value = node.style.marginRight; break;
|
|
8120
|
-
case 'row-reverse': value = node.style.marginLeft; break;
|
|
8121
|
-
case 'column': value = node.style.marginBottom; break;
|
|
8122
|
-
case 'column-reverse': value = node.style.marginTop; break;
|
|
8123
|
-
}
|
|
8124
|
-
|
|
8125
|
-
if (value != null) {
|
|
8126
|
-
return value;
|
|
8127
|
-
}
|
|
8128
|
-
|
|
8129
|
-
if (node.style.margin !== undefined) {
|
|
8130
|
-
return node.style.margin;
|
|
8131
|
-
}
|
|
8132
|
-
|
|
8133
|
-
return 0;
|
|
8134
|
-
}
|
|
8135
|
-
|
|
8136
|
-
function getLeadingPadding(node, axis) {
|
|
8137
|
-
if (node.style.paddingStart !== undefined && node.style.paddingStart >= 0
|
|
8138
|
-
&& isRowDirection(axis)) {
|
|
8139
|
-
return node.style.paddingStart;
|
|
8140
|
-
}
|
|
8141
|
-
|
|
8142
|
-
var value = null;
|
|
8143
|
-
switch (axis) {
|
|
8144
|
-
case 'row': value = node.style.paddingLeft; break;
|
|
8145
|
-
case 'row-reverse': value = node.style.paddingRight; break;
|
|
8146
|
-
case 'column': value = node.style.paddingTop; break;
|
|
8147
|
-
case 'column-reverse': value = node.style.paddingBottom; break;
|
|
8148
|
-
}
|
|
8149
|
-
|
|
8150
|
-
if (value != null && value >= 0) {
|
|
8151
|
-
return value;
|
|
8152
|
-
}
|
|
8153
|
-
|
|
8154
|
-
if (node.style.padding !== undefined && node.style.padding >= 0) {
|
|
8155
|
-
return node.style.padding;
|
|
8156
|
-
}
|
|
8157
|
-
|
|
8158
|
-
return 0;
|
|
8159
|
-
}
|
|
8160
|
-
|
|
8161
|
-
function getTrailingPadding(node, axis) {
|
|
8162
|
-
if (node.style.paddingEnd !== undefined && node.style.paddingEnd >= 0
|
|
8163
|
-
&& isRowDirection(axis)) {
|
|
8164
|
-
return node.style.paddingEnd;
|
|
8165
|
-
}
|
|
8166
|
-
|
|
8167
|
-
var value = null;
|
|
8168
|
-
switch (axis) {
|
|
8169
|
-
case 'row': value = node.style.paddingRight; break;
|
|
8170
|
-
case 'row-reverse': value = node.style.paddingLeft; break;
|
|
8171
|
-
case 'column': value = node.style.paddingBottom; break;
|
|
8172
|
-
case 'column-reverse': value = node.style.paddingTop; break;
|
|
8173
|
-
}
|
|
8174
|
-
|
|
8175
|
-
if (value != null && value >= 0) {
|
|
8176
|
-
return value;
|
|
8177
|
-
}
|
|
8178
|
-
|
|
8179
|
-
if (node.style.padding !== undefined && node.style.padding >= 0) {
|
|
8180
|
-
return node.style.padding;
|
|
8181
|
-
}
|
|
8182
|
-
|
|
8183
|
-
return 0;
|
|
8184
|
-
}
|
|
8185
|
-
|
|
8186
|
-
function getLeadingBorder(node, axis) {
|
|
8187
|
-
if (node.style.borderStartWidth !== undefined && node.style.borderStartWidth >= 0
|
|
8188
|
-
&& isRowDirection(axis)) {
|
|
8189
|
-
return node.style.borderStartWidth;
|
|
8190
|
-
}
|
|
8191
|
-
|
|
8192
|
-
var value = null;
|
|
8193
|
-
switch (axis) {
|
|
8194
|
-
case 'row': value = node.style.borderLeftWidth; break;
|
|
8195
|
-
case 'row-reverse': value = node.style.borderRightWidth; break;
|
|
8196
|
-
case 'column': value = node.style.borderTopWidth; break;
|
|
8197
|
-
case 'column-reverse': value = node.style.borderBottomWidth; break;
|
|
8198
|
-
}
|
|
8199
|
-
|
|
8200
|
-
if (value != null && value >= 0) {
|
|
8201
|
-
return value;
|
|
8202
|
-
}
|
|
8203
|
-
|
|
8204
|
-
if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
|
|
8205
|
-
return node.style.borderWidth;
|
|
8206
|
-
}
|
|
8207
|
-
|
|
8208
|
-
return 0;
|
|
8209
|
-
}
|
|
8210
|
-
|
|
8211
|
-
function getTrailingBorder(node, axis) {
|
|
8212
|
-
if (node.style.borderEndWidth !== undefined && node.style.borderEndWidth >= 0
|
|
8213
|
-
&& isRowDirection(axis)) {
|
|
8214
|
-
return node.style.borderEndWidth;
|
|
8215
|
-
}
|
|
8216
|
-
|
|
8217
|
-
var value = null;
|
|
8218
|
-
switch (axis) {
|
|
8219
|
-
case 'row': value = node.style.borderRightWidth; break;
|
|
8220
|
-
case 'row-reverse': value = node.style.borderLeftWidth; break;
|
|
8221
|
-
case 'column': value = node.style.borderBottomWidth; break;
|
|
8222
|
-
case 'column-reverse': value = node.style.borderTopWidth; break;
|
|
8223
|
-
}
|
|
8224
|
-
|
|
8225
|
-
if (value != null && value >= 0) {
|
|
8226
|
-
return value;
|
|
8227
|
-
}
|
|
8228
|
-
|
|
8229
|
-
if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
|
|
8230
|
-
return node.style.borderWidth;
|
|
8231
|
-
}
|
|
8232
|
-
|
|
8233
|
-
return 0;
|
|
8234
|
-
}
|
|
8235
|
-
|
|
8236
|
-
function getLeadingPaddingAndBorder(node, axis) {
|
|
8237
|
-
return getLeadingPadding(node, axis) + getLeadingBorder(node, axis);
|
|
8238
|
-
}
|
|
8239
|
-
|
|
8240
|
-
function getTrailingPaddingAndBorder(node, axis) {
|
|
8241
|
-
return getTrailingPadding(node, axis) + getTrailingBorder(node, axis);
|
|
8242
|
-
}
|
|
8243
|
-
|
|
8244
|
-
function getBorderAxis(node, axis) {
|
|
8245
|
-
return getLeadingBorder(node, axis) + getTrailingBorder(node, axis);
|
|
8246
|
-
}
|
|
8247
|
-
|
|
8248
|
-
function getMarginAxis(node, axis) {
|
|
8249
|
-
return getLeadingMargin(node, axis) + getTrailingMargin(node, axis);
|
|
8250
|
-
}
|
|
8251
|
-
|
|
8252
|
-
function getPaddingAndBorderAxis(node, axis) {
|
|
8253
|
-
return getLeadingPaddingAndBorder(node, axis) +
|
|
8254
|
-
getTrailingPaddingAndBorder(node, axis);
|
|
8255
|
-
}
|
|
8256
|
-
|
|
8257
|
-
function getJustifyContent(node) {
|
|
8258
|
-
if (node.style.justifyContent) {
|
|
8259
|
-
return node.style.justifyContent;
|
|
8260
|
-
}
|
|
8261
|
-
return 'flex-start';
|
|
8262
|
-
}
|
|
8263
|
-
|
|
8264
|
-
function getAlignContent(node) {
|
|
8265
|
-
if (node.style.alignContent) {
|
|
8266
|
-
return node.style.alignContent;
|
|
8267
|
-
}
|
|
8268
|
-
return 'flex-start';
|
|
8269
|
-
}
|
|
8270
|
-
|
|
8271
|
-
function getAlignItem(node, child) {
|
|
8272
|
-
if (child.style.alignSelf) {
|
|
8273
|
-
return child.style.alignSelf;
|
|
8274
|
-
}
|
|
8275
|
-
if (node.style.alignItems) {
|
|
8276
|
-
return node.style.alignItems;
|
|
8277
|
-
}
|
|
8278
|
-
return 'stretch';
|
|
8279
|
-
}
|
|
8280
|
-
|
|
8281
|
-
function resolveAxis(axis, direction) {
|
|
8282
|
-
if (direction === CSS_DIRECTION_RTL) {
|
|
8283
|
-
if (axis === CSS_FLEX_DIRECTION_ROW) {
|
|
8284
|
-
return CSS_FLEX_DIRECTION_ROW_REVERSE;
|
|
8285
|
-
} else if (axis === CSS_FLEX_DIRECTION_ROW_REVERSE) {
|
|
8286
|
-
return CSS_FLEX_DIRECTION_ROW;
|
|
8287
|
-
}
|
|
8288
|
-
}
|
|
8289
|
-
|
|
8290
|
-
return axis;
|
|
8291
|
-
}
|
|
8292
|
-
|
|
8293
|
-
function resolveDirection(node, parentDirection) {
|
|
8294
|
-
var direction;
|
|
8295
|
-
if (node.style.direction) {
|
|
8296
|
-
direction = node.style.direction;
|
|
8297
|
-
} else {
|
|
8298
|
-
direction = CSS_DIRECTION_INHERIT;
|
|
8299
|
-
}
|
|
8300
|
-
|
|
8301
|
-
if (direction === CSS_DIRECTION_INHERIT) {
|
|
8302
|
-
direction = (parentDirection === undefined ? CSS_DIRECTION_LTR : parentDirection);
|
|
8303
|
-
}
|
|
8304
|
-
|
|
8305
|
-
return direction;
|
|
8306
|
-
}
|
|
8307
|
-
|
|
8308
|
-
function getFlexDirection(node) {
|
|
8309
|
-
if (node.style.flexDirection) {
|
|
8310
|
-
return node.style.flexDirection;
|
|
8311
|
-
}
|
|
8312
|
-
return CSS_FLEX_DIRECTION_COLUMN;
|
|
8313
|
-
}
|
|
8314
|
-
|
|
8315
|
-
function getCrossFlexDirection(flexDirection, direction) {
|
|
8316
|
-
if (isColumnDirection(flexDirection)) {
|
|
8317
|
-
return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
|
|
8318
|
-
} else {
|
|
8319
|
-
return CSS_FLEX_DIRECTION_COLUMN;
|
|
8320
|
-
}
|
|
8321
|
-
}
|
|
8322
|
-
|
|
8323
|
-
function getPositionType(node) {
|
|
8324
|
-
if (node.style.position) {
|
|
8325
|
-
return node.style.position;
|
|
8326
|
-
}
|
|
8327
|
-
return 'relative';
|
|
8328
|
-
}
|
|
8329
|
-
|
|
8330
|
-
function isFlex(node) {
|
|
8331
|
-
return (
|
|
8332
|
-
getPositionType(node) === CSS_POSITION_RELATIVE &&
|
|
8333
|
-
node.style.flex > 0
|
|
8334
|
-
);
|
|
8335
|
-
}
|
|
8336
|
-
|
|
8337
|
-
function isFlexWrap(node) {
|
|
8338
|
-
return node.style.flexWrap === 'wrap';
|
|
8339
|
-
}
|
|
8340
|
-
|
|
8341
|
-
function getDimWithMargin(node, axis) {
|
|
8342
|
-
return node.layout[dim[axis]] + getMarginAxis(node, axis);
|
|
8343
|
-
}
|
|
8344
|
-
|
|
8345
|
-
function isDimDefined(node, axis) {
|
|
8346
|
-
return node.style[dim[axis]] !== undefined && node.style[dim[axis]] >= 0;
|
|
8347
|
-
}
|
|
8348
|
-
|
|
8349
|
-
function isPosDefined(node, pos) {
|
|
8350
|
-
return node.style[pos] !== undefined;
|
|
8351
|
-
}
|
|
8352
|
-
|
|
8353
|
-
function isMeasureDefined(node) {
|
|
8354
|
-
return node.style.measure !== undefined;
|
|
8355
|
-
}
|
|
8356
|
-
|
|
8357
|
-
function getPosition(node, pos) {
|
|
8358
|
-
if (node.style[pos] !== undefined) {
|
|
8359
|
-
return node.style[pos];
|
|
8360
|
-
}
|
|
8361
|
-
return 0;
|
|
8362
|
-
}
|
|
8363
|
-
|
|
8364
|
-
function boundAxis(node, axis, value) {
|
|
8365
|
-
var min = {
|
|
8366
|
-
'row': node.style.minWidth,
|
|
8367
|
-
'row-reverse': node.style.minWidth,
|
|
8368
|
-
'column': node.style.minHeight,
|
|
8369
|
-
'column-reverse': node.style.minHeight
|
|
8370
|
-
}[axis];
|
|
8371
|
-
|
|
8372
|
-
var max = {
|
|
8373
|
-
'row': node.style.maxWidth,
|
|
8374
|
-
'row-reverse': node.style.maxWidth,
|
|
8375
|
-
'column': node.style.maxHeight,
|
|
8376
|
-
'column-reverse': node.style.maxHeight
|
|
8377
|
-
}[axis];
|
|
8378
|
-
|
|
8379
|
-
var boundValue = value;
|
|
8380
|
-
if (max !== undefined && max >= 0 && boundValue > max) {
|
|
8381
|
-
boundValue = max;
|
|
8382
|
-
}
|
|
8383
|
-
if (min !== undefined && min >= 0 && boundValue < min) {
|
|
8384
|
-
boundValue = min;
|
|
8385
|
-
}
|
|
8386
|
-
return boundValue;
|
|
8387
|
-
}
|
|
8388
|
-
|
|
8389
|
-
function fmaxf(a, b) {
|
|
8390
|
-
if (a > b) {
|
|
8391
|
-
return a;
|
|
8392
|
-
}
|
|
8393
|
-
return b;
|
|
8394
|
-
}
|
|
8395
|
-
|
|
8396
|
-
// When the user specifically sets a value for width or height
|
|
8397
|
-
function setDimensionFromStyle(node, axis) {
|
|
8398
|
-
// The parent already computed us a width or height. We just skip it
|
|
8399
|
-
if (node.layout[dim[axis]] !== undefined) {
|
|
8400
|
-
return;
|
|
8401
|
-
}
|
|
8402
|
-
// We only run if there's a width or height defined
|
|
8403
|
-
if (!isDimDefined(node, axis)) {
|
|
8404
|
-
return;
|
|
8405
|
-
}
|
|
8406
|
-
|
|
8407
|
-
// The dimensions can never be smaller than the padding and border
|
|
8408
|
-
node.layout[dim[axis]] = fmaxf(
|
|
8409
|
-
boundAxis(node, axis, node.style[dim[axis]]),
|
|
8410
|
-
getPaddingAndBorderAxis(node, axis)
|
|
8411
|
-
);
|
|
8412
|
-
}
|
|
8413
|
-
|
|
8414
|
-
function setTrailingPosition(node, child, axis) {
|
|
8415
|
-
child.layout[trailing[axis]] = node.layout[dim[axis]] -
|
|
8416
|
-
child.layout[dim[axis]] - child.layout[pos[axis]];
|
|
8417
|
-
}
|
|
8418
|
-
|
|
8419
|
-
// If both left and right are defined, then use left. Otherwise return
|
|
8420
|
-
// +left or -right depending on which is defined.
|
|
8421
|
-
function getRelativePosition(node, axis) {
|
|
8422
|
-
if (node.style[leading[axis]] !== undefined) {
|
|
8423
|
-
return getPosition(node, leading[axis]);
|
|
8424
|
-
}
|
|
8425
|
-
return -getPosition(node, trailing[axis]);
|
|
8426
|
-
}
|
|
8427
|
-
|
|
8428
|
-
function layoutNodeImpl(node, parentMaxWidth, /*css_direction_t*/parentDirection) {
|
|
8429
|
-
var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);
|
|
8430
|
-
var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction);
|
|
8431
|
-
var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction);
|
|
8432
|
-
var/*(c)!css_flex_direction_t*//*(java)!int*/ resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
|
|
8433
|
-
|
|
8434
|
-
// Handle width and height style attributes
|
|
8435
|
-
setDimensionFromStyle(node, mainAxis);
|
|
8436
|
-
setDimensionFromStyle(node, crossAxis);
|
|
8437
|
-
|
|
8438
|
-
// Set the resolved resolution in the node's layout
|
|
8439
|
-
node.layout.direction = direction;
|
|
8440
|
-
|
|
8441
|
-
// The position is set by the parent, but we need to complete it with a
|
|
8442
|
-
// delta composed of the margin and left/top/right/bottom
|
|
8443
|
-
node.layout[leading[mainAxis]] += getLeadingMargin(node, mainAxis) +
|
|
8444
|
-
getRelativePosition(node, mainAxis);
|
|
8445
|
-
node.layout[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) +
|
|
8446
|
-
getRelativePosition(node, mainAxis);
|
|
8447
|
-
node.layout[leading[crossAxis]] += getLeadingMargin(node, crossAxis) +
|
|
8448
|
-
getRelativePosition(node, crossAxis);
|
|
8449
|
-
node.layout[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) +
|
|
8450
|
-
getRelativePosition(node, crossAxis);
|
|
8451
|
-
|
|
8452
|
-
// Inline immutable values from the target node to avoid excessive method
|
|
8453
|
-
// invocations during the layout calculation.
|
|
8454
|
-
var/*int*/ childCount = node.children.length;
|
|
8455
|
-
var/*float*/ paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
|
|
8456
|
-
|
|
8457
|
-
if (isMeasureDefined(node)) {
|
|
8458
|
-
var/*bool*/ isResolvedRowDimDefined = !isUndefined(node.layout[dim[resolvedRowAxis]]);
|
|
8459
|
-
|
|
8460
|
-
var/*float*/ width = CSS_UNDEFINED;
|
|
8461
|
-
if (isDimDefined(node, resolvedRowAxis)) {
|
|
8462
|
-
width = node.style.width;
|
|
8463
|
-
} else if (isResolvedRowDimDefined) {
|
|
8464
|
-
width = node.layout[dim[resolvedRowAxis]];
|
|
8465
|
-
} else {
|
|
8466
|
-
width = parentMaxWidth -
|
|
8467
|
-
getMarginAxis(node, resolvedRowAxis);
|
|
8468
|
-
}
|
|
8469
|
-
width -= paddingAndBorderAxisResolvedRow;
|
|
8470
|
-
|
|
8471
|
-
// We only need to give a dimension for the text if we haven't got any
|
|
8472
|
-
// for it computed yet. It can either be from the style attribute or because
|
|
8473
|
-
// the element is flexible.
|
|
8474
|
-
var/*bool*/ isRowUndefined = !isDimDefined(node, resolvedRowAxis) && !isResolvedRowDimDefined;
|
|
8475
|
-
var/*bool*/ isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) &&
|
|
8476
|
-
isUndefined(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]]);
|
|
8477
|
-
|
|
8478
|
-
// Let's not measure the text if we already know both dimensions
|
|
8479
|
-
if (isRowUndefined || isColumnUndefined) {
|
|
8480
|
-
var/*css_dim_t*/ measureDim = node.style.measure(
|
|
8481
|
-
/*(c)!node->context,*/
|
|
8482
|
-
/*(java)!layoutContext.measureOutput,*/
|
|
8483
|
-
width
|
|
8484
|
-
);
|
|
8485
|
-
if (isRowUndefined) {
|
|
8486
|
-
node.layout.width = measureDim.width +
|
|
8487
|
-
paddingAndBorderAxisResolvedRow;
|
|
8488
|
-
}
|
|
8489
|
-
if (isColumnUndefined) {
|
|
8490
|
-
node.layout.height = measureDim.height +
|
|
8491
|
-
getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
|
|
8492
|
-
}
|
|
8493
|
-
}
|
|
8494
|
-
if (childCount === 0) {
|
|
8495
|
-
return;
|
|
8496
|
-
}
|
|
8497
|
-
}
|
|
8498
|
-
|
|
8499
|
-
var/*bool*/ isNodeFlexWrap = isFlexWrap(node);
|
|
8500
|
-
|
|
8501
|
-
var/*css_justify_t*/ justifyContent = getJustifyContent(node);
|
|
8502
|
-
|
|
8503
|
-
var/*float*/ leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis);
|
|
8504
|
-
var/*float*/ leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis);
|
|
8505
|
-
var/*float*/ paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis);
|
|
8506
|
-
var/*float*/ paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis);
|
|
8507
|
-
|
|
8508
|
-
var/*bool*/ isMainDimDefined = !isUndefined(node.layout[dim[mainAxis]]);
|
|
8509
|
-
var/*bool*/ isCrossDimDefined = !isUndefined(node.layout[dim[crossAxis]]);
|
|
8510
|
-
var/*bool*/ isMainRowDirection = isRowDirection(mainAxis);
|
|
8511
|
-
|
|
8512
|
-
var/*int*/ i;
|
|
8513
|
-
var/*int*/ ii;
|
|
8514
|
-
var/*css_node_t**/ child;
|
|
8515
|
-
var/*(c)!css_flex_direction_t*//*(java)!int*/ axis;
|
|
8516
|
-
|
|
8517
|
-
var/*css_node_t**/ firstAbsoluteChild = null;
|
|
8518
|
-
var/*css_node_t**/ currentAbsoluteChild = null;
|
|
8519
|
-
|
|
8520
|
-
var/*float*/ definedMainDim = CSS_UNDEFINED;
|
|
8521
|
-
if (isMainDimDefined) {
|
|
8522
|
-
definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain;
|
|
8523
|
-
}
|
|
8524
|
-
|
|
8525
|
-
// We want to execute the next two loops one per line with flex-wrap
|
|
8526
|
-
var/*int*/ startLine = 0;
|
|
8527
|
-
var/*int*/ endLine = 0;
|
|
8528
|
-
// var/*int*/ nextOffset = 0;
|
|
8529
|
-
var/*int*/ alreadyComputedNextLayout = 0;
|
|
8530
|
-
// We aggregate the total dimensions of the container in those two variables
|
|
8531
|
-
var/*float*/ linesCrossDim = 0;
|
|
8532
|
-
var/*float*/ linesMainDim = 0;
|
|
8533
|
-
var/*int*/ linesCount = 0;
|
|
8534
|
-
while (endLine < childCount) {
|
|
8535
|
-
// <Loop A> Layout non flexible children and count children by type
|
|
8536
|
-
|
|
8537
|
-
// mainContentDim is accumulation of the dimensions and margin of all the
|
|
8538
|
-
// non flexible children. This will be used in order to either set the
|
|
8539
|
-
// dimensions of the node if none already exist, or to compute the
|
|
8540
|
-
// remaining space left for the flexible children.
|
|
8541
|
-
var/*float*/ mainContentDim = 0;
|
|
8542
|
-
|
|
8543
|
-
// There are three kind of children, non flexible, flexible and absolute.
|
|
8544
|
-
// We need to know how many there are in order to distribute the space.
|
|
8545
|
-
var/*int*/ flexibleChildrenCount = 0;
|
|
8546
|
-
var/*float*/ totalFlexible = 0;
|
|
8547
|
-
var/*int*/ nonFlexibleChildrenCount = 0;
|
|
8548
|
-
|
|
8549
|
-
// Use the line loop to position children in the main axis for as long
|
|
8550
|
-
// as they are using a simple stacking behaviour. Children that are
|
|
8551
|
-
// immediately stacked in the initial loop will not be touched again
|
|
8552
|
-
// in <Loop C>.
|
|
8553
|
-
var/*bool*/ isSimpleStackMain =
|
|
8554
|
-
(isMainDimDefined && justifyContent === CSS_JUSTIFY_FLEX_START) ||
|
|
8555
|
-
(!isMainDimDefined && justifyContent !== CSS_JUSTIFY_CENTER);
|
|
8556
|
-
var/*int*/ firstComplexMain = (isSimpleStackMain ? childCount : startLine);
|
|
8557
|
-
|
|
8558
|
-
// Use the initial line loop to position children in the cross axis for
|
|
8559
|
-
// as long as they are relatively positioned with alignment STRETCH or
|
|
8560
|
-
// FLEX_START. Children that are immediately stacked in the initial loop
|
|
8561
|
-
// will not be touched again in <Loop D>.
|
|
8562
|
-
var/*bool*/ isSimpleStackCross = true;
|
|
8563
|
-
var/*int*/ firstComplexCross = childCount;
|
|
8564
|
-
|
|
8565
|
-
var/*css_node_t**/ firstFlexChild = null;
|
|
8566
|
-
var/*css_node_t**/ currentFlexChild = null;
|
|
8567
|
-
|
|
8568
|
-
var/*float*/ mainDim = leadingPaddingAndBorderMain;
|
|
8569
|
-
var/*float*/ crossDim = 0;
|
|
8570
|
-
|
|
8571
|
-
var/*float*/ maxWidth;
|
|
8572
|
-
for (i = startLine; i < childCount; ++i) {
|
|
8573
|
-
child = node.children[i];
|
|
8574
|
-
child.lineIndex = linesCount;
|
|
8575
|
-
|
|
8576
|
-
child.nextAbsoluteChild = null;
|
|
8577
|
-
child.nextFlexChild = null;
|
|
8578
|
-
|
|
8579
|
-
var/*css_align_t*/ alignItem = getAlignItem(node, child);
|
|
8580
|
-
|
|
8581
|
-
// Pre-fill cross axis dimensions when the child is using stretch before
|
|
8582
|
-
// we call the recursive layout pass
|
|
8583
|
-
if (alignItem === CSS_ALIGN_STRETCH &&
|
|
8584
|
-
getPositionType(child) === CSS_POSITION_RELATIVE &&
|
|
8585
|
-
isCrossDimDefined &&
|
|
8586
|
-
!isDimDefined(child, crossAxis)) {
|
|
8587
|
-
child.layout[dim[crossAxis]] = fmaxf(
|
|
8588
|
-
boundAxis(child, crossAxis, node.layout[dim[crossAxis]] -
|
|
8589
|
-
paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
|
|
8590
|
-
// You never want to go smaller than padding
|
|
8591
|
-
getPaddingAndBorderAxis(child, crossAxis)
|
|
8592
|
-
);
|
|
8593
|
-
} else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) {
|
|
8594
|
-
// Store a private linked list of absolutely positioned children
|
|
8595
|
-
// so that we can efficiently traverse them later.
|
|
8596
|
-
if (firstAbsoluteChild === null) {
|
|
8597
|
-
firstAbsoluteChild = child;
|
|
8598
|
-
}
|
|
8599
|
-
if (currentAbsoluteChild !== null) {
|
|
8600
|
-
currentAbsoluteChild.nextAbsoluteChild = child;
|
|
8601
|
-
}
|
|
8602
|
-
currentAbsoluteChild = child;
|
|
8603
|
-
|
|
8604
|
-
// Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
|
|
8605
|
-
// left and right or top and bottom).
|
|
8606
|
-
for (ii = 0; ii < 2; ii++) {
|
|
8607
|
-
axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
|
|
8608
|
-
if (!isUndefined(node.layout[dim[axis]]) &&
|
|
8609
|
-
!isDimDefined(child, axis) &&
|
|
8610
|
-
isPosDefined(child, leading[axis]) &&
|
|
8611
|
-
isPosDefined(child, trailing[axis])) {
|
|
8612
|
-
child.layout[dim[axis]] = fmaxf(
|
|
8613
|
-
boundAxis(child, axis, node.layout[dim[axis]] -
|
|
8614
|
-
getPaddingAndBorderAxis(node, axis) -
|
|
8615
|
-
getMarginAxis(child, axis) -
|
|
8616
|
-
getPosition(child, leading[axis]) -
|
|
8617
|
-
getPosition(child, trailing[axis])),
|
|
8618
|
-
// You never want to go smaller than padding
|
|
8619
|
-
getPaddingAndBorderAxis(child, axis)
|
|
8620
|
-
);
|
|
8621
|
-
}
|
|
8622
|
-
}
|
|
8623
|
-
}
|
|
8624
|
-
|
|
8625
|
-
var/*float*/ nextContentDim = 0;
|
|
8626
|
-
|
|
8627
|
-
// It only makes sense to consider a child flexible if we have a computed
|
|
8628
|
-
// dimension for the node.
|
|
8629
|
-
if (isMainDimDefined && isFlex(child)) {
|
|
8630
|
-
flexibleChildrenCount++;
|
|
8631
|
-
totalFlexible += child.style.flex;
|
|
8632
|
-
|
|
8633
|
-
// Store a private linked list of flexible children so that we can
|
|
8634
|
-
// efficiently traverse them later.
|
|
8635
|
-
if (firstFlexChild === null) {
|
|
8636
|
-
firstFlexChild = child;
|
|
8637
|
-
}
|
|
8638
|
-
if (currentFlexChild !== null) {
|
|
8639
|
-
currentFlexChild.nextFlexChild = child;
|
|
8640
|
-
}
|
|
8641
|
-
currentFlexChild = child;
|
|
8642
|
-
|
|
8643
|
-
// Even if we don't know its exact size yet, we already know the padding,
|
|
8644
|
-
// border and margin. We'll use this partial information, which represents
|
|
8645
|
-
// the smallest possible size for the child, to compute the remaining
|
|
8646
|
-
// available space.
|
|
8647
|
-
nextContentDim = getPaddingAndBorderAxis(child, mainAxis) +
|
|
8648
|
-
getMarginAxis(child, mainAxis);
|
|
8649
|
-
|
|
8650
|
-
} else {
|
|
8651
|
-
maxWidth = CSS_UNDEFINED;
|
|
8652
|
-
if (!isMainRowDirection) {
|
|
8653
|
-
if (isDimDefined(node, resolvedRowAxis)) {
|
|
8654
|
-
maxWidth = node.layout[dim[resolvedRowAxis]] -
|
|
8655
|
-
paddingAndBorderAxisResolvedRow;
|
|
8656
|
-
} else {
|
|
8657
|
-
maxWidth = parentMaxWidth -
|
|
8658
|
-
getMarginAxis(node, resolvedRowAxis) -
|
|
8659
|
-
paddingAndBorderAxisResolvedRow;
|
|
8660
|
-
}
|
|
8661
|
-
}
|
|
8662
|
-
|
|
8663
|
-
// This is the main recursive call. We layout non flexible children.
|
|
8664
|
-
if (alreadyComputedNextLayout === 0) {
|
|
8665
|
-
layoutNode(/*(java)!layoutContext, */child, maxWidth, direction);
|
|
8666
|
-
}
|
|
8667
|
-
|
|
8668
|
-
// Absolute positioned elements do not take part of the layout, so we
|
|
8669
|
-
// don't use them to compute mainContentDim
|
|
8670
|
-
if (getPositionType(child) === CSS_POSITION_RELATIVE) {
|
|
8671
|
-
nonFlexibleChildrenCount++;
|
|
8672
|
-
// At this point we know the final size and margin of the element.
|
|
8673
|
-
nextContentDim = getDimWithMargin(child, mainAxis);
|
|
8674
|
-
}
|
|
8675
|
-
}
|
|
8676
|
-
|
|
8677
|
-
// The element we are about to add would make us go to the next line
|
|
8678
|
-
if (isNodeFlexWrap &&
|
|
8679
|
-
isMainDimDefined &&
|
|
8680
|
-
mainContentDim + nextContentDim > definedMainDim &&
|
|
8681
|
-
// If there's only one element, then it's bigger than the content
|
|
8682
|
-
// and needs its own line
|
|
8683
|
-
i !== startLine) {
|
|
8684
|
-
nonFlexibleChildrenCount--;
|
|
8685
|
-
alreadyComputedNextLayout = 1;
|
|
8686
|
-
break;
|
|
8687
|
-
}
|
|
8688
|
-
|
|
8689
|
-
// Disable simple stacking in the main axis for the current line as
|
|
8690
|
-
// we found a non-trivial child. The remaining children will be laid out
|
|
8691
|
-
// in <Loop C>.
|
|
8692
|
-
if (isSimpleStackMain &&
|
|
8693
|
-
(getPositionType(child) !== CSS_POSITION_RELATIVE || isFlex(child))) {
|
|
8694
|
-
isSimpleStackMain = false;
|
|
8695
|
-
firstComplexMain = i;
|
|
8696
|
-
}
|
|
8697
|
-
|
|
8698
|
-
// Disable simple stacking in the cross axis for the current line as
|
|
8699
|
-
// we found a non-trivial child. The remaining children will be laid out
|
|
8700
|
-
// in <Loop D>.
|
|
8701
|
-
if (isSimpleStackCross &&
|
|
8702
|
-
(getPositionType(child) !== CSS_POSITION_RELATIVE ||
|
|
8703
|
-
(alignItem !== CSS_ALIGN_STRETCH && alignItem !== CSS_ALIGN_FLEX_START) ||
|
|
8704
|
-
isUndefined(child.layout[dim[crossAxis]]))) {
|
|
8705
|
-
isSimpleStackCross = false;
|
|
8706
|
-
firstComplexCross = i;
|
|
8707
|
-
}
|
|
8708
|
-
|
|
8709
|
-
if (isSimpleStackMain) {
|
|
8710
|
-
child.layout[pos[mainAxis]] += mainDim;
|
|
8711
|
-
if (isMainDimDefined) {
|
|
8712
|
-
setTrailingPosition(node, child, mainAxis);
|
|
8713
|
-
}
|
|
8714
|
-
|
|
8715
|
-
mainDim += getDimWithMargin(child, mainAxis);
|
|
8716
|
-
crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
|
|
8717
|
-
}
|
|
8718
|
-
|
|
8719
|
-
if (isSimpleStackCross) {
|
|
8720
|
-
child.layout[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross;
|
|
8721
|
-
if (isCrossDimDefined) {
|
|
8722
|
-
setTrailingPosition(node, child, crossAxis);
|
|
8723
|
-
}
|
|
8724
|
-
}
|
|
8725
|
-
|
|
8726
|
-
alreadyComputedNextLayout = 0;
|
|
8727
|
-
mainContentDim += nextContentDim;
|
|
8728
|
-
endLine = i + 1;
|
|
8729
|
-
}
|
|
8730
|
-
|
|
8731
|
-
// <Loop B> Layout flexible children and allocate empty space
|
|
8732
|
-
|
|
8733
|
-
// In order to position the elements in the main axis, we have two
|
|
8734
|
-
// controls. The space between the beginning and the first element
|
|
8735
|
-
// and the space between each two elements.
|
|
8736
|
-
var/*float*/ leadingMainDim = 0;
|
|
8737
|
-
var/*float*/ betweenMainDim = 0;
|
|
8738
|
-
|
|
8739
|
-
// The remaining available space that needs to be allocated
|
|
8740
|
-
var/*float*/ remainingMainDim = 0;
|
|
8741
|
-
if (isMainDimDefined) {
|
|
8742
|
-
remainingMainDim = definedMainDim - mainContentDim;
|
|
8743
|
-
} else {
|
|
8744
|
-
remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim;
|
|
8745
|
-
}
|
|
8746
|
-
|
|
8747
|
-
// If there are flexible children in the mix, they are going to fill the
|
|
8748
|
-
// remaining space
|
|
8749
|
-
if (flexibleChildrenCount !== 0) {
|
|
8750
|
-
var/*float*/ flexibleMainDim = remainingMainDim / totalFlexible;
|
|
8751
|
-
var/*float*/ baseMainDim;
|
|
8752
|
-
var/*float*/ boundMainDim;
|
|
8753
|
-
|
|
8754
|
-
// If the flex share of remaining space doesn't meet min/max bounds,
|
|
8755
|
-
// remove this child from flex calculations.
|
|
8756
|
-
currentFlexChild = firstFlexChild;
|
|
8757
|
-
while (currentFlexChild !== null) {
|
|
8758
|
-
baseMainDim = flexibleMainDim * currentFlexChild.style.flex +
|
|
8759
|
-
getPaddingAndBorderAxis(currentFlexChild, mainAxis);
|
|
8760
|
-
boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim);
|
|
8761
|
-
|
|
8762
|
-
if (baseMainDim !== boundMainDim) {
|
|
8763
|
-
remainingMainDim -= boundMainDim;
|
|
8764
|
-
totalFlexible -= currentFlexChild.style.flex;
|
|
8765
|
-
}
|
|
8766
|
-
|
|
8767
|
-
currentFlexChild = currentFlexChild.nextFlexChild;
|
|
8768
|
-
}
|
|
8769
|
-
flexibleMainDim = remainingMainDim / totalFlexible;
|
|
8770
|
-
|
|
8771
|
-
// The non flexible children can overflow the container, in this case
|
|
8772
|
-
// we should just assume that there is no space available.
|
|
8773
|
-
if (flexibleMainDim < 0) {
|
|
8774
|
-
flexibleMainDim = 0;
|
|
8775
|
-
}
|
|
8776
|
-
|
|
8777
|
-
currentFlexChild = firstFlexChild;
|
|
8778
|
-
while (currentFlexChild !== null) {
|
|
8779
|
-
// At this point we know the final size of the element in the main
|
|
8780
|
-
// dimension
|
|
8781
|
-
currentFlexChild.layout[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis,
|
|
8782
|
-
flexibleMainDim * currentFlexChild.style.flex +
|
|
8783
|
-
getPaddingAndBorderAxis(currentFlexChild, mainAxis)
|
|
8784
|
-
);
|
|
8785
|
-
|
|
8786
|
-
maxWidth = CSS_UNDEFINED;
|
|
8787
|
-
if (isDimDefined(node, resolvedRowAxis)) {
|
|
8788
|
-
maxWidth = node.layout[dim[resolvedRowAxis]] -
|
|
8789
|
-
paddingAndBorderAxisResolvedRow;
|
|
8790
|
-
} else if (!isMainRowDirection) {
|
|
8791
|
-
maxWidth = parentMaxWidth -
|
|
8792
|
-
getMarginAxis(node, resolvedRowAxis) -
|
|
8793
|
-
paddingAndBorderAxisResolvedRow;
|
|
8794
|
-
}
|
|
8795
|
-
|
|
8796
|
-
// And we recursively call the layout algorithm for this child
|
|
8797
|
-
layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, direction);
|
|
8798
|
-
|
|
8799
|
-
child = currentFlexChild;
|
|
8800
|
-
currentFlexChild = currentFlexChild.nextFlexChild;
|
|
8801
|
-
child.nextFlexChild = null;
|
|
8802
|
-
}
|
|
8803
|
-
|
|
8804
|
-
// We use justifyContent to figure out how to allocate the remaining
|
|
8805
|
-
// space available
|
|
8806
|
-
} else if (justifyContent !== CSS_JUSTIFY_FLEX_START) {
|
|
8807
|
-
if (justifyContent === CSS_JUSTIFY_CENTER) {
|
|
8808
|
-
leadingMainDim = remainingMainDim / 2;
|
|
8809
|
-
} else if (justifyContent === CSS_JUSTIFY_FLEX_END) {
|
|
8810
|
-
leadingMainDim = remainingMainDim;
|
|
8811
|
-
} else if (justifyContent === CSS_JUSTIFY_SPACE_BETWEEN) {
|
|
8812
|
-
remainingMainDim = fmaxf(remainingMainDim, 0);
|
|
8813
|
-
if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 !== 0) {
|
|
8814
|
-
betweenMainDim = remainingMainDim /
|
|
8815
|
-
(flexibleChildrenCount + nonFlexibleChildrenCount - 1);
|
|
8816
|
-
} else {
|
|
8817
|
-
betweenMainDim = 0;
|
|
8818
|
-
}
|
|
8819
|
-
} else if (justifyContent === CSS_JUSTIFY_SPACE_AROUND) {
|
|
8820
|
-
// Space on the edges is half of the space between elements
|
|
8821
|
-
betweenMainDim = remainingMainDim /
|
|
8822
|
-
(flexibleChildrenCount + nonFlexibleChildrenCount);
|
|
8823
|
-
leadingMainDim = betweenMainDim / 2;
|
|
8824
|
-
}
|
|
8825
|
-
}
|
|
8826
|
-
|
|
8827
|
-
// <Loop C> Position elements in the main axis and compute dimensions
|
|
8828
|
-
|
|
8829
|
-
// At this point, all the children have their dimensions set. We need to
|
|
8830
|
-
// find their position. In order to do that, we accumulate data in
|
|
8831
|
-
// variables that are also useful to compute the total dimensions of the
|
|
8832
|
-
// container!
|
|
8833
|
-
mainDim += leadingMainDim;
|
|
8834
|
-
|
|
8835
|
-
for (i = firstComplexMain; i < endLine; ++i) {
|
|
8836
|
-
child = node.children[i];
|
|
8837
|
-
|
|
8838
|
-
if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&
|
|
8839
|
-
isPosDefined(child, leading[mainAxis])) {
|
|
8840
|
-
// In case the child is position absolute and has left/top being
|
|
8841
|
-
// defined, we override the position to whatever the user said
|
|
8842
|
-
// (and margin/border).
|
|
8843
|
-
child.layout[pos[mainAxis]] = getPosition(child, leading[mainAxis]) +
|
|
8844
|
-
getLeadingBorder(node, mainAxis) +
|
|
8845
|
-
getLeadingMargin(child, mainAxis);
|
|
8846
|
-
} else {
|
|
8847
|
-
// If the child is position absolute (without top/left) or relative,
|
|
8848
|
-
// we put it at the current accumulated offset.
|
|
8849
|
-
child.layout[pos[mainAxis]] += mainDim;
|
|
8850
|
-
|
|
8851
|
-
// Define the trailing position accordingly.
|
|
8852
|
-
if (isMainDimDefined) {
|
|
8853
|
-
setTrailingPosition(node, child, mainAxis);
|
|
8854
|
-
}
|
|
8855
|
-
|
|
8856
|
-
// Now that we placed the element, we need to update the variables
|
|
8857
|
-
// We only need to do that for relative elements. Absolute elements
|
|
8858
|
-
// do not take part in that phase.
|
|
8859
|
-
if (getPositionType(child) === CSS_POSITION_RELATIVE) {
|
|
8860
|
-
// The main dimension is the sum of all the elements dimension plus
|
|
8861
|
-
// the spacing.
|
|
8862
|
-
mainDim += betweenMainDim + getDimWithMargin(child, mainAxis);
|
|
8863
|
-
// The cross dimension is the max of the elements dimension since there
|
|
8864
|
-
// can only be one element in that cross dimension.
|
|
8865
|
-
crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
|
|
8866
|
-
}
|
|
8867
|
-
}
|
|
8868
|
-
}
|
|
8869
|
-
|
|
8870
|
-
var/*float*/ containerCrossAxis = node.layout[dim[crossAxis]];
|
|
8871
|
-
if (!isCrossDimDefined) {
|
|
8872
|
-
containerCrossAxis = fmaxf(
|
|
8873
|
-
// For the cross dim, we add both sides at the end because the value
|
|
8874
|
-
// is aggregate via a max function. Intermediate negative values
|
|
8875
|
-
// can mess this computation otherwise
|
|
8876
|
-
boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross),
|
|
8877
|
-
paddingAndBorderAxisCross
|
|
8878
|
-
);
|
|
8879
|
-
}
|
|
8880
|
-
|
|
8881
|
-
// <Loop D> Position elements in the cross axis
|
|
8882
|
-
for (i = firstComplexCross; i < endLine; ++i) {
|
|
8883
|
-
child = node.children[i];
|
|
8884
|
-
|
|
8885
|
-
if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&
|
|
8886
|
-
isPosDefined(child, leading[crossAxis])) {
|
|
8887
|
-
// In case the child is absolutely positionned and has a
|
|
8888
|
-
// top/left/bottom/right being set, we override all the previously
|
|
8889
|
-
// computed positions to set it correctly.
|
|
8890
|
-
child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]) +
|
|
8891
|
-
getLeadingBorder(node, crossAxis) +
|
|
8892
|
-
getLeadingMargin(child, crossAxis);
|
|
8893
|
-
|
|
8894
|
-
} else {
|
|
8895
|
-
var/*float*/ leadingCrossDim = leadingPaddingAndBorderCross;
|
|
8896
|
-
|
|
8897
|
-
// For a relative children, we're either using alignItems (parent) or
|
|
8898
|
-
// alignSelf (child) in order to determine the position in the cross axis
|
|
8899
|
-
if (getPositionType(child) === CSS_POSITION_RELATIVE) {
|
|
8900
|
-
/*eslint-disable */
|
|
8901
|
-
// This variable is intentionally re-defined as the code is transpiled to a block scope language
|
|
8902
|
-
var/*css_align_t*/ alignItem = getAlignItem(node, child);
|
|
8903
|
-
/*eslint-enable */
|
|
8904
|
-
if (alignItem === CSS_ALIGN_STRETCH) {
|
|
8905
|
-
// You can only stretch if the dimension has not already been set
|
|
8906
|
-
// previously.
|
|
8907
|
-
if (isUndefined(child.layout[dim[crossAxis]])) {
|
|
8908
|
-
child.layout[dim[crossAxis]] = fmaxf(
|
|
8909
|
-
boundAxis(child, crossAxis, containerCrossAxis -
|
|
8910
|
-
paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
|
|
8911
|
-
// You never want to go smaller than padding
|
|
8912
|
-
getPaddingAndBorderAxis(child, crossAxis)
|
|
8913
|
-
);
|
|
8914
|
-
}
|
|
8915
|
-
} else if (alignItem !== CSS_ALIGN_FLEX_START) {
|
|
8916
|
-
// The remaining space between the parent dimensions+padding and child
|
|
8917
|
-
// dimensions+margin.
|
|
8918
|
-
var/*float*/ remainingCrossDim = containerCrossAxis -
|
|
8919
|
-
paddingAndBorderAxisCross - getDimWithMargin(child, crossAxis);
|
|
8920
|
-
|
|
8921
|
-
if (alignItem === CSS_ALIGN_CENTER) {
|
|
8922
|
-
leadingCrossDim += remainingCrossDim / 2;
|
|
8923
|
-
} else { // CSS_ALIGN_FLEX_END
|
|
8924
|
-
leadingCrossDim += remainingCrossDim;
|
|
8925
|
-
}
|
|
8926
|
-
}
|
|
8927
|
-
}
|
|
8928
|
-
|
|
8929
|
-
// And we apply the position
|
|
8930
|
-
child.layout[pos[crossAxis]] += linesCrossDim + leadingCrossDim;
|
|
8931
|
-
|
|
8932
|
-
// Define the trailing position accordingly.
|
|
8933
|
-
if (isCrossDimDefined) {
|
|
8934
|
-
setTrailingPosition(node, child, crossAxis);
|
|
8935
|
-
}
|
|
8936
|
-
}
|
|
8937
|
-
}
|
|
8938
|
-
|
|
8939
|
-
linesCrossDim += crossDim;
|
|
8940
|
-
linesMainDim = fmaxf(linesMainDim, mainDim);
|
|
8941
|
-
linesCount += 1;
|
|
8942
|
-
startLine = endLine;
|
|
8943
|
-
}
|
|
8944
|
-
|
|
8945
|
-
// <Loop E>
|
|
8946
|
-
//
|
|
8947
|
-
// Note(prenaux): More than one line, we need to layout the crossAxis
|
|
8948
|
-
// according to alignContent.
|
|
8949
|
-
//
|
|
8950
|
-
// Note that we could probably remove <Loop D> and handle the one line case
|
|
8951
|
-
// here too, but for the moment this is safer since it won't interfere with
|
|
8952
|
-
// previously working code.
|
|
8953
|
-
//
|
|
8954
|
-
// See specs:
|
|
8955
|
-
// http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm
|
|
8956
|
-
// section 9.4
|
|
8957
|
-
//
|
|
8958
|
-
if (linesCount > 1 && isCrossDimDefined) {
|
|
8959
|
-
var/*float*/ nodeCrossAxisInnerSize = node.layout[dim[crossAxis]] -
|
|
8960
|
-
paddingAndBorderAxisCross;
|
|
8961
|
-
var/*float*/ remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;
|
|
8962
|
-
|
|
8963
|
-
var/*float*/ crossDimLead = 0;
|
|
8964
|
-
var/*float*/ currentLead = leadingPaddingAndBorderCross;
|
|
8965
|
-
|
|
8966
|
-
var/*css_align_t*/ alignContent = getAlignContent(node);
|
|
8967
|
-
if (alignContent === CSS_ALIGN_FLEX_END) {
|
|
8968
|
-
currentLead += remainingAlignContentDim;
|
|
8969
|
-
} else if (alignContent === CSS_ALIGN_CENTER) {
|
|
8970
|
-
currentLead += remainingAlignContentDim / 2;
|
|
8971
|
-
} else if (alignContent === CSS_ALIGN_STRETCH) {
|
|
8972
|
-
if (nodeCrossAxisInnerSize > linesCrossDim) {
|
|
8973
|
-
crossDimLead = (remainingAlignContentDim / linesCount);
|
|
8974
|
-
}
|
|
8975
|
-
}
|
|
8976
|
-
|
|
8977
|
-
var/*int*/ endIndex = 0;
|
|
8978
|
-
for (i = 0; i < linesCount; ++i) {
|
|
8979
|
-
var/*int*/ startIndex = endIndex;
|
|
8980
|
-
|
|
8981
|
-
// compute the line's height and find the endIndex
|
|
8982
|
-
var/*float*/ lineHeight = 0;
|
|
8983
|
-
for (ii = startIndex; ii < childCount; ++ii) {
|
|
8984
|
-
child = node.children[ii];
|
|
8985
|
-
if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
|
|
8986
|
-
continue;
|
|
8987
|
-
}
|
|
8988
|
-
if (child.lineIndex !== i) {
|
|
8989
|
-
break;
|
|
8990
|
-
}
|
|
8991
|
-
if (!isUndefined(child.layout[dim[crossAxis]])) {
|
|
8992
|
-
lineHeight = fmaxf(
|
|
8993
|
-
lineHeight,
|
|
8994
|
-
child.layout[dim[crossAxis]] + getMarginAxis(child, crossAxis)
|
|
8995
|
-
);
|
|
8996
|
-
}
|
|
8997
|
-
}
|
|
8998
|
-
endIndex = ii;
|
|
8999
|
-
lineHeight += crossDimLead;
|
|
9000
|
-
|
|
9001
|
-
for (ii = startIndex; ii < endIndex; ++ii) {
|
|
9002
|
-
child = node.children[ii];
|
|
9003
|
-
if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
|
|
9004
|
-
continue;
|
|
9005
|
-
}
|
|
9006
|
-
|
|
9007
|
-
var/*css_align_t*/ alignContentAlignItem = getAlignItem(node, child);
|
|
9008
|
-
if (alignContentAlignItem === CSS_ALIGN_FLEX_START) {
|
|
9009
|
-
child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
|
|
9010
|
-
} else if (alignContentAlignItem === CSS_ALIGN_FLEX_END) {
|
|
9011
|
-
child.layout[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child.layout[dim[crossAxis]];
|
|
9012
|
-
} else if (alignContentAlignItem === CSS_ALIGN_CENTER) {
|
|
9013
|
-
var/*float*/ childHeight = child.layout[dim[crossAxis]];
|
|
9014
|
-
child.layout[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2;
|
|
9015
|
-
} else if (alignContentAlignItem === CSS_ALIGN_STRETCH) {
|
|
9016
|
-
child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
|
|
9017
|
-
// TODO(prenaux): Correctly set the height of items with undefined
|
|
9018
|
-
// (auto) crossAxis dimension.
|
|
9019
|
-
}
|
|
9020
|
-
}
|
|
9021
|
-
|
|
9022
|
-
currentLead += lineHeight;
|
|
9023
|
-
}
|
|
9024
|
-
}
|
|
9025
|
-
|
|
9026
|
-
var/*bool*/ needsMainTrailingPos = false;
|
|
9027
|
-
var/*bool*/ needsCrossTrailingPos = false;
|
|
9028
|
-
|
|
9029
|
-
// If the user didn't specify a width or height, and it has not been set
|
|
9030
|
-
// by the container, then we set it via the children.
|
|
9031
|
-
if (!isMainDimDefined) {
|
|
9032
|
-
node.layout[dim[mainAxis]] = fmaxf(
|
|
9033
|
-
// We're missing the last padding at this point to get the final
|
|
9034
|
-
// dimension
|
|
9035
|
-
boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)),
|
|
9036
|
-
// We can never assign a width smaller than the padding and borders
|
|
9037
|
-
paddingAndBorderAxisMain
|
|
9038
|
-
);
|
|
9039
|
-
|
|
9040
|
-
if (mainAxis === CSS_FLEX_DIRECTION_ROW_REVERSE ||
|
|
9041
|
-
mainAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
|
|
9042
|
-
needsMainTrailingPos = true;
|
|
9043
|
-
}
|
|
9044
|
-
}
|
|
9045
|
-
|
|
9046
|
-
if (!isCrossDimDefined) {
|
|
9047
|
-
node.layout[dim[crossAxis]] = fmaxf(
|
|
9048
|
-
// For the cross dim, we add both sides at the end because the value
|
|
9049
|
-
// is aggregate via a max function. Intermediate negative values
|
|
9050
|
-
// can mess this computation otherwise
|
|
9051
|
-
boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross),
|
|
9052
|
-
paddingAndBorderAxisCross
|
|
9053
|
-
);
|
|
9054
|
-
|
|
9055
|
-
if (crossAxis === CSS_FLEX_DIRECTION_ROW_REVERSE ||
|
|
9056
|
-
crossAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
|
|
9057
|
-
needsCrossTrailingPos = true;
|
|
9058
|
-
}
|
|
9059
|
-
}
|
|
9060
|
-
|
|
9061
|
-
// <Loop F> Set trailing position if necessary
|
|
9062
|
-
if (needsMainTrailingPos || needsCrossTrailingPos) {
|
|
9063
|
-
for (i = 0; i < childCount; ++i) {
|
|
9064
|
-
child = node.children[i];
|
|
9065
|
-
|
|
9066
|
-
if (needsMainTrailingPos) {
|
|
9067
|
-
setTrailingPosition(node, child, mainAxis);
|
|
9068
|
-
}
|
|
9069
|
-
|
|
9070
|
-
if (needsCrossTrailingPos) {
|
|
9071
|
-
setTrailingPosition(node, child, crossAxis);
|
|
9072
|
-
}
|
|
9073
|
-
}
|
|
9074
|
-
}
|
|
9075
|
-
|
|
9076
|
-
// <Loop G> Calculate dimensions for absolutely positioned elements
|
|
9077
|
-
currentAbsoluteChild = firstAbsoluteChild;
|
|
9078
|
-
while (currentAbsoluteChild !== null) {
|
|
9079
|
-
// Pre-fill dimensions when using absolute position and both offsets for
|
|
9080
|
-
// the axis are defined (either both left and right or top and bottom).
|
|
9081
|
-
for (ii = 0; ii < 2; ii++) {
|
|
9082
|
-
axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
|
|
9083
|
-
|
|
9084
|
-
if (!isUndefined(node.layout[dim[axis]]) &&
|
|
9085
|
-
!isDimDefined(currentAbsoluteChild, axis) &&
|
|
9086
|
-
isPosDefined(currentAbsoluteChild, leading[axis]) &&
|
|
9087
|
-
isPosDefined(currentAbsoluteChild, trailing[axis])) {
|
|
9088
|
-
currentAbsoluteChild.layout[dim[axis]] = fmaxf(
|
|
9089
|
-
boundAxis(currentAbsoluteChild, axis, node.layout[dim[axis]] -
|
|
9090
|
-
getBorderAxis(node, axis) -
|
|
9091
|
-
getMarginAxis(currentAbsoluteChild, axis) -
|
|
9092
|
-
getPosition(currentAbsoluteChild, leading[axis]) -
|
|
9093
|
-
getPosition(currentAbsoluteChild, trailing[axis])
|
|
9094
|
-
),
|
|
9095
|
-
// You never want to go smaller than padding
|
|
9096
|
-
getPaddingAndBorderAxis(currentAbsoluteChild, axis)
|
|
9097
|
-
);
|
|
9098
|
-
}
|
|
9099
|
-
|
|
9100
|
-
if (isPosDefined(currentAbsoluteChild, trailing[axis]) &&
|
|
9101
|
-
!isPosDefined(currentAbsoluteChild, leading[axis])) {
|
|
9102
|
-
currentAbsoluteChild.layout[leading[axis]] =
|
|
9103
|
-
node.layout[dim[axis]] -
|
|
9104
|
-
currentAbsoluteChild.layout[dim[axis]] -
|
|
9105
|
-
getPosition(currentAbsoluteChild, trailing[axis]);
|
|
9106
|
-
}
|
|
9107
|
-
}
|
|
9108
|
-
|
|
9109
|
-
child = currentAbsoluteChild;
|
|
9110
|
-
currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild;
|
|
9111
|
-
child.nextAbsoluteChild = null;
|
|
9112
|
-
}
|
|
9113
|
-
}
|
|
9114
|
-
|
|
9115
|
-
function layoutNode(node, parentMaxWidth, parentDirection) {
|
|
9116
|
-
node.shouldUpdate = true;
|
|
9117
|
-
|
|
9118
|
-
var direction = node.style.direction || CSS_DIRECTION_LTR;
|
|
9119
|
-
var skipLayout =
|
|
9120
|
-
!node.isDirty &&
|
|
9121
|
-
node.lastLayout &&
|
|
9122
|
-
node.lastLayout.requestedHeight === node.layout.height &&
|
|
9123
|
-
node.lastLayout.requestedWidth === node.layout.width &&
|
|
9124
|
-
node.lastLayout.parentMaxWidth === parentMaxWidth &&
|
|
9125
|
-
node.lastLayout.direction === direction;
|
|
9126
|
-
|
|
9127
|
-
if (skipLayout) {
|
|
9128
|
-
node.layout.width = node.lastLayout.width;
|
|
9129
|
-
node.layout.height = node.lastLayout.height;
|
|
9130
|
-
node.layout.top = node.lastLayout.top;
|
|
9131
|
-
node.layout.left = node.lastLayout.left;
|
|
9132
|
-
} else {
|
|
9133
|
-
if (!node.lastLayout) {
|
|
9134
|
-
node.lastLayout = {};
|
|
9135
|
-
}
|
|
9136
|
-
|
|
9137
|
-
node.lastLayout.requestedWidth = node.layout.width;
|
|
9138
|
-
node.lastLayout.requestedHeight = node.layout.height;
|
|
9139
|
-
node.lastLayout.parentMaxWidth = parentMaxWidth;
|
|
9140
|
-
node.lastLayout.direction = direction;
|
|
9141
|
-
|
|
9142
|
-
// Reset child layouts
|
|
9143
|
-
node.children.forEach(function(child) {
|
|
9144
|
-
child.layout.width = undefined;
|
|
9145
|
-
child.layout.height = undefined;
|
|
9146
|
-
child.layout.top = 0;
|
|
9147
|
-
child.layout.left = 0;
|
|
9148
|
-
});
|
|
9149
|
-
|
|
9150
|
-
layoutNodeImpl(node, parentMaxWidth, parentDirection);
|
|
9151
|
-
|
|
9152
|
-
node.lastLayout.width = node.layout.width;
|
|
9153
|
-
node.lastLayout.height = node.layout.height;
|
|
9154
|
-
node.lastLayout.top = node.layout.top;
|
|
9155
|
-
node.lastLayout.left = node.layout.left;
|
|
9156
|
-
}
|
|
9157
|
-
}
|
|
9158
|
-
|
|
9159
|
-
return {
|
|
9160
|
-
layoutNodeImpl: layoutNodeImpl,
|
|
9161
|
-
computeLayout: layoutNode,
|
|
9162
|
-
fillNodes: fillNodes
|
|
9163
|
-
};
|
|
9164
|
-
})();
|
|
9165
|
-
|
|
9166
|
-
// This module export is only used for the purposes of unit testing this file. When
|
|
9167
|
-
// the library is packaged this file is included within css-layout.js which forms
|
|
9168
|
-
// the public API.
|
|
9169
|
-
{
|
|
9170
|
-
module.exports = computeLayout;
|
|
9171
|
-
}
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
return function(node) {
|
|
9175
|
-
/*eslint-disable */
|
|
9176
|
-
// disabling ESLint because this code relies on the above include
|
|
9177
|
-
computeLayout.fillNodes(node);
|
|
9178
|
-
computeLayout.computeLayout(node);
|
|
9179
|
-
/*eslint-enable */
|
|
9180
|
-
};
|
|
9181
|
-
}));
|
|
9182
|
-
} (cssLayout));
|
|
9183
|
-
|
|
9184
|
-
var cssLayoutExports = cssLayout.exports;
|
|
9185
|
-
|
|
9186
|
-
function _interopDefault$1(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=_interopDefault$1(React$1),reactDom=require$$0,computeLayout=_interopDefault$1(cssLayoutExports);function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){_defineProperty(e,t,r[t]);});}return e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n);}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),e}function _typeof2(e){return (_typeof2="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _typeof(e){return (_typeof="function"==typeof Symbol&&"symbol"===_typeof2(Symbol.iterator)?function(e){return _typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":_typeof2(e)})(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return !t||"object"!==_typeof(t)&&"function"!=typeof t?_assertThisInitialized(e):t}function _getPrototypeOf(e){return (_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return (_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t);}var Flexbox=function(e){function t(){var e;return _classCallCheck(this,t),(e=_possibleConstructorReturn(this,_getPrototypeOf(t).call(this))).childRefs=[],e.shouldUpdateAgain=!1,e.state={layout:{children:[]}},e}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.forceUpdate();}},{key:"componentDidUpdate",value:function(){if(this.shouldUpdateAgain=!this.shouldUpdateAgain,this.shouldUpdateAgain){var e=this.props,t=e.children,r=e.onLayout,n=e.style,o=this.getChildrenMeasured(this.childRefs),i=this.getFlattenedChildren(t),u=this.getChildrenAsMergedStyles(i,o),c=this.getComputedLayout(u,n);r(c),this.setState({layout:c});}}},{key:"getFlattenedChildren",value:function(e){return e.filter(function(e){return e}).filter(function(e){return "string"!=typeof e}).map(function(e){return Array.isArray(e)?e:[e]}).reduce(function(e,t){return e.concat(t)},[])}},{key:"getChildrenAsMergedStyles",value:function(e,t){return t.map(function(t,r){var n=e[r]||{},o=n&&n.props?n.props.style:{};return {style:_objectSpread({},o,{height:t.height||o.height,width:t.width||o.width})}})}},{key:"getChildrenMeasured",value:function(e){return e&&e.length?e.map(function(e){return e.getBBox?e.getBBox():reactDom.findDOMNode(e).getBBox()}):[]}},{key:"getComputedLayout",value:function(e,t){var r={children:Array.from(e||[]),style:_objectSpread({},t)};return computeLayout(r),r}},{key:"getLayoutChildren",value:function(e){return e&&e.children&&e.children.length?e.children:[]}},{key:"getLayoutAttributesForChild",value:function(e,t){if(t&&t.layout){var r=t.layout,n=r.left,o=r.top;switch(e.type){case"circle":var i=e.props.r||0;return {cx:n+i,cy:o+i};case"ellipse":return {cx:n+(e.props.rx||0),cy:o+(e.props.ry||0)};case"g":case"path":case"polygon":case"polyline":return {transform:"translate(".concat(n," ").concat(o,")")};default:return {x:n,y:o}}}return {}}},{key:"render",value:function(){var e=this,t=this.props,r=t.children,n=t.className,o=t.x,i=t.y,u=this.state.layout;this.childRefs=[];var c=this.getFlattenedChildren(r),a=this.getLayoutChildren(u);return React.createElement("g",{className:n,transform:"translate(".concat(o," ").concat(i,")")},c.map(function(t,r){return React.cloneElement(t,_objectSpread({},t.props,e.getLayoutAttributesForChild(t,a[r]),{key:"child-".concat(r),ref:function(t){return t?e.childRefs.push(t):null}}))}))}}]),t}();Flexbox.defaultProps={children:[],className:null,onLayout:function(){},style:{},x:0,y:0},bundle.exports=Flexbox;
|
|
9187
|
-
|
|
9188
|
-
var bundleExports = bundle.exports;
|
|
9189
|
-
var Flexbox$1 = /*@__PURE__*/getDefaultExportFromCjs(bundleExports);
|
|
9190
|
-
|
|
9191
8021
|
var Element = function (props) {
|
|
9192
|
-
var _a, _b
|
|
9193
|
-
var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, cssClass = props.cssClass, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container
|
|
9194
|
-
var
|
|
9195
|
-
var
|
|
9196
|
-
var
|
|
9197
|
-
var
|
|
9198
|
-
var
|
|
9199
|
-
var
|
|
9200
|
-
var
|
|
9201
|
-
var
|
|
9202
|
-
var
|
|
9203
|
-
|
|
9204
|
-
|
|
8022
|
+
var _a, _b;
|
|
8023
|
+
var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, cssClass = props.cssClass, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container; props.textsPlaceHolderFlexStyle; props.textsPlaceHolderFlexboxPosition; props.textsPlaceHolderClassName; var texts = props.texts, portSlideRailSVGClassName = props.portSlideRailSVGClassName, portMoveableAreas = props.portMoveableAreas, portDirection = props.portDirection, defaultPortSize = props.defaultPortSize, onClick = props.onClick, onContextMenu = props.onContextMenu, renderShape = props.renderShape; props.onMoved; var onPortMoved = props.onPortMoved; props.onResized; var onPortMouseDown = props.onPortMouseDown, onPortMouseUp = props.onPortMouseUp, onMouseMove = props.onMouseMove, onMouseLeave = props.onMouseLeave, onMouseUp = props.onMouseUp, onMouseUpAtLinkedPortPlaceholder = props.onMouseUpAtLinkedPortPlaceholder, onTextUpdated = props.onTextUpdated;
|
|
8024
|
+
var _c = React.useState(), selectedPort = _c[0], setSelectedPort = _c[1];
|
|
8025
|
+
var _d = React.useState(), hoveredPort = _d[0], setHoveredPort = _d[1];
|
|
8026
|
+
var _e = React.useState([]), ports = _e[0], setPorts = _e[1];
|
|
8027
|
+
var _f = React.useState(false), someElementLinkStarted = _f[0], setSomeElementLinkStarted = _f[1];
|
|
8028
|
+
var _g = React.useState(), potentialPortPosition = _g[0], setPotentialPortPosition = _g[1];
|
|
8029
|
+
var _paperEventEmitterContext = React.useContext(paperEventEmitterContext);
|
|
8030
|
+
var elementRef = React.useRef(null);
|
|
8031
|
+
var elementLinkStarted = React.useRef();
|
|
8032
|
+
var portsRef = React.useRef(ports);
|
|
8033
|
+
React.useEffect(function () {
|
|
8034
|
+
console.log('changed props.children', texts === null || texts === void 0 ? void 0 : texts[0].content);
|
|
8035
|
+
}, [props.children]);
|
|
8036
|
+
React.useEffect(function () {
|
|
9205
8037
|
return function () {
|
|
9206
8038
|
var _a;
|
|
9207
8039
|
console.log('un mount', (_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content);
|
|
9208
8040
|
};
|
|
9209
8041
|
}, []);
|
|
9210
8042
|
//Listen to manually trigger render event
|
|
9211
|
-
React
|
|
9212
|
-
var
|
|
8043
|
+
React.useEffect(function () {
|
|
8044
|
+
var _a;
|
|
8045
|
+
var off = (_a = props.onManuallyTriggerRenderPort) === null || _a === void 0 ? void 0 : _a.call(props, function (portId, elementId) {
|
|
9213
8046
|
if (elementId !== id)
|
|
9214
8047
|
return;
|
|
9215
8048
|
console.log('onManuallyTriggerRenderPort', id);
|
|
9216
8049
|
setPorts(function (prev) { return __spreadArray([], prev, true); });
|
|
9217
8050
|
});
|
|
9218
8051
|
return function () {
|
|
9219
|
-
off();
|
|
8052
|
+
off === null || off === void 0 ? void 0 : off();
|
|
9220
8053
|
};
|
|
9221
8054
|
}, [props.onManuallyTriggerRenderPort]);
|
|
9222
8055
|
//Update portsRef when ports changed
|
|
9223
|
-
React
|
|
8056
|
+
React.useEffect(function () {
|
|
9224
8057
|
portsRef.current = ports;
|
|
9225
8058
|
}, [ports]);
|
|
9226
|
-
React
|
|
8059
|
+
React.useEffect(function () {
|
|
9227
8060
|
var _a;
|
|
9228
8061
|
console.info('Rendering Element ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content) || id);
|
|
9229
8062
|
});
|
|
9230
8063
|
//Listen a new port is created, after add new port to ports state
|
|
9231
|
-
React
|
|
8064
|
+
React.useEffect(function () {
|
|
9232
8065
|
console.info('Ports changed', props.ports);
|
|
9233
8066
|
setPorts(function (prev) {
|
|
9234
8067
|
var _a, _b;
|
|
@@ -9248,14 +8081,14 @@ var Element = function (props) {
|
|
|
9248
8081
|
onPortMoved === null || onPortMoved === void 0 ? void 0 : onPortMoved(p, id, newPortState.position, newPosition);
|
|
9249
8082
|
_paperEventEmitterContext.emitPortMoved(p, id, newPortState.position, newPosition);
|
|
9250
8083
|
newPortState.position = newPosition;
|
|
9251
|
-
newPortState.ref = React
|
|
8084
|
+
newPortState.ref = React.createRef();
|
|
9252
8085
|
}
|
|
9253
8086
|
return newPortState;
|
|
9254
8087
|
})) !== null && _b !== void 0 ? _b : [];
|
|
9255
8088
|
});
|
|
9256
8089
|
}, [props.ports]);
|
|
9257
8090
|
//Listen trigger of Delete key, handle delete port is selected
|
|
9258
|
-
React
|
|
8091
|
+
React.useEffect(function () {
|
|
9259
8092
|
var listener = _paperEventEmitterContext.onCommandDeleteSelectedPort(function () {
|
|
9260
8093
|
if (selectedPort) {
|
|
9261
8094
|
setPorts(function (prev) { return prev.filter(function (p) { return p.id !== selectedPort.id; }); });
|
|
@@ -9266,7 +8099,7 @@ var Element = function (props) {
|
|
|
9266
8099
|
listener.off();
|
|
9267
8100
|
};
|
|
9268
8101
|
}, [selectedPort]);
|
|
9269
|
-
React
|
|
8102
|
+
React.useEffect(function () {
|
|
9270
8103
|
//Listener onMouseDown event on #paper-container
|
|
9271
8104
|
var eventListener = _paperEventEmitterContext.onPaperClicked(function (ev) {
|
|
9272
8105
|
setSelectedPort(undefined);
|
|
@@ -9290,7 +8123,7 @@ var Element = function (props) {
|
|
|
9290
8123
|
};
|
|
9291
8124
|
}, [onPortMoved]);
|
|
9292
8125
|
//Listen creating element link started, ended.
|
|
9293
|
-
React
|
|
8126
|
+
React.useEffect(function () {
|
|
9294
8127
|
var elementStartedListener = _paperEventEmitterContext.onElementLinkStarted(function (tempLink) {
|
|
9295
8128
|
elementLinkStarted.current = tempLink;
|
|
9296
8129
|
setSomeElementLinkStarted(true);
|
|
@@ -9307,7 +8140,7 @@ var Element = function (props) {
|
|
|
9307
8140
|
};
|
|
9308
8141
|
}, []);
|
|
9309
8142
|
//Listen another port is selected
|
|
9310
|
-
React
|
|
8143
|
+
React.useEffect(function () {
|
|
9311
8144
|
var portSelectedListener = _paperEventEmitterContext.onPortSelected(function (port, elementId) {
|
|
9312
8145
|
if (elementId !== id) {
|
|
9313
8146
|
setSelectedPort(undefined);
|
|
@@ -9318,7 +8151,7 @@ var Element = function (props) {
|
|
|
9318
8151
|
};
|
|
9319
8152
|
}, []);
|
|
9320
8153
|
//Listen text is selected
|
|
9321
|
-
React
|
|
8154
|
+
React.useEffect(function () {
|
|
9322
8155
|
var textSelectedListener = _paperEventEmitterContext.onTextSelected(function (text) {
|
|
9323
8156
|
setSelectedPort(undefined);
|
|
9324
8157
|
});
|
|
@@ -9327,7 +8160,7 @@ var Element = function (props) {
|
|
|
9327
8160
|
};
|
|
9328
8161
|
}, []);
|
|
9329
8162
|
//Listen another element is selected
|
|
9330
|
-
React
|
|
8163
|
+
React.useEffect(function () {
|
|
9331
8164
|
var portSelectedListener = _paperEventEmitterContext.onElementSelected(function (element) {
|
|
9332
8165
|
setSelectedPort(undefined);
|
|
9333
8166
|
});
|
|
@@ -9335,7 +8168,7 @@ var Element = function (props) {
|
|
|
9335
8168
|
portSelectedListener.off();
|
|
9336
8169
|
};
|
|
9337
8170
|
}, []);
|
|
9338
|
-
var handleSelectedPort = React
|
|
8171
|
+
var handleSelectedPort = React.useCallback(function (portId, e) {
|
|
9339
8172
|
e.stopPropagation();
|
|
9340
8173
|
var port = portsRef.current.find(function (p) { return p.id === portId; });
|
|
9341
8174
|
if (!port)
|
|
@@ -9377,7 +8210,7 @@ var Element = function (props) {
|
|
|
9377
8210
|
}
|
|
9378
8211
|
return coordinates;
|
|
9379
8212
|
};
|
|
9380
|
-
var getSlideRailSVG = React
|
|
8213
|
+
var getSlideRailSVG = React.useCallback(function (portSlideRailSVGClassName) {
|
|
9381
8214
|
var _a;
|
|
9382
8215
|
var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
|
|
9383
8216
|
return slideRailSVG;
|
|
@@ -9442,7 +8275,7 @@ var Element = function (props) {
|
|
|
9442
8275
|
}
|
|
9443
8276
|
};
|
|
9444
8277
|
//Handle when mouse down on port
|
|
9445
|
-
var handlePortMouseDown = React
|
|
8278
|
+
var handlePortMouseDown = React.useCallback(function (portId, e) {
|
|
9446
8279
|
e.stopPropagation();
|
|
9447
8280
|
var port = portsRef.current.find(function (p) { return p.id === portId; });
|
|
9448
8281
|
if (!port)
|
|
@@ -9451,7 +8284,7 @@ var Element = function (props) {
|
|
|
9451
8284
|
onPortMouseDown === null || onPortMouseDown === void 0 ? void 0 : onPortMouseDown(e, port, id);
|
|
9452
8285
|
}, [_paperEventEmitterContext]);
|
|
9453
8286
|
//Handle when mouse up on port
|
|
9454
|
-
var handlePortMouseUp = React
|
|
8287
|
+
var handlePortMouseUp = React.useCallback(function (portId, e) {
|
|
9455
8288
|
e.stopPropagation();
|
|
9456
8289
|
var port = portsRef.current.find(function (p) { return p.id === portId; });
|
|
9457
8290
|
if (!port)
|
|
@@ -9464,7 +8297,7 @@ var Element = function (props) {
|
|
|
9464
8297
|
}
|
|
9465
8298
|
}, [_paperEventEmitterContext, potentialPortPosition]);
|
|
9466
8299
|
//Update state when label of port is moved
|
|
9467
|
-
var handlePortLabelMoved = React
|
|
8300
|
+
var handlePortLabelMoved = React.useCallback(function (offsetX, offsetY, portId) {
|
|
9468
8301
|
setPorts(function (prevPorts) {
|
|
9469
8302
|
return prevPorts.map(function (p) {
|
|
9470
8303
|
if (p.id === portId && p.label) {
|
|
@@ -9479,7 +8312,7 @@ var Element = function (props) {
|
|
|
9479
8312
|
});
|
|
9480
8313
|
}, []);
|
|
9481
8314
|
//Update state when label of port is resized
|
|
9482
|
-
var handlePortLabelResized = React
|
|
8315
|
+
var handlePortLabelResized = React.useCallback(function (width, height, portId) {
|
|
9483
8316
|
setPorts(function (prevPorts) {
|
|
9484
8317
|
return prevPorts.map(function (p) {
|
|
9485
8318
|
if (p.id === portId && p.label) {
|
|
@@ -9493,7 +8326,7 @@ var Element = function (props) {
|
|
|
9493
8326
|
});
|
|
9494
8327
|
}, []);
|
|
9495
8328
|
//Update state when label of port is changed content
|
|
9496
|
-
var handlePortLabelContentChanged = React
|
|
8329
|
+
var handlePortLabelContentChanged = React.useCallback(function (ev, newValue, portId) {
|
|
9497
8330
|
setPorts(function (prevPorts) {
|
|
9498
8331
|
return prevPorts.map(function (p) {
|
|
9499
8332
|
if (p.id === portId && p.label) {
|
|
@@ -9505,6 +8338,7 @@ var Element = function (props) {
|
|
|
9505
8338
|
}, []);
|
|
9506
8339
|
function handleElementMouseMove(ev) {
|
|
9507
8340
|
//ev.stopPropagation(); //Can't use stopPropagation here, because do not create tempLink
|
|
8341
|
+
onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove(ev, id);
|
|
9508
8342
|
if (someElementLinkStarted && elementRef.current) {
|
|
9509
8343
|
//If an element link is being created, calculate the potential port position when the mouse moves over the element.
|
|
9510
8344
|
if (hoveredPort) {
|
|
@@ -9539,12 +8373,14 @@ var Element = function (props) {
|
|
|
9539
8373
|
}
|
|
9540
8374
|
function handleElementMouseLeave(ev) {
|
|
9541
8375
|
ev.stopPropagation();
|
|
8376
|
+
onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(ev, id);
|
|
9542
8377
|
if (someElementLinkStarted) { //If an element link is being created, clear the placeholder when the mouse leaves the element.
|
|
9543
8378
|
setPotentialPortPosition(undefined);
|
|
9544
8379
|
}
|
|
9545
8380
|
}
|
|
9546
8381
|
var handleElementMouseUp = function (ev) {
|
|
9547
8382
|
ev.stopPropagation();
|
|
8383
|
+
onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(ev, id);
|
|
9548
8384
|
//If an element link is being created, trigger onMouseUpAtLinkedPortPlaceholder when the mouse up the element.
|
|
9549
8385
|
if (potentialPortPosition && elementLinkStarted.current) {
|
|
9550
8386
|
var newElementLink = __assign(__assign({}, elementLinkStarted.current), { tempTargetPosition: undefined });
|
|
@@ -9553,7 +8389,7 @@ var Element = function (props) {
|
|
|
9553
8389
|
}
|
|
9554
8390
|
};
|
|
9555
8391
|
//Handle when mouse move on port
|
|
9556
|
-
var handlePortMouseMove = React
|
|
8392
|
+
var handlePortMouseMove = React.useCallback(function (portId) {
|
|
9557
8393
|
if (someElementLinkStarted) {
|
|
9558
8394
|
var port = portsRef.current.find(function (p) { return p.id === portId; });
|
|
9559
8395
|
if (!port)
|
|
@@ -9562,12 +8398,12 @@ var Element = function (props) {
|
|
|
9562
8398
|
}
|
|
9563
8399
|
}, [someElementLinkStarted]);
|
|
9564
8400
|
//Handle when mouse leave on port
|
|
9565
|
-
var handlePortMouseLeave = React
|
|
8401
|
+
var handlePortMouseLeave = React.useCallback(function () {
|
|
9566
8402
|
if (someElementLinkStarted)
|
|
9567
8403
|
setHoveredPort(undefined);
|
|
9568
8404
|
}, [someElementLinkStarted]);
|
|
9569
8405
|
//Get rotate angle of port by port direction is defined.
|
|
9570
|
-
var rotatePort = React
|
|
8406
|
+
var rotatePort = React.useCallback(function (x, y) {
|
|
9571
8407
|
// console.info('calculating port rotation', x, y)
|
|
9572
8408
|
if (!portSlideRailSVGClassName)
|
|
9573
8409
|
return 0;
|
|
@@ -9607,7 +8443,7 @@ var Element = function (props) {
|
|
|
9607
8443
|
}
|
|
9608
8444
|
return rotationAngle;
|
|
9609
8445
|
}, [portSlideRailSVGClassName, portDirection, getSlideRailSVG]);
|
|
9610
|
-
var renderedShape = React
|
|
8446
|
+
var renderedShape = React.useMemo(function () {
|
|
9611
8447
|
if (renderShape)
|
|
9612
8448
|
return renderShape(props);
|
|
9613
8449
|
return null;
|
|
@@ -9615,7 +8451,7 @@ var Element = function (props) {
|
|
|
9615
8451
|
//Re-render port again after rendered to automation rotate port
|
|
9616
8452
|
//Because elementRef.current equals null in first render so automation rotate port is incorrect.
|
|
9617
8453
|
//TODO: check if this is still needed -> Still needed
|
|
9618
|
-
React
|
|
8454
|
+
React.useLayoutEffect(function () {
|
|
9619
8455
|
if (elementRef.current) {
|
|
9620
8456
|
setPorts(function (prev) { return __spreadArray([], prev, true); });
|
|
9621
8457
|
}
|
|
@@ -9623,7 +8459,7 @@ var Element = function (props) {
|
|
|
9623
8459
|
//use selection frame
|
|
9624
8460
|
useSelectionFrame({
|
|
9625
8461
|
container: container,
|
|
9626
|
-
targetSVGElement: ((
|
|
8462
|
+
targetSVGElement: ((_a = selectedPort === null || selectedPort === void 0 ? void 0 : selectedPort.ref) === null || _a === void 0 ? void 0 : _a.current) || undefined,
|
|
9627
8463
|
resizability: {
|
|
9628
8464
|
enabled: false,
|
|
9629
8465
|
keepRatio: false
|
|
@@ -9635,20 +8471,20 @@ var Element = function (props) {
|
|
|
9635
8471
|
});
|
|
9636
8472
|
useSelectionFrame({
|
|
9637
8473
|
container: container,
|
|
9638
|
-
targetSVGElement: ((
|
|
8474
|
+
targetSVGElement: ((_b = hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.ref) === null || _b === void 0 ? void 0 : _b.current) || undefined,
|
|
9639
8475
|
resizability: {
|
|
9640
8476
|
enabled: false,
|
|
9641
8477
|
keepRatio: false
|
|
9642
8478
|
},
|
|
9643
8479
|
});
|
|
9644
|
-
return (React
|
|
8480
|
+
return (React.createElement(ElementWrapper, { ref: elementRef, x: x, y: y, cssClass: cssClass, onClick: function (e) { return onClick ? onClick(id, e, elementRef.current) : true; }, onMouseMove: handleElementMouseMove, onMouseLeave: handleElementMouseLeave, onMouseUp: handleElementMouseUp, onContextMenu: function (e) { return onContextMenu ? onContextMenu(id, e, elementRef.current) : true; } },
|
|
9645
8481
|
renderedShape,
|
|
9646
8482
|
potentialPortPosition && (portPlaceholderShape
|
|
9647
|
-
? React
|
|
9648
|
-
: React
|
|
8483
|
+
? React.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
|
|
8484
|
+
: React.createElement("rect", { x: potentialPortPosition.x - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, y: potentialPortPosition.y - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, width: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, height: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, rx: PORT_PLACEHOLDER_DEFAULT_SIZE, ry: PORT_PLACEHOLDER_DEFAULT_SIZE, stroke: PORT_PLACEHOLDER_DEFAULT_STROKE, fill: "none", strokeWidth: 3 })), ports === null || ports === void 0 ? void 0 :
|
|
9649
8485
|
ports.map(function (p, index) {
|
|
9650
8486
|
var _a, _b, _c, _d, _e, _f;
|
|
9651
|
-
return React
|
|
8487
|
+
return React.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: (_c = (_b = (_a = p.size) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : defaultPortSize) !== null && _c !== void 0 ? _c : PORT_DEFAULT_SIZE, height: (_f = (_e = (_d = p.size) === null || _d === void 0 ? void 0 : _d.height) !== null && _e !== void 0 ? _e : defaultPortSize) !== null && _f !== void 0 ? _f : PORT_DEFAULT_SIZE, container: container,
|
|
9652
8488
|
// rotation={rotatePort(p)}
|
|
9653
8489
|
calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: handlePortLabelMoved, onPortLabelResized: handlePortLabelResized, onPortLabelContentChanged: handlePortLabelContentChanged, onSelected: handleSelectedPort, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, onMouseMove: handlePortMouseMove,
|
|
9654
8490
|
// onMouseEnter={() => {
|
|
@@ -9657,14 +8493,14 @@ var Element = function (props) {
|
|
|
9657
8493
|
onMouseLeave: handlePortMouseLeave,
|
|
9658
8494
|
// onManuallyTriggerRenderHandler={p.manuallyTriggerRenderHandler?.bind(p)}
|
|
9659
8495
|
renderShape: p.renderShape });
|
|
9660
|
-
}),
|
|
9661
|
-
|
|
8496
|
+
}), texts === null || texts === void 0 ? void 0 :
|
|
8497
|
+
texts.map(function (t, index) {
|
|
9662
8498
|
var _a, _b;
|
|
9663
|
-
return React
|
|
9664
|
-
})
|
|
8499
|
+
return React.createElement(Text$1, { id: t.id, key: index, content: t.content, x: (_a = t.position) === null || _a === void 0 ? void 0 : _a.x, y: (_b = t.position) === null || _b === void 0 ? void 0 : _b.y, width: t.size.width, height: t.size.height, editable: t.editable, align: t.align, fontSize: t.fontSize, border: t.border, container: container, style: t.style, onContentChanged: function (ev, newContent) { return onTextUpdated === null || onTextUpdated === void 0 ? void 0 : onTextUpdated(id, t.id, newContent); } });
|
|
8500
|
+
}),
|
|
9665
8501
|
children));
|
|
9666
8502
|
};
|
|
9667
|
-
var Element$1 = React
|
|
8503
|
+
var Element$1 = React.memo(Element);
|
|
9668
8504
|
|
|
9669
8505
|
var createRect = function (x, y, width, height, strokeWidth, transformOrigin, transform) {
|
|
9670
8506
|
var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
|
@@ -9682,9 +8518,9 @@ var createRect = function (x, y, width, height, strokeWidth, transformOrigin, tr
|
|
|
9682
8518
|
};
|
|
9683
8519
|
function BBoxDebugger(_a) {
|
|
9684
8520
|
var elementSVG = _a.elementSVG;
|
|
9685
|
-
var _b = React
|
|
9686
|
-
var displayedBBoxDebug = React
|
|
9687
|
-
React
|
|
8521
|
+
var _b = React.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
|
|
8522
|
+
var displayedBBoxDebug = React.useRef([]);
|
|
8523
|
+
React.useEffect(function () {
|
|
9688
8524
|
var keyPress = function (ev) {
|
|
9689
8525
|
if (ev.ctrlKey && ev.key === 'b') {
|
|
9690
8526
|
setIsTurnOn(function (prev) { return !prev; });
|
|
@@ -9764,7 +8600,7 @@ function BBoxDebugger(_a) {
|
|
|
9764
8600
|
}, 1000);
|
|
9765
8601
|
return intervalId;
|
|
9766
8602
|
};
|
|
9767
|
-
React
|
|
8603
|
+
React.useEffect(function () {
|
|
9768
8604
|
if (!isTurnOn || !elementSVG)
|
|
9769
8605
|
return;
|
|
9770
8606
|
var listChildrenGroupByLevel = getListChildrenAndGroupSameLevel(elementSVG);
|
|
@@ -9776,12 +8612,12 @@ function BBoxDebugger(_a) {
|
|
|
9776
8612
|
clearBBoxDebugger(displayedBBoxDebug.current);
|
|
9777
8613
|
};
|
|
9778
8614
|
}, [isTurnOn, elementSVG]);
|
|
9779
|
-
return (React
|
|
8615
|
+
return (React.createElement("div", { style: {
|
|
9780
8616
|
position: 'fixed',
|
|
9781
8617
|
top: 20,
|
|
9782
8618
|
right: 20
|
|
9783
8619
|
} },
|
|
9784
|
-
React
|
|
8620
|
+
React.createElement("div", { style: {
|
|
9785
8621
|
backgroundColor: 'white',
|
|
9786
8622
|
boxShadow: '0px 1px 4px 1px',
|
|
9787
8623
|
borderRadius: 4,
|
|
@@ -9805,9 +8641,9 @@ var createDebuggerPoint = function (cx, cy) {
|
|
|
9805
8641
|
};
|
|
9806
8642
|
var LinkDebugger = function (_a) {
|
|
9807
8643
|
var links = _a.links, svgContainer = _a.svgContainer;
|
|
9808
|
-
var _b = React
|
|
9809
|
-
var displayedDebuggerPoint = React
|
|
9810
|
-
React
|
|
8644
|
+
var _b = React.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
|
|
8645
|
+
var displayedDebuggerPoint = React.useRef([]);
|
|
8646
|
+
React.useEffect(function () {
|
|
9811
8647
|
var keyPress = function (ev) {
|
|
9812
8648
|
if (ev.ctrlKey && ev.key === 'l') {
|
|
9813
8649
|
setIsTurnOn(function (prev) { return !prev; });
|
|
@@ -9824,7 +8660,7 @@ var LinkDebugger = function (_a) {
|
|
|
9824
8660
|
ele === null || ele === void 0 ? void 0 : ele.remove();
|
|
9825
8661
|
}
|
|
9826
8662
|
};
|
|
9827
|
-
React
|
|
8663
|
+
React.useEffect(function () {
|
|
9828
8664
|
if (isTurnOn) {
|
|
9829
8665
|
links.forEach(function (link) {
|
|
9830
8666
|
var _a;
|
|
@@ -9839,13 +8675,13 @@ var LinkDebugger = function (_a) {
|
|
|
9839
8675
|
clearDebuggerPoint();
|
|
9840
8676
|
};
|
|
9841
8677
|
}, [isTurnOn, links]);
|
|
9842
|
-
return (React
|
|
8678
|
+
return (React.createElement("div", null));
|
|
9843
8679
|
};
|
|
9844
8680
|
|
|
9845
8681
|
function useKeyboardCommands(_a) {
|
|
9846
8682
|
var element = _a.element;
|
|
9847
|
-
var _b = React
|
|
9848
|
-
React
|
|
8683
|
+
var _b = React.useContext(paperEventEmitterContext), emitCommandDeleteSelectedElement = _b.emitCommandDeleteSelectedElement, emitCommandDeleteSelectedLink = _b.emitCommandDeleteSelectedLink, emitCommandDeleteSelectedPort = _b.emitCommandDeleteSelectedPort, emitCommandDeleteSelectedText = _b.emitCommandDeleteSelectedText;
|
|
8684
|
+
React.useEffect(function () {
|
|
9849
8685
|
var callback = function (ev) {
|
|
9850
8686
|
var keyboardEv = ev;
|
|
9851
8687
|
if (keyboardEv.key === "Delete") {
|
|
@@ -9894,34 +8730,34 @@ function convertElementsToTree(elements) {
|
|
|
9894
8730
|
return parsedElementsInTree;
|
|
9895
8731
|
}
|
|
9896
8732
|
var Paper = function (props) {
|
|
9897
|
-
var _a = React
|
|
9898
|
-
var _b = React
|
|
9899
|
-
var _c = React
|
|
9900
|
-
var _d = React
|
|
9901
|
-
var _e = React
|
|
9902
|
-
var _f = React
|
|
9903
|
-
var _g = React
|
|
9904
|
-
var _h = React
|
|
9905
|
-
var _j = React
|
|
9906
|
-
var _k = React
|
|
9907
|
-
var paperEventEmitter = React
|
|
9908
|
-
var paperContainerRef = React
|
|
9909
|
-
var tempLinkRef = React
|
|
9910
|
-
var elementsRef = React
|
|
8733
|
+
var _a = React.useState([]), elements = _a[0], setElements = _a[1];
|
|
8734
|
+
var _b = React.useState([]), elementsInTree = _b[0], setElementsInTree = _b[1];
|
|
8735
|
+
var _c = React.useState(), selectedElement = _c[0], setSelectedElement = _c[1];
|
|
8736
|
+
var _d = React.useState([]), links = _d[0], setLinks = _d[1];
|
|
8737
|
+
var _e = React.useState(), selectedLink = _e[0], setSelectedLink = _e[1];
|
|
8738
|
+
var _f = React.useState(null), tempLink = _f[0], setTempLink = _f[1];
|
|
8739
|
+
var _g = React.useState([]), texts = _g[0], setTexts = _g[1];
|
|
8740
|
+
var _h = React.useState(), selectedText = _h[0], setSelectedText = _h[1];
|
|
8741
|
+
var _j = React.useState(null), selectedElementSVG = _j[0], setSelectedElementSVG = _j[1];
|
|
8742
|
+
var _k = React.useState(false), mouseDownedOnPaper = _k[0], setMouseDownedOnPaper = _k[1];
|
|
8743
|
+
var paperEventEmitter = React.useContext(paperEventEmitterContext);
|
|
8744
|
+
var paperContainerRef = React.useRef(null);
|
|
8745
|
+
var tempLinkRef = React.useRef(tempLink); //Cache tempLink to avoid re-render when tempLink changed
|
|
8746
|
+
var elementsRef = React.useRef(elements); //Cache elements to avoid re-render when elements changed
|
|
9911
8747
|
var size = props.size;
|
|
9912
|
-
React
|
|
8748
|
+
React.useEffect(function () {
|
|
9913
8749
|
console.log('Render Paper');
|
|
9914
8750
|
});
|
|
9915
|
-
React
|
|
8751
|
+
React.useEffect(function () {
|
|
9916
8752
|
setElements(props.elements);
|
|
9917
8753
|
}, [props.elements]);
|
|
9918
|
-
React
|
|
8754
|
+
React.useEffect(function () {
|
|
9919
8755
|
setLinks(props.links || []);
|
|
9920
8756
|
}, [props.links]);
|
|
9921
|
-
React
|
|
8757
|
+
React.useEffect(function () {
|
|
9922
8758
|
setTexts(props.texts);
|
|
9923
8759
|
}, [props.texts]);
|
|
9924
|
-
React
|
|
8760
|
+
React.useEffect(function () {
|
|
9925
8761
|
var off = props.onManuallyTriggerRenderElement(function (elementId) {
|
|
9926
8762
|
console.log('onManuallyTriggerRenderElement');
|
|
9927
8763
|
setElements(function (prev) { return __spreadArray([], prev, true); });
|
|
@@ -9931,7 +8767,7 @@ var Paper = function (props) {
|
|
|
9931
8767
|
};
|
|
9932
8768
|
}, [props.onManuallyTriggerRenderElement]);
|
|
9933
8769
|
//Cache elements to avoid re-render when elements changed
|
|
9934
|
-
React
|
|
8770
|
+
React.useEffect(function () {
|
|
9935
8771
|
elementsRef.current = elements;
|
|
9936
8772
|
}, [elements]);
|
|
9937
8773
|
useKeyboardCommands({
|
|
@@ -9942,11 +8778,11 @@ var Paper = function (props) {
|
|
|
9942
8778
|
setElementsInTree(parsedElementsInTree);
|
|
9943
8779
|
};
|
|
9944
8780
|
//Cache tempLink to avoid re-render when tempLink changed
|
|
9945
|
-
React
|
|
8781
|
+
React.useEffect(function () {
|
|
9946
8782
|
tempLinkRef.current = tempLink;
|
|
9947
8783
|
}, [tempLink]);
|
|
9948
8784
|
//Listen text is selected
|
|
9949
|
-
React
|
|
8785
|
+
React.useEffect(function () {
|
|
9950
8786
|
var textSelectedListener = paperEventEmitter.onTextSelected(function (text) {
|
|
9951
8787
|
var _a;
|
|
9952
8788
|
setSelectedElement(undefined);
|
|
@@ -9960,7 +8796,7 @@ var Paper = function (props) {
|
|
|
9960
8796
|
};
|
|
9961
8797
|
}, []);
|
|
9962
8798
|
//Listen port is selected
|
|
9963
|
-
React
|
|
8799
|
+
React.useEffect(function () {
|
|
9964
8800
|
var portSelectedListener = paperEventEmitter.onPortSelected(function (port, elementId) {
|
|
9965
8801
|
var _a;
|
|
9966
8802
|
setSelectedElement(undefined);
|
|
@@ -9976,11 +8812,12 @@ var Paper = function (props) {
|
|
|
9976
8812
|
portSelectedListener.off();
|
|
9977
8813
|
};
|
|
9978
8814
|
}, []);
|
|
9979
|
-
React
|
|
8815
|
+
React.useEffect(function () {
|
|
9980
8816
|
//Listen parent of elements changed, then update elements tree
|
|
9981
8817
|
var parentChangedCancelers = elementsRef.current.map(function (element) {
|
|
9982
8818
|
var _a;
|
|
9983
8819
|
return (_a = element.onParentChanged) === null || _a === void 0 ? void 0 : _a.call(element, function (newPa, oldPa) {
|
|
8820
|
+
console.log('onParentChanged');
|
|
9984
8821
|
updateElementsTree();
|
|
9985
8822
|
});
|
|
9986
8823
|
});
|
|
@@ -10004,7 +8841,7 @@ var Paper = function (props) {
|
|
|
10004
8841
|
};
|
|
10005
8842
|
}, []);
|
|
10006
8843
|
//Update elements tree when length of elements change
|
|
10007
|
-
React
|
|
8844
|
+
React.useEffect(function () {
|
|
10008
8845
|
updateElementsTree();
|
|
10009
8846
|
}, [elements]);
|
|
10010
8847
|
//Get all child elements of the deleted element
|
|
@@ -10018,7 +8855,7 @@ var Paper = function (props) {
|
|
|
10018
8855
|
return __spreadArray(__spreadArray([], childElms, true), childOfChildElements, true);
|
|
10019
8856
|
};
|
|
10020
8857
|
//Listen command delete selected for element
|
|
10021
|
-
React
|
|
8858
|
+
React.useEffect(function () {
|
|
10022
8859
|
var _a;
|
|
10023
8860
|
var listener = paperEventEmitter.onCommandDeleteSelectedElement(function () {
|
|
10024
8861
|
if (selectedElement) {
|
|
@@ -10039,7 +8876,7 @@ var Paper = function (props) {
|
|
|
10039
8876
|
};
|
|
10040
8877
|
}, [selectedElement]);
|
|
10041
8878
|
//Listen command delete selected for link
|
|
10042
|
-
React
|
|
8879
|
+
React.useEffect(function () {
|
|
10043
8880
|
var _a;
|
|
10044
8881
|
var listener = paperEventEmitter.onCommandDeleteSelectedLink(function () {
|
|
10045
8882
|
if (selectedLink) {
|
|
@@ -10056,7 +8893,7 @@ var Paper = function (props) {
|
|
|
10056
8893
|
};
|
|
10057
8894
|
}, [selectedLink]);
|
|
10058
8895
|
//Listen command delete selected for Text
|
|
10059
|
-
React
|
|
8896
|
+
React.useEffect(function () {
|
|
10060
8897
|
var _a;
|
|
10061
8898
|
var listener = paperEventEmitter.onCommandDeleteSelectedText(function () {
|
|
10062
8899
|
if (selectedText) {
|
|
@@ -10073,7 +8910,7 @@ var Paper = function (props) {
|
|
|
10073
8910
|
};
|
|
10074
8911
|
}, [selectedText]);
|
|
10075
8912
|
//Automatically add points on the link so that the link does not cross elements, default maximum 10 points
|
|
10076
|
-
var automationAddPointsToLink = React
|
|
8913
|
+
var automationAddPointsToLink = React.useCallback(function (eleLink, limitPoint) {
|
|
10077
8914
|
if (limitPoint === void 0) { limitPoint = 10; }
|
|
10078
8915
|
var sourceElement = eleLink.sourceElement, sourcePort = eleLink.sourcePort, targetElement = eleLink.targetElement, targetPort = eleLink.targetPort;
|
|
10079
8916
|
var sourcePosition = {
|
|
@@ -10168,7 +9005,7 @@ var Paper = function (props) {
|
|
|
10168
9005
|
y: ev.clientY
|
|
10169
9006
|
});
|
|
10170
9007
|
};
|
|
10171
|
-
var handlePathChange = React
|
|
9008
|
+
var handlePathChange = React.useCallback(function (path, id) {
|
|
10172
9009
|
//Update path of element link, that changed
|
|
10173
9010
|
setLinks(function (prevLinks) {
|
|
10174
9011
|
var updatedLinkIndex = prevLinks.findIndex(function (l) { return l.id === id; });
|
|
@@ -10176,7 +9013,7 @@ var Paper = function (props) {
|
|
|
10176
9013
|
return __spreadArray([], prevLinks, true);
|
|
10177
9014
|
});
|
|
10178
9015
|
}, []);
|
|
10179
|
-
var handlePortMoved = React
|
|
9016
|
+
var handlePortMoved = React.useCallback(function (port, elementId, oldPosition, newPosition) {
|
|
10180
9017
|
var element = elementsRef.current.find(function (e) { return e.id === elementId; });
|
|
10181
9018
|
if (element) {
|
|
10182
9019
|
//set links equals a clone links to re-render links with new position
|
|
@@ -10208,23 +9045,27 @@ var Paper = function (props) {
|
|
|
10208
9045
|
}
|
|
10209
9046
|
}, [props.onPortMoved]);
|
|
10210
9047
|
//Handle creating a new element link
|
|
10211
|
-
var handlePortMouseDown = React
|
|
9048
|
+
var handlePortMouseDown = React.useCallback(function (ev, port, elementId) {
|
|
9049
|
+
var _a;
|
|
10212
9050
|
ev.stopPropagation();
|
|
10213
|
-
|
|
10214
|
-
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
|
|
10222
|
-
|
|
10223
|
-
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
|
|
10227
|
-
|
|
9051
|
+
var element = elementsRef.current.find(function (e) { return e.id === elementId; });
|
|
9052
|
+
//broadcast port mouse down to parent component
|
|
9053
|
+
if (element) {
|
|
9054
|
+
(_a = props.onPortMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, port, element);
|
|
9055
|
+
}
|
|
9056
|
+
if (!tempLinkRef.current && element) {
|
|
9057
|
+
//handle create temp element link;
|
|
9058
|
+
var newLink = {
|
|
9059
|
+
id: generateUniqueId(),
|
|
9060
|
+
points: [],
|
|
9061
|
+
sourceElement: element,
|
|
9062
|
+
sourcePort: port,
|
|
9063
|
+
};
|
|
9064
|
+
setTempLink(newLink);
|
|
9065
|
+
paperEventEmitter.emitElementLinkStarted(newLink);
|
|
9066
|
+
}
|
|
9067
|
+
}, [paperEventEmitter, props.onPortMouseDown]);
|
|
9068
|
+
var createElementLink = React.useCallback(function (sourcePort, sourceElement, targetPort, targetElement) {
|
|
10228
9069
|
//if no onCreatingLink prop, no link will be created
|
|
10229
9070
|
if (!props.onCreatingLink) {
|
|
10230
9071
|
return null;
|
|
@@ -10238,15 +9079,21 @@ var Paper = function (props) {
|
|
|
10238
9079
|
}
|
|
10239
9080
|
return newElementLink;
|
|
10240
9081
|
}, [props.onCreatingLink, automationAddPointsToLink]);
|
|
10241
|
-
var handlePortMouseUp = React
|
|
9082
|
+
var handlePortMouseUp = React.useCallback(function (ev, port, elementId) {
|
|
9083
|
+
var _a;
|
|
10242
9084
|
ev.stopPropagation();
|
|
9085
|
+
var element = elementsRef.current.find(function (e) { return e.id === elementId; });
|
|
9086
|
+
//broadcast port mouse down to parent component
|
|
9087
|
+
if (element) {
|
|
9088
|
+
(_a = props.onPortMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, port, element);
|
|
9089
|
+
}
|
|
10243
9090
|
//Create new element link, if has tempLink
|
|
10244
9091
|
if (tempLinkRef.current) {
|
|
10245
9092
|
//Check if mouse up point is mouse down point or not
|
|
10246
9093
|
var isMouseUpOnNotSelf = tempLinkRef.current.sourcePort.id !== port.id || tempLinkRef.current.sourceElement.id !== elementId;
|
|
10247
9094
|
var newElementLink_1 = null;
|
|
10248
9095
|
if (isMouseUpOnNotSelf) {
|
|
10249
|
-
var
|
|
9096
|
+
var _b = tempLinkRef.current, sourcePort = _b.sourcePort, sourceElement = _b.sourceElement;
|
|
10250
9097
|
var targetElement = elementsRef.current.find(function (e) { return e.id === elementId; });
|
|
10251
9098
|
newElementLink_1 = createElementLink(sourcePort, sourceElement, port, targetElement);
|
|
10252
9099
|
}
|
|
@@ -10259,8 +9106,8 @@ var Paper = function (props) {
|
|
|
10259
9106
|
}
|
|
10260
9107
|
setTempLink(null);
|
|
10261
9108
|
}
|
|
10262
|
-
}, [paperEventEmitter, createElementLink]);
|
|
10263
|
-
var handleLinkLabelMoved = React
|
|
9109
|
+
}, [paperEventEmitter, createElementLink, props.onPortMouseUp]);
|
|
9110
|
+
var handleLinkLabelMoved = React.useCallback(function (offsetX, offsetY, index, labelType) {
|
|
10264
9111
|
setLinks(function (prevLinks) {
|
|
10265
9112
|
var newLinks = __spreadArray([], prevLinks, true);
|
|
10266
9113
|
var currentLink = newLinks[index];
|
|
@@ -10296,7 +9143,7 @@ var Paper = function (props) {
|
|
|
10296
9143
|
return newLinks;
|
|
10297
9144
|
});
|
|
10298
9145
|
}, []);
|
|
10299
|
-
var handleLinkLabelResized = React
|
|
9146
|
+
var handleLinkLabelResized = React.useCallback(function (width, height, index, labelType) {
|
|
10300
9147
|
setLinks(function (prevLinks) {
|
|
10301
9148
|
var newLinks = __spreadArray([], prevLinks, true);
|
|
10302
9149
|
var currentLink = newLinks[index];
|
|
@@ -10329,7 +9176,7 @@ var Paper = function (props) {
|
|
|
10329
9176
|
return newLinks;
|
|
10330
9177
|
});
|
|
10331
9178
|
}, []);
|
|
10332
|
-
var handleLinkLabelContentChanged = React
|
|
9179
|
+
var handleLinkLabelContentChanged = React.useCallback(function (newValue, index, labelType) {
|
|
10333
9180
|
setLinks(function (prevLinks) {
|
|
10334
9181
|
var newLinks = __spreadArray([], prevLinks, true);
|
|
10335
9182
|
var currentLink = newLinks[index];
|
|
@@ -10413,7 +9260,7 @@ var Paper = function (props) {
|
|
|
10413
9260
|
Cache to avoid re-initializing the function when the component re-renders to
|
|
10414
9261
|
avoid causing the components using it to re-render unnecessarily
|
|
10415
9262
|
*/
|
|
10416
|
-
var onLabelMoved = React
|
|
9263
|
+
var onLabelMoved = React.useCallback(function (index) {
|
|
10417
9264
|
return function (offsetX, offsetY, labelType) {
|
|
10418
9265
|
handleLinkLabelMoved(offsetX, offsetY, index, labelType);
|
|
10419
9266
|
};
|
|
@@ -10422,7 +9269,7 @@ var Paper = function (props) {
|
|
|
10422
9269
|
Cache to avoid re-initializing the function when the component re-renders to
|
|
10423
9270
|
avoid causing the components using it to re-render unnecessarily
|
|
10424
9271
|
*/
|
|
10425
|
-
var onLabelResized = React
|
|
9272
|
+
var onLabelResized = React.useCallback(function (index) {
|
|
10426
9273
|
return function (width, height, labelType) {
|
|
10427
9274
|
handleLinkLabelResized(width, height, index, labelType);
|
|
10428
9275
|
};
|
|
@@ -10431,12 +9278,12 @@ var Paper = function (props) {
|
|
|
10431
9278
|
Cache to avoid re-initializing the function when the component re-renders to
|
|
10432
9279
|
avoid causing the components using it to re-render unnecessarily
|
|
10433
9280
|
*/
|
|
10434
|
-
var onLabelContentChanged = React
|
|
9281
|
+
var onLabelContentChanged = React.useCallback(function (index) {
|
|
10435
9282
|
return function (newValue, labelType) {
|
|
10436
9283
|
handleLinkLabelContentChanged(newValue, index, labelType);
|
|
10437
9284
|
};
|
|
10438
9285
|
}, [handleLinkLabelContentChanged]);
|
|
10439
|
-
var handleClickLinkDelete = React
|
|
9286
|
+
var handleClickLinkDelete = React.useCallback(function (link, index) {
|
|
10440
9287
|
return function () {
|
|
10441
9288
|
setLinks(function (prevLinks) {
|
|
10442
9289
|
var newLinks = __spreadArray([], prevLinks, true);
|
|
@@ -10445,7 +9292,7 @@ var Paper = function (props) {
|
|
|
10445
9292
|
});
|
|
10446
9293
|
};
|
|
10447
9294
|
}, []);
|
|
10448
|
-
var handleMouseUpAtLinkedPortPlaceholder = React
|
|
9295
|
+
var handleMouseUpAtLinkedPortPlaceholder = React.useCallback(function (link, position, targetElementId) {
|
|
10449
9296
|
var targetElement = elementsRef.current.find(function (e) { return e.id === targetElementId; });
|
|
10450
9297
|
if (!targetElement)
|
|
10451
9298
|
return;
|
|
@@ -10472,7 +9319,7 @@ var Paper = function (props) {
|
|
|
10472
9319
|
setTempLink(null);
|
|
10473
9320
|
paperEventEmitter.emitElementLinkEnded();
|
|
10474
9321
|
}, [props.onCreatingPortByLinking, createElementLink, paperEventEmitter]);
|
|
10475
|
-
var handleElementTextChange = React
|
|
9322
|
+
var handleElementTextChange = React.useCallback(function (elementId, textId, newContent) {
|
|
10476
9323
|
setElements(function (prevElms) {
|
|
10477
9324
|
return prevElms.map(function (curEle) {
|
|
10478
9325
|
//Find changed text of element to update the content for it.
|
|
@@ -10486,7 +9333,7 @@ var Paper = function (props) {
|
|
|
10486
9333
|
});
|
|
10487
9334
|
});
|
|
10488
9335
|
}, []);
|
|
10489
|
-
var handleElementClicked = React
|
|
9336
|
+
var handleElementClicked = React.useCallback(function (elementId, e, ref) {
|
|
10490
9337
|
e.stopPropagation();
|
|
10491
9338
|
var tempLink = tempLinkRef.current;
|
|
10492
9339
|
if (tempLink) {
|
|
@@ -10504,7 +9351,7 @@ var Paper = function (props) {
|
|
|
10504
9351
|
}
|
|
10505
9352
|
setMouseDownedOnPaper(false);
|
|
10506
9353
|
}, [paperEventEmitter]);
|
|
10507
|
-
var handleContextMenu = React
|
|
9354
|
+
var handleContextMenu = React.useCallback(function (elementId, e, ref) {
|
|
10508
9355
|
var _a;
|
|
10509
9356
|
e.preventDefault();
|
|
10510
9357
|
var element = elementsRef.current.find(function (e) { return e.id === elementId; });
|
|
@@ -10513,34 +9360,54 @@ var Paper = function (props) {
|
|
|
10513
9360
|
(_a = props.onElementContextMenu) === null || _a === void 0 ? void 0 : _a.call(props, element, e);
|
|
10514
9361
|
}
|
|
10515
9362
|
}, [props.onElementContextMenu, handleElementClicked]);
|
|
10516
|
-
var
|
|
9363
|
+
var handleMouseUp = React.useCallback(function (ev, elementId) {
|
|
9364
|
+
var _a;
|
|
9365
|
+
var element = elementsRef.current.find(function (ele) { return ele.id === elementId; });
|
|
9366
|
+
if (element) {
|
|
9367
|
+
(_a = props.onElementMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, ev, element);
|
|
9368
|
+
}
|
|
9369
|
+
}, [props.onElementMouseUp]);
|
|
9370
|
+
var handleMouseMove = React.useCallback(function (ev, elementId) {
|
|
9371
|
+
var _a;
|
|
9372
|
+
var element = elementsRef.current.find(function (ele) { return ele.id === elementId; });
|
|
9373
|
+
if (element) {
|
|
9374
|
+
(_a = props.onElementMouseMove) === null || _a === void 0 ? void 0 : _a.call(props, ev, element);
|
|
9375
|
+
}
|
|
9376
|
+
}, [props.onElementMouseMove]);
|
|
9377
|
+
var handleMouseLeave = React.useCallback(function (ev, elementId) {
|
|
9378
|
+
var _a;
|
|
9379
|
+
var element = elementsRef.current.find(function (ele) { return ele.id === elementId; });
|
|
9380
|
+
if (element) {
|
|
9381
|
+
(_a = props.onElementMouseLeave) === null || _a === void 0 ? void 0 : _a.call(props, ev, element);
|
|
9382
|
+
}
|
|
9383
|
+
}, [props.onElementMouseLeave]);
|
|
9384
|
+
var renderElementInTree = React.useCallback(function (element) {
|
|
10517
9385
|
var _a, _b;
|
|
10518
9386
|
//use the defined react element or the default Element component
|
|
10519
9387
|
var ReactElement = element.reactElement || Element$1;
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
React$1.createElement(ReactElement, { key: "element-".concat(element.id), id: element.id, height: element.size.height, width: element.size.width, x: (_a = element.relativePosition) === null || _a === void 0 ? void 0 : _a.x, y: (_b = element.relativePosition) === null || _b === void 0 ? void 0 : _b.y, onClick: handleElementClicked, onContextMenu: handleContextMenu, container: paperContainerRef.current, renderShape: element.renderShape, cssClass: element.cssClass, texts: element.texts, ports: element.ports, portMoveableAreas: element.portMoveableAreas, portSlideRailSVGClassName: element.portSlideRailSVGClassName, portDirection: element.portDirection, defaultPortSize: element.defaultPortSize, onPortMoved: handlePortMoved, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp,
|
|
9388
|
+
return (React.createElement("g", { key: element.id },
|
|
9389
|
+
React.createElement(ReactElement, { key: "element-".concat(element.id), id: element.id, height: element.size.height, width: element.size.width, x: (_a = element.relativePosition) === null || _a === void 0 ? void 0 : _a.x, y: (_b = element.relativePosition) === null || _b === void 0 ? void 0 : _b.y, onClick: handleElementClicked, onContextMenu: handleContextMenu, onMouseUp: handleMouseUp, onMouseMove: handleMouseMove, onMouseLeave: handleMouseLeave, container: paperContainerRef.current, renderShape: element.renderShape, cssClass: element.cssClass, texts: element.texts, ports: element.ports, portMoveableAreas: element.portMoveableAreas, portSlideRailSVGClassName: element.portSlideRailSVGClassName, portDirection: element.portDirection, defaultPortSize: element.defaultPortSize, onPortMoved: handlePortMoved, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp,
|
|
10523
9390
|
// portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
|
|
10524
9391
|
onMouseUpAtLinkedPortPlaceholder: handleMouseUpAtLinkedPortPlaceholder, onTextUpdated: handleElementTextChange, onManuallyTriggerRenderPort: props.onManuallyTriggerRenderPort, textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition }, element.childrenElements && element.childrenElements.map(renderElementInTree))));
|
|
10525
|
-
}, [handleElementClicked, handleContextMenu, handlePortMoved, handlePortMouseDown, handlePortMouseUp, handleMouseUpAtLinkedPortPlaceholder, handleElementTextChange]);
|
|
10526
|
-
React
|
|
9392
|
+
}, [handleElementClicked, handleContextMenu, handlePortMoved, handlePortMouseDown, handlePortMouseUp, handleMouseUpAtLinkedPortPlaceholder, handleElementTextChange, handleMouseUp, handleMouseMove, handleMouseLeave]);
|
|
9393
|
+
React.useEffect(function () {
|
|
10527
9394
|
console.log('elementsInTree');
|
|
10528
9395
|
}, [elementsInTree]);
|
|
10529
|
-
React
|
|
9396
|
+
React.useEffect(function () {
|
|
10530
9397
|
console.log('renderElementInTree');
|
|
10531
9398
|
}, [renderElementInTree]);
|
|
10532
|
-
var ElementsInTree = React
|
|
9399
|
+
var ElementsInTree = React.useMemo(function () {
|
|
10533
9400
|
return elementsInTree.map(function (element, index) {
|
|
10534
9401
|
return renderElementInTree(element);
|
|
10535
9402
|
});
|
|
10536
9403
|
}, [elementsInTree, renderElementInTree]);
|
|
10537
|
-
return (React
|
|
10538
|
-
React
|
|
10539
|
-
React
|
|
9404
|
+
return (React.createElement("div", { style: { position: "relative" } },
|
|
9405
|
+
React.createElement(Ruler, { squareSize: 100, border: '1px dashed grey' }),
|
|
9406
|
+
React.createElement("svg", { tabIndex: 0, width: size.width, height: size.height, ref: paperContainerRef, id: "paper-container", onMouseMove: handlePaperMouseMove, onMouseDown: handleMouseDownOnPaper, onMouseUp: handleMouseUpOnPaper },
|
|
10540
9407
|
paperContainerRef.current ? ElementsInTree : "",
|
|
10541
9408
|
links && links.map(function (link, index) {
|
|
10542
9409
|
var _a, _b, _c, _d;
|
|
10543
|
-
return (React
|
|
9410
|
+
return (React.createElement(ElementLink, { key: link.id, id: link.id, path: link.path, sourcePosition: {
|
|
10544
9411
|
x: link.sourceElement.position.x + link.sourcePort.position.x,
|
|
10545
9412
|
y: link.sourceElement.position.y + link.sourcePort.position.y
|
|
10546
9413
|
}, targetPosition: {
|
|
@@ -10548,40 +9415,40 @@ var Paper = function (props) {
|
|
|
10548
9415
|
y: ((_c = link.targetElement) === null || _c === void 0 ? void 0 : _c.position.y) + ((_d = link.targetPort) === null || _d === void 0 ? void 0 : _d.position.y)
|
|
10549
9416
|
}, points: link.points, onPathChanged: handlePathChange, onClickDelete: handleClickLinkDelete(link, index), onSelected: function () { return handleSelectLink(link); }, onDeselected: function () { return handleDeselectLink(); }, container: paperContainerRef.current, markerStart: link.markerStart, markerEnd: link.markerEnd, markerDistanceFromPort: link.markerDistanceFromPort, markerSize: link.markerSize, label: link.label, sourceLabel: link.sourceLabel, targetLabel: link.targetLabel, onLabelMoved: onLabelMoved(index), onLabelResized: onLabelResized(index), onLabelContentChanged: onLabelContentChanged(index) }));
|
|
10550
9417
|
}),
|
|
10551
|
-
(tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React
|
|
9418
|
+
(tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React.createElement(ElementLink, { id: tempLink.id, points: tempLink.points, sourcePosition: {
|
|
10552
9419
|
x: tempLink.sourceElement.position.x + tempLink.sourcePort.position.x,
|
|
10553
9420
|
y: tempLink.sourceElement.position.y + tempLink.sourcePort.position.y
|
|
10554
9421
|
}, targetPosition: tempLink.tempTargetPosition, container: paperContainerRef.current, markerStart: tempLink.markerStart, markerEnd: tempLink.markerEnd, markerDistanceFromPort: tempLink.markerDistanceFromPort, markerSize: tempLink.markerSize }),
|
|
10555
|
-
texts.map(function (text, index) { return (React
|
|
9422
|
+
texts.map(function (text, index) { return (React.createElement(Text$1, { key: text.id, id: text.id, x: text.position.x, y: text.position.y, width: text.size.width, height: text.size.height, editable: text.editable, fontSize: text.fontSize, border: text.border, container: paperContainerRef.current, content: text.content, align: text.align, onSelected: function () {
|
|
10556
9423
|
setSelectedText(text);
|
|
10557
9424
|
} })); })),
|
|
10558
|
-
React
|
|
10559
|
-
React
|
|
9425
|
+
React.createElement(BBoxDebugger, { elementSVG: selectedElementSVG }),
|
|
9426
|
+
React.createElement(LinkDebugger, { links: links, svgContainer: paperContainerRef.current })));
|
|
10560
9427
|
};
|
|
10561
|
-
var Paper$1 = React
|
|
9428
|
+
var Paper$1 = React.memo(Paper);
|
|
10562
9429
|
|
|
10563
9430
|
var Editor = function (_a) {
|
|
10564
9431
|
var editorContext = _a.editorContext, width = _a.width, height = _a.height;
|
|
10565
|
-
var _b = React
|
|
10566
|
-
var _c = React
|
|
10567
|
-
var _d = React
|
|
9432
|
+
var _b = React.useState([]), elements = _b[0], setElements = _b[1];
|
|
9433
|
+
var _c = React.useState([]), links = _c[0], setLinks = _c[1];
|
|
9434
|
+
var _d = React.useState([]), texts = _d[0], setTexts = _d[1];
|
|
10568
9435
|
if (!width) {
|
|
10569
9436
|
width = 3000;
|
|
10570
9437
|
}
|
|
10571
9438
|
if (!height) {
|
|
10572
9439
|
height = 3000;
|
|
10573
9440
|
}
|
|
10574
|
-
var setEditorStates = React
|
|
9441
|
+
var setEditorStates = React.useCallback(function (ctx) {
|
|
10575
9442
|
setElements(__spreadArray([], ctx.elements, true));
|
|
10576
9443
|
setLinks(__spreadArray([], ctx.links, true));
|
|
10577
9444
|
setTexts(__spreadArray([], ctx.texts, true));
|
|
10578
9445
|
}, []);
|
|
10579
|
-
React
|
|
9446
|
+
React.useEffect(function () {
|
|
10580
9447
|
if (editorContext) {
|
|
10581
9448
|
setEditorStates(editorContext);
|
|
10582
9449
|
}
|
|
10583
9450
|
}, [editorContext, setEditorStates]);
|
|
10584
|
-
React
|
|
9451
|
+
React.useEffect(function () {
|
|
10585
9452
|
var offs = [];
|
|
10586
9453
|
if (editorContext) {
|
|
10587
9454
|
offs.push(editorContext.onEditorContextUpdated(function () {
|
|
@@ -10593,55 +9460,70 @@ var Editor = function (_a) {
|
|
|
10593
9460
|
offs.forEach(function (off) { return off(); });
|
|
10594
9461
|
};
|
|
10595
9462
|
}, [editorContext, setEditorStates]);
|
|
10596
|
-
var handlePaperClicked = React
|
|
9463
|
+
var handlePaperClicked = React.useCallback(function (position) {
|
|
10597
9464
|
editorContext.onPaperClickedHandler(position);
|
|
10598
9465
|
}, [editorContext]);
|
|
10599
|
-
var
|
|
9466
|
+
var handlePortMouseDown = React.useCallback(function (port, element) {
|
|
9467
|
+
editorContext.onPortMouseDownHandler(port, element);
|
|
9468
|
+
}, [editorContext]);
|
|
9469
|
+
var handlePortMouseUp = React.useCallback(function (port, element) {
|
|
9470
|
+
editorContext.onPortMouseUpHandler(port, element);
|
|
9471
|
+
}, [editorContext]);
|
|
9472
|
+
var handlePortMoved = React.useCallback(function (position, port, element) {
|
|
10600
9473
|
editorContext.onPortMovedHandler(position, port, element);
|
|
10601
9474
|
}, [editorContext]);
|
|
10602
|
-
var handlePortSelected = React
|
|
9475
|
+
var handlePortSelected = React.useCallback(function (port, element) {
|
|
10603
9476
|
editorContext.onPortSelectedHandler(port, element);
|
|
10604
9477
|
}, [editorContext]);
|
|
10605
|
-
var handleElementContextMenu = React
|
|
9478
|
+
var handleElementContextMenu = React.useCallback(function (element, event) {
|
|
10606
9479
|
editorContext.onElementContextMenuHandler(element, event);
|
|
10607
9480
|
}, [editorContext]);
|
|
10608
|
-
var handleElementMoved = React
|
|
9481
|
+
var handleElementMoved = React.useCallback(function (position, element) {
|
|
10609
9482
|
editorContext.onElementMovedHandler(position, element);
|
|
10610
9483
|
}, [editorContext]);
|
|
10611
|
-
var handleElementResized = React
|
|
9484
|
+
var handleElementResized = React.useCallback(function (size, element) {
|
|
10612
9485
|
editorContext.onElementResizedHandler(size, element);
|
|
10613
9486
|
}, [editorContext]);
|
|
10614
|
-
var handleElementSelected = React
|
|
9487
|
+
var handleElementSelected = React.useCallback(function (element) {
|
|
10615
9488
|
editorContext.onElementSelectedHandler(element);
|
|
10616
9489
|
}, [editorContext]);
|
|
10617
|
-
var
|
|
9490
|
+
var handleElementMouseLeave = React.useCallback(function (ev, element) {
|
|
9491
|
+
editorContext.onElementMouseLeaveHandler(ev, element);
|
|
9492
|
+
}, [editorContext]);
|
|
9493
|
+
var handleElementMouseMove = React.useCallback(function (ev, element) {
|
|
9494
|
+
editorContext.onElementMouseMoveHandler(ev, element);
|
|
9495
|
+
}, [editorContext]);
|
|
9496
|
+
var handleElementMouseUp = React.useCallback(function (ev, element) {
|
|
9497
|
+
editorContext.onElementMouseUpHandler(ev, element);
|
|
9498
|
+
}, [editorContext]);
|
|
9499
|
+
var handleLinkSelected = React.useCallback(function (link) {
|
|
10618
9500
|
editorContext.onLinkSelectedHandler(link);
|
|
10619
9501
|
}, [editorContext]);
|
|
10620
|
-
var handleTextSelected = React
|
|
9502
|
+
var handleTextSelected = React.useCallback(function (text) {
|
|
10621
9503
|
editorContext.onTextSelectedHandler(text);
|
|
10622
9504
|
}, [editorContext]);
|
|
10623
|
-
var handleOnCreatingLink = React
|
|
9505
|
+
var handleOnCreatingLink = React.useCallback(function (sourcePort, sourceElement, targetPort, targetElement) {
|
|
10624
9506
|
if (editorContext.onCreatingLinkHandler) {
|
|
10625
9507
|
return editorContext.onCreatingLinkHandler(sourcePort, sourceElement, targetPort, targetElement);
|
|
10626
9508
|
}
|
|
10627
9509
|
return null;
|
|
10628
9510
|
}, [editorContext]);
|
|
10629
|
-
var handleOnCreatingPortByLinking = React
|
|
9511
|
+
var handleOnCreatingPortByLinking = React.useCallback(function (sourceElement, sourcePort, targetElement, position) {
|
|
10630
9512
|
if (editorContext.onCreatingPortByLinkingHandler) {
|
|
10631
9513
|
return editorContext.onCreatingPortByLinkingHandler(sourceElement, sourcePort, targetElement, position);
|
|
10632
9514
|
}
|
|
10633
9515
|
return null;
|
|
10634
9516
|
}, [editorContext]);
|
|
10635
|
-
var handlePaperMouseMoved = React
|
|
9517
|
+
var handlePaperMouseMoved = React.useCallback(function (position) {
|
|
10636
9518
|
editorContext.onPaperMouseMovedHandler(position);
|
|
10637
9519
|
}, [editorContext]);
|
|
10638
|
-
var handlePaperMouseDown = React
|
|
9520
|
+
var handlePaperMouseDown = React.useCallback(function (position) {
|
|
10639
9521
|
editorContext.onPaperMouseDownHandler(position);
|
|
10640
9522
|
}, [editorContext]);
|
|
10641
|
-
var handlePaperMouseUp = React
|
|
9523
|
+
var handlePaperMouseUp = React.useCallback(function (position) {
|
|
10642
9524
|
editorContext.onPaperMouseUpHandler(position);
|
|
10643
9525
|
}, [editorContext]);
|
|
10644
|
-
return (React
|
|
9526
|
+
return (React.createElement(Paper$1, { key: "paper", size: { width: width, height: height }, elements: elements, links: links, texts: texts, onPaperClicked: handlePaperClicked, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onElementMouseLeave: handleElementMouseLeave, onElementMouseMove: handleElementMouseMove, onElementMouseUp: handleElementMouseUp, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onTextSelected: handleTextSelected, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseUp, onPaperMouseDown: handlePaperMouseDown, onManuallyTriggerRenderElement: editorContext.onManuallyTriggerRenderElement.bind(editorContext), onManuallyTriggerRenderPort: editorContext.onManuallyTriggerRenderPort.bind(editorContext) }));
|
|
10645
9527
|
};
|
|
10646
9528
|
|
|
10647
9529
|
exports.CircleRC = Circle;
|