orcasvn-react-diagrams 0.1.28 → 0.1.30

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var React$1 = require('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$1.forwardRef(function (shapeProps, ref) {
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$1.useMemo(function () {
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$1.createElement("g", { transform: "rotate(".concat(rotation, ")"), style: { transformOrigin: transformOrigin, transformBox: "content-box" } },
666
- React$1.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)));
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$1.forwardRef(function (props, ref) {
670
- return (React$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref }), props.children));
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$1.forwardRef(function (props, ref) {
692
- return (React$1.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));
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$1.forwardRef(function (props, ref) {
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$1.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height, ref: ref }),
973
- React$1.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 })));
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$1.forwardRef(function (props, ref) {
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$1.createElement(ShapeWrapper, __assign({ ref: ref, viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height }),
991
- React$1.createElement("rect", { width: 100, height: 100, stroke: "transparent", fill: 'transparent' }),
992
- React$1.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 })));
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$1.forwardRef(function (props, ref) {
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$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
1012
- React$1.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 })));
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$1.forwardRef(function (props, ref) {
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$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
1036
- React$1.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 }),
1037
- React$1.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" }),
1038
- React$1.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" })));
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$1.useState(props.width || (bbox === null || bbox === void 0 ? void 0 : bbox.width) || MIN_ELEMENT_SIZE), width = _b[0], setWidth = _b[1];
1121
- var _c = React$1.useState(props.height || (bbox === null || bbox === void 0 ? void 0 : bbox.height) || MIN_ELEMENT_SIZE), height = _c[0], setHeight = _c[1];
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$1.useState(false), draggingRect = _d[0], setDraggingRect = _d[1];
1127
- var _e = React$1.useState(false), draggingCircle = _e[0], setDraggingCircle = _e[1];
1128
- var _f = React$1.useState(0), startX = _f[0], setStartX = _f[1];
1129
- var _g = React$1.useState(0), startY = _g[0], setStartY = _g[1];
1130
- var _h = React$1.useState(0), lastMoveTime = _h[0], setLastMoveTime = _h[1];
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$1.useCallback(function (event) {
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$1.useEffect(function () {
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$1.useEffect(function () {
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$1.createElement(React$1.Fragment, null,
1245
- props.dragDropHandlerElement && React$1.createElement(props.dragDropHandlerElement, { dragging: draggingRect, onMouseDown: addRectHandleMouseDown }),
1246
- React$1.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 }),
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$1.createElement("circle", { cursor: 'se-resize', cx: leftX + width, cy: topY + height, r: r, fill: 'blue', stroke: 'blue', onMouseDown: circleHandleMouseDown })) : null));
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$1.useEffect(function () {
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$1.createElement(SelectionFrame, __assign({}, props, { container: props.container })));
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$1.createContext({
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$1.forwardRef(function (_a, ref) {
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$1.useState(false), isSelected = _c[0], setIsSelected = _c[1];
1519
- var _d = React$1.useState(false), isEditing = _d[0], setIsEditing = _d[1];
1520
- var svgRef = React$1.useRef();
1521
- var _e = React$1.useContext(paperEventEmitterContext), onPaperClicked = _e.onPaperClicked, emitTextSelected = _e.emitTextSelected, onPortSelected = _e.onPortSelected, onElementSelected = _e.onElementSelected, onTextSelected = _e.onTextSelected;
1522
- React$1.useEffect(function () {
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$1.useMemo(function () {
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$1.createElement("svg", { style: { overflow: "visible" }, x: x, y: y, ref: function (node) {
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$1.createElement("foreignObject", { width: width, height: height, style: {
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$1.createElement("div", { style: {
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$1.createElement("textarea", { style: {
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 (onContentChanged) {
1680
+ if (editable) {
1639
1681
  setIsEditing(true);
1640
1682
  }
1641
1683
  }, value: content, onChange: handleChangeText })))));
1642
1684
  });
1643
- var Text$1 = React$1.memo(Text);
1685
+ var Text$1 = React.memo(Text);
1644
1686
 
1645
- var Port1 = React$1.forwardRef(function (props, ref) {
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$1.useState(false); _a[0]; _a[1];
1650
- var textRef = React$1.useRef(null);
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$1.useMemo(function () {
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$1.useEffect(function () {
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$1.createElement(Text$1, { id: label.id, ref: textRef, x: x + position.x, y: y + position.y, width: size.width, height: size.height, 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); } });
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$1.useMemo(function () {
1714
+ var renderedShape = React.useMemo(function () {
1673
1715
  if (renderShape) {
1674
1716
  var RenderShape = renderShape;
1675
- return (React$1.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1717
+ return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1676
1718
  }
1677
1719
  else {
1678
- return React$1.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" });
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$1.createElement(React$1.Fragment, null,
1723
+ return (React.createElement(React.Fragment, null,
1682
1724
  renderedShape,
1683
1725
  label && renderLabel(label)));
1684
1726
  });
1685
- var Port = React$1.memo(Port1);
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$1.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' },
1847
- React$1.createElement("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0", transform: "translate(3.84,3.84), scale(0.68)" },
1848
- React$1.createElement("rect", { x: "0", y: "0", width: "24.00", height: "24.00", rx: "12", fill: "#ffffff", strokeWidth: "0" })),
1849
- React$1.createElement("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round", stroke: "#CCCCCC", "stroke-width": "0.048" }),
1850
- React$1.createElement("g", { id: "SVGRepo_iconCarrier" },
1851
- React$1.createElement("g", null,
1852
- React$1.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
1853
- React$1.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" })))));
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 vertexes = getFourVertexesOfBBoxFromElement(ele);
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(vertexes[0].x, vertexes[0].y),
7511
+ Flatten$1.point(vertexes[1].x, vertexes[1].y),
7512
+ Flatten$1.point(vertexes[2].x, vertexes[2].y),
7513
+ Flatten$1.point(vertexes[3].x, vertexes[3].y),
7465
7514
  ]);
7466
7515
  return polygon;
7467
7516
  };
@@ -7503,44 +7552,37 @@ 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;
7506
- var vertex1Position = {
7507
- x: ele.position.x,
7508
- y: ele.position.y,
7509
- };
7510
- var vertex2Position = {
7511
- x: ele.position.x + ele.size.width,
7512
- y: ele.position.y,
7513
- };
7514
- var vertex3Position = {
7515
- x: ele.position.x + ele.size.width,
7516
- y: ele.position.y + ele.size.height,
7517
- };
7518
- var vertex4Position = {
7519
- x: ele.position.x,
7520
- y: ele.position.y + ele.size.height,
7521
- };
7555
+ var _a = getFourVertexesOfBBoxFromElement(ele), vertex1Position = _a[0], vertex2Position = _a[1], vertex3Position = _a[2], vertex4Position = _a[3];
7522
7556
  var replacementPosition = null;
7523
7557
  if (checkSamePosition(vertex1Position, intersectedPosition, 0)) {
7524
7558
  //Cut at vertex 1 of bbox, move out a distance x,y
7525
- replacementPosition.x = vertex1Position.x - translationOffset;
7526
- replacementPosition.y = vertex1Position.y - translationOffset;
7559
+ replacementPosition = {
7560
+ x: vertex1Position.x - translationOffset,
7561
+ y: vertex1Position.y - translationOffset,
7562
+ };
7527
7563
  }
7528
7564
  else if (checkSamePosition(vertex2Position, intersectedPosition, 0)) {
7529
7565
  //Cut at vertex 2 of bbox, move out a distance x,y
7530
- replacementPosition.x = vertex1Position.x + translationOffset;
7531
- replacementPosition.y = vertex1Position.y - translationOffset;
7566
+ replacementPosition = {
7567
+ x: vertex2Position.x + translationOffset,
7568
+ y: vertex2Position.y - translationOffset,
7569
+ };
7532
7570
  }
7533
7571
  else if (checkSamePosition(vertex3Position, intersectedPosition, 0)) {
7534
7572
  //Cut at vertex 3 of bbox, move out a distance x,y
7535
- replacementPosition.x = vertex1Position.x + translationOffset;
7536
- replacementPosition.y = vertex1Position.y + translationOffset;
7573
+ replacementPosition = {
7574
+ x: vertex3Position.x + translationOffset,
7575
+ y: vertex3Position.y + translationOffset,
7576
+ };
7537
7577
  }
7538
7578
  else if (checkSamePosition(vertex4Position, intersectedPosition, 0)) {
7539
7579
  //Cut at vertex 4 of bbox, move out a distance x,y
7540
- replacementPosition.x = vertex1Position.x - translationOffset;
7541
- replacementPosition.y = vertex1Position.y + translationOffset;
7580
+ replacementPosition = {
7581
+ x: vertex4Position.x - translationOffset,
7582
+ y: vertex4Position.y + translationOffset,
7583
+ };
7542
7584
  }
7543
- else if (intersectedPosition.y === ele.position.y) {
7585
+ else if (checkPositionOnLine(intersectedPosition, [vertex1Position, vertex2Position])) {
7544
7586
  //cut top edge, move left or right
7545
7587
  var lineOfVertex12 = Flatten$1.line(Flatten$1.point(vertex1Position.x, vertex1Position.y), Flatten$1.point(vertex2Position.x, vertex2Position.y));
7546
7588
  //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 +7606,7 @@ var generateSubstitutePosition = function (intersectedPosition, targetPosition,
7564
7606
  replacementPosition = findNearestPosition([leftPosition, rightPosition], targetPosition);
7565
7607
  }
7566
7608
  }
7567
- else if (intersectedPosition.y === ele.position.y + ele.size.height) {
7609
+ else if (checkPositionOnLine(intersectedPosition, [vertex3Position, vertex4Position])) {
7568
7610
  //cut bottom edge, move left or right
7569
7611
  var lineOfVertex34 = Flatten$1.line(Flatten$1.point(vertex3Position.x, vertex3Position.y), Flatten$1.point(vertex4Position.x, vertex4Position.y));
7570
7612
  if (Flatten$1.point(intersectedPosition.x, intersectedPosition.y).distanceTo(lineOfVertex34)[0] === 0 &&
@@ -7587,7 +7629,7 @@ var generateSubstitutePosition = function (intersectedPosition, targetPosition,
7587
7629
  replacementPosition = findNearestPosition([leftPosition, rightPosition], targetPosition);
7588
7630
  }
7589
7631
  }
7590
- else if (intersectedPosition.x === ele.position.x) {
7632
+ else if (checkPositionOnLine(intersectedPosition, [vertex1Position, vertex4Position])) {
7591
7633
  //cut left edge, move up or down
7592
7634
  var lineOfVertex14 = Flatten$1.line(Flatten$1.point(vertex1Position.x, vertex1Position.y), Flatten$1.point(vertex4Position.x, vertex4Position.y));
7593
7635
  if (Flatten$1.point(intersectedPosition.x, intersectedPosition.y).distanceTo(lineOfVertex14)[0] === 0 &&
@@ -7610,7 +7652,7 @@ var generateSubstitutePosition = function (intersectedPosition, targetPosition,
7610
7652
  replacementPosition = findNearestPosition([topPosition, bottomPosition], targetPosition);
7611
7653
  }
7612
7654
  }
7613
- else if (intersectedPosition.x === ele.position.x + ele.size.width) {
7655
+ else if (checkPositionOnLine(intersectedPosition, [vertex2Position, vertex3Position])) {
7614
7656
  //cut right edge, move up or down
7615
7657
  var lineOfVertex23 = Flatten$1.line(Flatten$1.point(vertex2Position.x, vertex2Position.y), Flatten$1.point(vertex3Position.x, vertex3Position.y));
7616
7658
  if (Flatten$1.point(intersectedPosition.x, intersectedPosition.y).distanceTo(lineOfVertex23)[0] === 0 &&
@@ -7641,27 +7683,46 @@ var getRelativePosition = function (clientPosition, relativeElement) {
7641
7683
  x: clientPosition.x - relativeRect.left,
7642
7684
  y: clientPosition.y - relativeRect.top,
7643
7685
  };
7686
+ };
7687
+ var getFourVertexesOfBBoxFromElement = function (element) {
7688
+ var vertex1Position = {
7689
+ x: element.position.x,
7690
+ y: element.position.y
7691
+ };
7692
+ var vertex2Position = {
7693
+ x: element.position.x + element.size.width,
7694
+ y: element.position.y
7695
+ };
7696
+ var vertex3Position = {
7697
+ x: element.position.x + element.size.width,
7698
+ y: element.position.y + element.size.height
7699
+ };
7700
+ var vertex4Position = {
7701
+ x: element.position.x,
7702
+ y: element.position.y + element.size.height
7703
+ };
7704
+ return [vertex1Position, vertex2Position, vertex3Position, vertex4Position];
7644
7705
  };
7645
7706
 
7646
- var makerStart = React$1.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
7647
- var makerEnd = React$1.createElement("path", { d: "M0 0 L 20 10 L0 20 Z", fill: "blue" }); //<path d="M0 0 L 10 5 L0 10 Z"></path>
7707
+ var makerStart = React.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
7708
+ 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
7709
  var IElementLink = function (_a) {
7649
7710
  var _b, _c;
7650
7711
  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$1.useState(path), pathStr = _j[0], setPathStr = _j[1];
7652
- var _k = React$1.useState(pointsProp !== null && pointsProp !== void 0 ? pointsProp : []), points = _k[0], setPoints = _k[1];
7653
- var _l = React$1.useState(false), isDragging = _l[0], setIsDragging = _l[1];
7654
- var _m = React$1.useState(), draggingPointIndex = _m[0], setDraggingPointIndex = _m[1];
7655
- var _o = React$1.useState({
7712
+ var _j = React.useState(path), pathStr = _j[0], setPathStr = _j[1];
7713
+ var _k = React.useState(pointsProp !== null && pointsProp !== void 0 ? pointsProp : []), points = _k[0], setPoints = _k[1];
7714
+ var _l = React.useState(false), isDragging = _l[0], setIsDragging = _l[1];
7715
+ var _m = React.useState(), draggingPointIndex = _m[0], setDraggingPointIndex = _m[1];
7716
+ var _o = React.useState({
7656
7717
  current: null,
7657
7718
  }), selectedLabelRef = _o[0], setSelectedLabelRef = _o[1];
7658
- var _p = React$1.useState(false), isSelectedLink = _p[0], setIsSelectedLink = _p[1];
7659
- var _q = React$1.useContext(paperEventEmitterContext), onPaperClicked = _q.onPaperClicked, onElementSelected = _q.onElementSelected;
7660
- var pathRef = React$1.useRef(null);
7661
- var labelRef = React$1.useRef(null);
7662
- var sourceLabelRef = React$1.useRef(null);
7663
- var targetLabelRef = React$1.useRef(null);
7664
- React$1.useEffect(function () {
7719
+ var _p = React.useState(false), isSelectedLink = _p[0], setIsSelectedLink = _p[1];
7720
+ var _q = React.useContext(paperEventEmitterContext), onPaperClicked = _q.onPaperClicked, onElementSelected = _q.onElementSelected;
7721
+ var pathRef = React.useRef(null);
7722
+ var labelRef = React.useRef(null);
7723
+ var sourceLabelRef = React.useRef(null);
7724
+ var targetLabelRef = React.useRef(null);
7725
+ React.useEffect(function () {
7665
7726
  var paperClickListener = onPaperClicked(function () {
7666
7727
  setSelectedLabelRef({
7667
7728
  current: null,
@@ -7673,7 +7734,7 @@ var IElementLink = function (_a) {
7673
7734
  paperClickListener.off();
7674
7735
  };
7675
7736
  }, []);
7676
- React$1.useEffect(function () {
7737
+ React.useEffect(function () {
7677
7738
  var elementSelectedListener = onElementSelected(function () {
7678
7739
  setSelectedLabelRef({
7679
7740
  current: null,
@@ -7685,17 +7746,17 @@ var IElementLink = function (_a) {
7685
7746
  elementSelectedListener.off();
7686
7747
  };
7687
7748
  }, []);
7688
- React$1.useLayoutEffect(function () {
7749
+ React.useLayoutEffect(function () {
7689
7750
  var pointsList = __spreadArray(__spreadArray([sourcePosition], points, true), [targetPosition], false);
7690
7751
  var _pathStr = createSmoothPathString(pointsList, undefined);
7691
7752
  setPathStr(_pathStr);
7692
7753
  }, [sourcePosition, points, targetPosition]);
7693
- React$1.useEffect(function () {
7754
+ React.useEffect(function () {
7694
7755
  if (!pathStr)
7695
7756
  return;
7696
7757
  onPathChanged === null || onPathChanged === void 0 ? void 0 : onPathChanged(pathStr, id);
7697
7758
  }, [pathStr, id]);
7698
- React$1.useLayoutEffect(function () {
7759
+ React.useLayoutEffect(function () {
7699
7760
  //handle when creating and moving point
7700
7761
  var handleMouseMove = function (ev) {
7701
7762
  var mouseEvent = ev;
@@ -7851,7 +7912,7 @@ var IElementLink = function (_a) {
7851
7912
  x: relativePosition.x + relativePositionTo.x,
7852
7913
  y: relativePosition.y + relativePositionTo.y,
7853
7914
  };
7854
- return (React$1.createElement(Text$1, { id: label.id, x: position.x, y: position.y, width: size.width, height: size.height, content: content, fontSize: label.fontSize, border: label.border, ref: curLabelRef, container: container, onSelected: function () { return setSelectedLabelRef(curLabelRef); }, onMoved: handleLabelMoved, onResized: handleLabelResized, onContentChanged: handleLabelContentChanged }));
7915
+ 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
7916
  };
7856
7917
  var angleMarkerStart = '0';
7857
7918
  var angleMarkerEnd = '0';
@@ -7869,28 +7930,28 @@ var IElementLink = function (_a) {
7869
7930
  }
7870
7931
  centerPathPosition = (_c = pathRef.current) === null || _c === void 0 ? void 0 : _c.getPointAtLength(pathRef.current.getTotalLength() / 2);
7871
7932
  }
7872
- return (React$1.createElement("g", null,
7873
- React$1.createElement("path", { ref: pathRef, d: pathStr, className: isSelectedLink ? CSS_CLASS_LINK_SELECTED : '', fill: "none", stroke: stroke || LINK_DEFAULT_COLOR, strokeWidth: strokeWidth }),
7874
- React$1.createElement("path", { d: pathStr, fill: "none", stroke: 'transparent', strokeWidth: LINK_CLICKABLE_STROKE_WIDTH, onClick: handleClickPath, onMouseDown: handleMouseDownOnPath }),
7875
- isSelectedLink && centerPathPosition && React$1.createElement("svg", { x: centerPathPosition.x - 10, y: centerPathPosition.y - 10 },
7876
- React$1.createElement(CloseIcon, { onClick: onClickDelete })),
7933
+ return (React.createElement("g", null,
7934
+ React.createElement("path", { ref: pathRef, d: pathStr, className: isSelectedLink ? CSS_CLASS_LINK_SELECTED : '', fill: "none", stroke: stroke || LINK_DEFAULT_COLOR, strokeWidth: strokeWidth }),
7935
+ React.createElement("path", { d: pathStr, fill: "none", stroke: 'transparent', strokeWidth: LINK_CLICKABLE_STROKE_WIDTH, onClick: handleClickPath, onMouseDown: handleMouseDownOnPath }),
7936
+ isSelectedLink && centerPathPosition && React.createElement("svg", { x: centerPathPosition.x - 10, y: centerPathPosition.y - 10 },
7937
+ React.createElement(CloseIcon, { onClick: onClickDelete })),
7877
7938
  label && renderLabel(label, 'middle', centerPathPosition),
7878
7939
  sourceLabel && renderLabel(sourceLabel, 'source', sourcePosition),
7879
7940
  targetLabel && renderLabel(targetLabel, 'target', targetPosition),
7880
- markerStartPosition && React$1.createElement("g", { transform: "rotate(".concat(angleMarkerStart, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
7881
- React$1.createElement("svg", { x: markerStartPosition.x - markerSize / 2, y: markerStartPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerStart)),
7882
- markerEndPosition && React$1.createElement("g", { transform: "rotate(".concat(angleMarkerEnd, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
7883
- React$1.createElement("svg", { x: markerEndPosition.x - markerSize / 2, y: markerEndPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerEnd))));
7941
+ markerStartPosition && React.createElement("g", { transform: "rotate(".concat(angleMarkerStart, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
7942
+ React.createElement("svg", { x: markerStartPosition.x - markerSize / 2, y: markerStartPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerStart)),
7943
+ markerEndPosition && React.createElement("g", { transform: "rotate(".concat(angleMarkerEnd, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
7944
+ React.createElement("svg", { x: markerEndPosition.x - markerSize / 2, y: markerEndPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerEnd))));
7884
7945
  };
7885
- var ElementLink = React$1.memo(IElementLink);
7946
+ var ElementLink = React.memo(IElementLink);
7886
7947
 
7887
7948
  var Ruler = function (_a) {
7888
7949
  var squareSize = _a.squareSize, border = _a.border;
7889
7950
  var numColumns = Math.ceil(3000 / squareSize);
7890
7951
  var numRows = Math.ceil(3000 / squareSize);
7891
7952
  var tableWidth = numColumns * squareSize;
7892
- return (React$1.createElement("table", { style: { position: 'absolute', zIndex: -1, top: 0, left: 0, borderCollapse: 'collapse', width: tableWidth } },
7893
- React$1.createElement("tbody", null, Array.from({ length: numRows }).map(function (_, rowIndex) { return (React$1.createElement("tr", { key: rowIndex, style: { margin: 0, padding: 0 } }, Array.from({ length: numColumns }).map(function (_, colIndex) { return (React$1.createElement("td", { key: colIndex, style: {
7953
+ return (React.createElement("table", { style: { position: 'absolute', zIndex: -1, top: 0, left: 0, borderCollapse: 'collapse', width: tableWidth } },
7954
+ 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
7955
  width: squareSize,
7895
7956
  height: squareSize,
7896
7957
  border: border,
@@ -7901,11 +7962,11 @@ var Ruler = function (_a) {
7901
7962
  position: 'relative',
7902
7963
  fontSize: 12,
7903
7964
  } },
7904
- rowIndex === 0 ? React$1.createElement("span", { style: { marginLeft: "-12px" } }, colIndex * squareSize) : "",
7905
- colIndex === 0 ? React$1.createElement("span", { style: { top: "-9px", position: "absolute" } }, rowIndex * squareSize) : "")); }))); }))));
7965
+ rowIndex === 0 ? React.createElement("span", { style: { marginLeft: "-12px" } }, colIndex * squareSize) : "",
7966
+ colIndex === 0 ? React.createElement("span", { style: { top: "-9px", position: "absolute" } }, rowIndex * squareSize) : "")); }))); }))));
7906
7967
  };
7907
7968
 
7908
- var ElementWrapper = React$1.forwardRef(function (_a, ref) {
7969
+ var ElementWrapper = React.forwardRef(function (_a, ref) {
7909
7970
  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
7971
  var handleMouseDown = function (ev) {
7911
7972
  ev.stopPropagation();
@@ -7920,7 +7981,7 @@ var ElementWrapper = React$1.forwardRef(function (_a, ref) {
7920
7981
  onContextMenu(ev);
7921
7982
  }
7922
7983
  };
7923
- return (React$1.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));
7984
+ 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
7985
  });
7925
7986
 
7926
7987
  // Calculate the position of the 4 vertices of a rectangle relative to its parent svg
@@ -7960,1275 +8021,50 @@ var getElementRotationInfo = function (element) {
7960
8021
  return rotationAngle;
7961
8022
  };
7962
8023
 
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
8024
  var Element = function (props) {
9192
- var _a, _b, _c;
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, textsPlaceHolderFlexStyle = props.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition = props.textsPlaceHolderFlexboxPosition, textsPlaceHolderClassName = props.textsPlaceHolderClassName, 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; props.onMouseMove; props.onMouseLeave; props.onMouseUp; var onMouseUpAtLinkedPortPlaceholder = props.onMouseUpAtLinkedPortPlaceholder, onTextUpdated = props.onTextUpdated;
9194
- var _d = React$1.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
9195
- var _e = React$1.useState(), hoveredPort = _e[0], setHoveredPort = _e[1];
9196
- var _f = React$1.useState((_a = props.ports) !== null && _a !== void 0 ? _a : []), ports = _f[0], setPorts = _f[1];
9197
- var _g = React$1.useState(false), someElementLinkStarted = _g[0], setSomeElementLinkStarted = _g[1];
9198
- var _h = React$1.useState(), potentialPortPosition = _h[0], setPotentialPortPosition = _h[1];
9199
- var _j = React$1.useState(false); _j[0]; _j[1];
9200
- var _paperEventEmitterContext = React$1.useContext(paperEventEmitterContext);
9201
- var elementRef = React$1.useRef(null);
9202
- var elementLinkStarted = React$1.useRef();
9203
- var portsRef = React$1.useRef(ports);
9204
- React$1.useEffect(function () {
8025
+ var _a, _b;
8026
+ 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;
8027
+ var _c = React.useState(), selectedPort = _c[0], setSelectedPort = _c[1];
8028
+ var _d = React.useState(), hoveredPort = _d[0], setHoveredPort = _d[1];
8029
+ var _e = React.useState([]), ports = _e[0], setPorts = _e[1];
8030
+ var _f = React.useState(false), someElementLinkStarted = _f[0], setSomeElementLinkStarted = _f[1];
8031
+ var _g = React.useState(), potentialPortPosition = _g[0], setPotentialPortPosition = _g[1];
8032
+ var _paperEventEmitterContext = React.useContext(paperEventEmitterContext);
8033
+ var elementRef = React.useRef(null);
8034
+ var elementLinkStarted = React.useRef();
8035
+ var portsRef = React.useRef(ports);
8036
+ React.useEffect(function () {
8037
+ console.log('changed props.children', texts === null || texts === void 0 ? void 0 : texts[0].content);
8038
+ }, [props.children]);
8039
+ React.useEffect(function () {
9205
8040
  return function () {
9206
8041
  var _a;
9207
8042
  console.log('un mount', (_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content);
9208
8043
  };
9209
8044
  }, []);
9210
8045
  //Listen to manually trigger render event
9211
- React$1.useEffect(function () {
9212
- var off = props.onManuallyTriggerRenderPort(function (portId, elementId) {
8046
+ React.useEffect(function () {
8047
+ var _a;
8048
+ var off = (_a = props.onManuallyTriggerRenderPort) === null || _a === void 0 ? void 0 : _a.call(props, function (portId, elementId) {
9213
8049
  if (elementId !== id)
9214
8050
  return;
9215
8051
  console.log('onManuallyTriggerRenderPort', id);
9216
8052
  setPorts(function (prev) { return __spreadArray([], prev, true); });
9217
8053
  });
9218
8054
  return function () {
9219
- off();
8055
+ off === null || off === void 0 ? void 0 : off();
9220
8056
  };
9221
8057
  }, [props.onManuallyTriggerRenderPort]);
9222
8058
  //Update portsRef when ports changed
9223
- React$1.useEffect(function () {
8059
+ React.useEffect(function () {
9224
8060
  portsRef.current = ports;
9225
8061
  }, [ports]);
9226
- React$1.useEffect(function () {
8062
+ React.useEffect(function () {
9227
8063
  var _a;
9228
- console.info('Rendering Element ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content) || id);
8064
+ console.info('Rendering Element ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content) || id, props.ports);
9229
8065
  });
9230
8066
  //Listen a new port is created, after add new port to ports state
9231
- React$1.useEffect(function () {
8067
+ React.useEffect(function () {
9232
8068
  console.info('Ports changed', props.ports);
9233
8069
  setPorts(function (prev) {
9234
8070
  var _a, _b;
@@ -9248,14 +8084,14 @@ var Element = function (props) {
9248
8084
  onPortMoved === null || onPortMoved === void 0 ? void 0 : onPortMoved(p, id, newPortState.position, newPosition);
9249
8085
  _paperEventEmitterContext.emitPortMoved(p, id, newPortState.position, newPosition);
9250
8086
  newPortState.position = newPosition;
9251
- newPortState.ref = React$1.createRef();
8087
+ newPortState.ref = React.createRef();
9252
8088
  }
9253
8089
  return newPortState;
9254
8090
  })) !== null && _b !== void 0 ? _b : [];
9255
8091
  });
9256
8092
  }, [props.ports]);
9257
8093
  //Listen trigger of Delete key, handle delete port is selected
9258
- React$1.useEffect(function () {
8094
+ React.useEffect(function () {
9259
8095
  var listener = _paperEventEmitterContext.onCommandDeleteSelectedPort(function () {
9260
8096
  if (selectedPort) {
9261
8097
  setPorts(function (prev) { return prev.filter(function (p) { return p.id !== selectedPort.id; }); });
@@ -9266,7 +8102,7 @@ var Element = function (props) {
9266
8102
  listener.off();
9267
8103
  };
9268
8104
  }, [selectedPort]);
9269
- React$1.useEffect(function () {
8105
+ React.useEffect(function () {
9270
8106
  //Listener onMouseDown event on #paper-container
9271
8107
  var eventListener = _paperEventEmitterContext.onPaperClicked(function (ev) {
9272
8108
  setSelectedPort(undefined);
@@ -9290,7 +8126,7 @@ var Element = function (props) {
9290
8126
  };
9291
8127
  }, [onPortMoved]);
9292
8128
  //Listen creating element link started, ended.
9293
- React$1.useEffect(function () {
8129
+ React.useEffect(function () {
9294
8130
  var elementStartedListener = _paperEventEmitterContext.onElementLinkStarted(function (tempLink) {
9295
8131
  elementLinkStarted.current = tempLink;
9296
8132
  setSomeElementLinkStarted(true);
@@ -9307,7 +8143,7 @@ var Element = function (props) {
9307
8143
  };
9308
8144
  }, []);
9309
8145
  //Listen another port is selected
9310
- React$1.useEffect(function () {
8146
+ React.useEffect(function () {
9311
8147
  var portSelectedListener = _paperEventEmitterContext.onPortSelected(function (port, elementId) {
9312
8148
  if (elementId !== id) {
9313
8149
  setSelectedPort(undefined);
@@ -9318,7 +8154,7 @@ var Element = function (props) {
9318
8154
  };
9319
8155
  }, []);
9320
8156
  //Listen text is selected
9321
- React$1.useEffect(function () {
8157
+ React.useEffect(function () {
9322
8158
  var textSelectedListener = _paperEventEmitterContext.onTextSelected(function (text) {
9323
8159
  setSelectedPort(undefined);
9324
8160
  });
@@ -9327,7 +8163,7 @@ var Element = function (props) {
9327
8163
  };
9328
8164
  }, []);
9329
8165
  //Listen another element is selected
9330
- React$1.useEffect(function () {
8166
+ React.useEffect(function () {
9331
8167
  var portSelectedListener = _paperEventEmitterContext.onElementSelected(function (element) {
9332
8168
  setSelectedPort(undefined);
9333
8169
  });
@@ -9335,7 +8171,7 @@ var Element = function (props) {
9335
8171
  portSelectedListener.off();
9336
8172
  };
9337
8173
  }, []);
9338
- var handleSelectedPort = React$1.useCallback(function (portId, e) {
8174
+ var handleSelectedPort = React.useCallback(function (portId, e) {
9339
8175
  e.stopPropagation();
9340
8176
  var port = portsRef.current.find(function (p) { return p.id === portId; });
9341
8177
  if (!port)
@@ -9377,7 +8213,7 @@ var Element = function (props) {
9377
8213
  }
9378
8214
  return coordinates;
9379
8215
  };
9380
- var getSlideRailSVG = React$1.useCallback(function (portSlideRailSVGClassName) {
8216
+ var getSlideRailSVG = React.useCallback(function (portSlideRailSVGClassName) {
9381
8217
  var _a;
9382
8218
  var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
9383
8219
  return slideRailSVG;
@@ -9442,7 +8278,7 @@ var Element = function (props) {
9442
8278
  }
9443
8279
  };
9444
8280
  //Handle when mouse down on port
9445
- var handlePortMouseDown = React$1.useCallback(function (portId, e) {
8281
+ var handlePortMouseDown = React.useCallback(function (portId, e) {
9446
8282
  e.stopPropagation();
9447
8283
  var port = portsRef.current.find(function (p) { return p.id === portId; });
9448
8284
  if (!port)
@@ -9451,7 +8287,7 @@ var Element = function (props) {
9451
8287
  onPortMouseDown === null || onPortMouseDown === void 0 ? void 0 : onPortMouseDown(e, port, id);
9452
8288
  }, [_paperEventEmitterContext]);
9453
8289
  //Handle when mouse up on port
9454
- var handlePortMouseUp = React$1.useCallback(function (portId, e) {
8290
+ var handlePortMouseUp = React.useCallback(function (portId, e) {
9455
8291
  e.stopPropagation();
9456
8292
  var port = portsRef.current.find(function (p) { return p.id === portId; });
9457
8293
  if (!port)
@@ -9464,7 +8300,7 @@ var Element = function (props) {
9464
8300
  }
9465
8301
  }, [_paperEventEmitterContext, potentialPortPosition]);
9466
8302
  //Update state when label of port is moved
9467
- var handlePortLabelMoved = React$1.useCallback(function (offsetX, offsetY, portId) {
8303
+ var handlePortLabelMoved = React.useCallback(function (offsetX, offsetY, portId) {
9468
8304
  setPorts(function (prevPorts) {
9469
8305
  return prevPorts.map(function (p) {
9470
8306
  if (p.id === portId && p.label) {
@@ -9479,7 +8315,7 @@ var Element = function (props) {
9479
8315
  });
9480
8316
  }, []);
9481
8317
  //Update state when label of port is resized
9482
- var handlePortLabelResized = React$1.useCallback(function (width, height, portId) {
8318
+ var handlePortLabelResized = React.useCallback(function (width, height, portId) {
9483
8319
  setPorts(function (prevPorts) {
9484
8320
  return prevPorts.map(function (p) {
9485
8321
  if (p.id === portId && p.label) {
@@ -9493,7 +8329,7 @@ var Element = function (props) {
9493
8329
  });
9494
8330
  }, []);
9495
8331
  //Update state when label of port is changed content
9496
- var handlePortLabelContentChanged = React$1.useCallback(function (ev, newValue, portId) {
8332
+ var handlePortLabelContentChanged = React.useCallback(function (ev, newValue, portId) {
9497
8333
  setPorts(function (prevPorts) {
9498
8334
  return prevPorts.map(function (p) {
9499
8335
  if (p.id === portId && p.label) {
@@ -9505,6 +8341,7 @@ var Element = function (props) {
9505
8341
  }, []);
9506
8342
  function handleElementMouseMove(ev) {
9507
8343
  //ev.stopPropagation(); //Can't use stopPropagation here, because do not create tempLink
8344
+ onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove(ev, id);
9508
8345
  if (someElementLinkStarted && elementRef.current) {
9509
8346
  //If an element link is being created, calculate the potential port position when the mouse moves over the element.
9510
8347
  if (hoveredPort) {
@@ -9539,12 +8376,14 @@ var Element = function (props) {
9539
8376
  }
9540
8377
  function handleElementMouseLeave(ev) {
9541
8378
  ev.stopPropagation();
8379
+ onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(ev, id);
9542
8380
  if (someElementLinkStarted) { //If an element link is being created, clear the placeholder when the mouse leaves the element.
9543
8381
  setPotentialPortPosition(undefined);
9544
8382
  }
9545
8383
  }
9546
8384
  var handleElementMouseUp = function (ev) {
9547
8385
  ev.stopPropagation();
8386
+ onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(ev, id);
9548
8387
  //If an element link is being created, trigger onMouseUpAtLinkedPortPlaceholder when the mouse up the element.
9549
8388
  if (potentialPortPosition && elementLinkStarted.current) {
9550
8389
  var newElementLink = __assign(__assign({}, elementLinkStarted.current), { tempTargetPosition: undefined });
@@ -9553,7 +8392,7 @@ var Element = function (props) {
9553
8392
  }
9554
8393
  };
9555
8394
  //Handle when mouse move on port
9556
- var handlePortMouseMove = React$1.useCallback(function (portId) {
8395
+ var handlePortMouseMove = React.useCallback(function (portId) {
9557
8396
  if (someElementLinkStarted) {
9558
8397
  var port = portsRef.current.find(function (p) { return p.id === portId; });
9559
8398
  if (!port)
@@ -9562,12 +8401,12 @@ var Element = function (props) {
9562
8401
  }
9563
8402
  }, [someElementLinkStarted]);
9564
8403
  //Handle when mouse leave on port
9565
- var handlePortMouseLeave = React$1.useCallback(function () {
8404
+ var handlePortMouseLeave = React.useCallback(function () {
9566
8405
  if (someElementLinkStarted)
9567
8406
  setHoveredPort(undefined);
9568
8407
  }, [someElementLinkStarted]);
9569
8408
  //Get rotate angle of port by port direction is defined.
9570
- var rotatePort = React$1.useCallback(function (x, y) {
8409
+ var rotatePort = React.useCallback(function (x, y) {
9571
8410
  // console.info('calculating port rotation', x, y)
9572
8411
  if (!portSlideRailSVGClassName)
9573
8412
  return 0;
@@ -9607,7 +8446,7 @@ var Element = function (props) {
9607
8446
  }
9608
8447
  return rotationAngle;
9609
8448
  }, [portSlideRailSVGClassName, portDirection, getSlideRailSVG]);
9610
- var renderedShape = React$1.useMemo(function () {
8449
+ var renderedShape = React.useMemo(function () {
9611
8450
  if (renderShape)
9612
8451
  return renderShape(props);
9613
8452
  return null;
@@ -9615,7 +8454,7 @@ var Element = function (props) {
9615
8454
  //Re-render port again after rendered to automation rotate port
9616
8455
  //Because elementRef.current equals null in first render so automation rotate port is incorrect.
9617
8456
  //TODO: check if this is still needed -> Still needed
9618
- React$1.useLayoutEffect(function () {
8457
+ React.useLayoutEffect(function () {
9619
8458
  if (elementRef.current) {
9620
8459
  setPorts(function (prev) { return __spreadArray([], prev, true); });
9621
8460
  }
@@ -9623,7 +8462,7 @@ var Element = function (props) {
9623
8462
  //use selection frame
9624
8463
  useSelectionFrame({
9625
8464
  container: container,
9626
- targetSVGElement: ((_b = selectedPort === null || selectedPort === void 0 ? void 0 : selectedPort.ref) === null || _b === void 0 ? void 0 : _b.current) || undefined,
8465
+ targetSVGElement: ((_a = selectedPort === null || selectedPort === void 0 ? void 0 : selectedPort.ref) === null || _a === void 0 ? void 0 : _a.current) || undefined,
9627
8466
  resizability: {
9628
8467
  enabled: false,
9629
8468
  keepRatio: false
@@ -9635,20 +8474,20 @@ var Element = function (props) {
9635
8474
  });
9636
8475
  useSelectionFrame({
9637
8476
  container: container,
9638
- targetSVGElement: ((_c = hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.ref) === null || _c === void 0 ? void 0 : _c.current) || undefined,
8477
+ targetSVGElement: ((_b = hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.ref) === null || _b === void 0 ? void 0 : _b.current) || undefined,
9639
8478
  resizability: {
9640
8479
  enabled: false,
9641
8480
  keepRatio: false
9642
8481
  },
9643
8482
  });
9644
- return (React$1.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; } },
8483
+ 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
8484
  renderedShape,
9646
8485
  potentialPortPosition && (portPlaceholderShape
9647
- ? React$1.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
9648
- : React$1.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 :
8486
+ ? React.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
8487
+ : 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
8488
  ports.map(function (p, index) {
9650
8489
  var _a, _b, _c, _d, _e, _f;
9651
- return React$1.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,
8490
+ 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
8491
  // rotation={rotatePort(p)}
9653
8492
  calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: handlePortLabelMoved, onPortLabelResized: handlePortLabelResized, onPortLabelContentChanged: handlePortLabelContentChanged, onSelected: handleSelectedPort, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, onMouseMove: handlePortMouseMove,
9654
8493
  // onMouseEnter={() => {
@@ -9657,14 +8496,14 @@ var Element = function (props) {
9657
8496
  onMouseLeave: handlePortMouseLeave,
9658
8497
  // onManuallyTriggerRenderHandler={p.manuallyTriggerRenderHandler?.bind(p)}
9659
8498
  renderShape: p.renderShape });
9660
- }),
9661
- React$1.createElement(Flexbox$1, { className: textsPlaceHolderClassName, style: textsPlaceHolderFlexStyle, x: textsPlaceHolderFlexboxPosition === null || textsPlaceHolderFlexboxPosition === void 0 ? void 0 : textsPlaceHolderFlexboxPosition.x, y: textsPlaceHolderFlexboxPosition === null || textsPlaceHolderFlexboxPosition === void 0 ? void 0 : textsPlaceHolderFlexboxPosition.y }, texts === null || texts === void 0 ? void 0 : texts.map(function (t, index) {
8499
+ }), texts === null || texts === void 0 ? void 0 :
8500
+ texts.map(function (t, index) {
9662
8501
  var _a, _b;
9663
- return React$1.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, 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); } });
9664
- })),
8502
+ 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); } });
8503
+ }),
9665
8504
  children));
9666
8505
  };
9667
- var Element$1 = React$1.memo(Element);
8506
+ var Element$1 = React.memo(Element);
9668
8507
 
9669
8508
  var createRect = function (x, y, width, height, strokeWidth, transformOrigin, transform) {
9670
8509
  var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
@@ -9682,9 +8521,9 @@ var createRect = function (x, y, width, height, strokeWidth, transformOrigin, tr
9682
8521
  };
9683
8522
  function BBoxDebugger(_a) {
9684
8523
  var elementSVG = _a.elementSVG;
9685
- var _b = React$1.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
9686
- var displayedBBoxDebug = React$1.useRef([]);
9687
- React$1.useEffect(function () {
8524
+ var _b = React.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
8525
+ var displayedBBoxDebug = React.useRef([]);
8526
+ React.useEffect(function () {
9688
8527
  var keyPress = function (ev) {
9689
8528
  if (ev.ctrlKey && ev.key === 'b') {
9690
8529
  setIsTurnOn(function (prev) { return !prev; });
@@ -9764,7 +8603,7 @@ function BBoxDebugger(_a) {
9764
8603
  }, 1000);
9765
8604
  return intervalId;
9766
8605
  };
9767
- React$1.useEffect(function () {
8606
+ React.useEffect(function () {
9768
8607
  if (!isTurnOn || !elementSVG)
9769
8608
  return;
9770
8609
  var listChildrenGroupByLevel = getListChildrenAndGroupSameLevel(elementSVG);
@@ -9776,12 +8615,12 @@ function BBoxDebugger(_a) {
9776
8615
  clearBBoxDebugger(displayedBBoxDebug.current);
9777
8616
  };
9778
8617
  }, [isTurnOn, elementSVG]);
9779
- return (React$1.createElement("div", { style: {
8618
+ return (React.createElement("div", { style: {
9780
8619
  position: 'fixed',
9781
8620
  top: 20,
9782
8621
  right: 20
9783
8622
  } },
9784
- React$1.createElement("div", { style: {
8623
+ React.createElement("div", { style: {
9785
8624
  backgroundColor: 'white',
9786
8625
  boxShadow: '0px 1px 4px 1px',
9787
8626
  borderRadius: 4,
@@ -9805,9 +8644,9 @@ var createDebuggerPoint = function (cx, cy) {
9805
8644
  };
9806
8645
  var LinkDebugger = function (_a) {
9807
8646
  var links = _a.links, svgContainer = _a.svgContainer;
9808
- var _b = React$1.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
9809
- var displayedDebuggerPoint = React$1.useRef([]);
9810
- React$1.useEffect(function () {
8647
+ var _b = React.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
8648
+ var displayedDebuggerPoint = React.useRef([]);
8649
+ React.useEffect(function () {
9811
8650
  var keyPress = function (ev) {
9812
8651
  if (ev.ctrlKey && ev.key === 'l') {
9813
8652
  setIsTurnOn(function (prev) { return !prev; });
@@ -9824,7 +8663,7 @@ var LinkDebugger = function (_a) {
9824
8663
  ele === null || ele === void 0 ? void 0 : ele.remove();
9825
8664
  }
9826
8665
  };
9827
- React$1.useEffect(function () {
8666
+ React.useEffect(function () {
9828
8667
  if (isTurnOn) {
9829
8668
  links.forEach(function (link) {
9830
8669
  var _a;
@@ -9839,13 +8678,13 @@ var LinkDebugger = function (_a) {
9839
8678
  clearDebuggerPoint();
9840
8679
  };
9841
8680
  }, [isTurnOn, links]);
9842
- return (React$1.createElement("div", null));
8681
+ return (React.createElement("div", null));
9843
8682
  };
9844
8683
 
9845
8684
  function useKeyboardCommands(_a) {
9846
8685
  var element = _a.element;
9847
- var _b = React$1.useContext(paperEventEmitterContext), emitCommandDeleteSelectedElement = _b.emitCommandDeleteSelectedElement, emitCommandDeleteSelectedLink = _b.emitCommandDeleteSelectedLink, emitCommandDeleteSelectedPort = _b.emitCommandDeleteSelectedPort, emitCommandDeleteSelectedText = _b.emitCommandDeleteSelectedText;
9848
- React$1.useEffect(function () {
8686
+ var _b = React.useContext(paperEventEmitterContext), emitCommandDeleteSelectedElement = _b.emitCommandDeleteSelectedElement, emitCommandDeleteSelectedLink = _b.emitCommandDeleteSelectedLink, emitCommandDeleteSelectedPort = _b.emitCommandDeleteSelectedPort, emitCommandDeleteSelectedText = _b.emitCommandDeleteSelectedText;
8687
+ React.useEffect(function () {
9849
8688
  var callback = function (ev) {
9850
8689
  var keyboardEv = ev;
9851
8690
  if (keyboardEv.key === "Delete") {
@@ -9894,34 +8733,34 @@ function convertElementsToTree(elements) {
9894
8733
  return parsedElementsInTree;
9895
8734
  }
9896
8735
  var Paper = function (props) {
9897
- var _a = React$1.useState([]), elements = _a[0], setElements = _a[1];
9898
- var _b = React$1.useState([]), elementsInTree = _b[0], setElementsInTree = _b[1];
9899
- var _c = React$1.useState(), selectedElement = _c[0], setSelectedElement = _c[1];
9900
- var _d = React$1.useState([]), links = _d[0], setLinks = _d[1];
9901
- var _e = React$1.useState(), selectedLink = _e[0], setSelectedLink = _e[1];
9902
- var _f = React$1.useState(null), tempLink = _f[0], setTempLink = _f[1];
9903
- var _g = React$1.useState([]), texts = _g[0], setTexts = _g[1];
9904
- var _h = React$1.useState(), selectedText = _h[0], setSelectedText = _h[1];
9905
- var _j = React$1.useState(null), selectedElementSVG = _j[0], setSelectedElementSVG = _j[1];
9906
- var _k = React$1.useState(false), mouseDownedOnPaper = _k[0], setMouseDownedOnPaper = _k[1];
9907
- var paperEventEmitter = React$1.useContext(paperEventEmitterContext);
9908
- var paperContainerRef = React$1.useRef(null);
9909
- var tempLinkRef = React$1.useRef(tempLink); //Cache tempLink to avoid re-render when tempLink changed
9910
- var elementsRef = React$1.useRef(elements); //Cache elements to avoid re-render when elements changed
8736
+ var _a = React.useState([]), elements = _a[0], setElements = _a[1];
8737
+ var _b = React.useState([]), elementsInTree = _b[0], setElementsInTree = _b[1];
8738
+ var _c = React.useState(), selectedElement = _c[0], setSelectedElement = _c[1];
8739
+ var _d = React.useState([]), links = _d[0], setLinks = _d[1];
8740
+ var _e = React.useState(), selectedLink = _e[0], setSelectedLink = _e[1];
8741
+ var _f = React.useState(null), tempLink = _f[0], setTempLink = _f[1];
8742
+ var _g = React.useState([]), texts = _g[0], setTexts = _g[1];
8743
+ var _h = React.useState(), selectedText = _h[0], setSelectedText = _h[1];
8744
+ var _j = React.useState(null), selectedElementSVG = _j[0], setSelectedElementSVG = _j[1];
8745
+ var _k = React.useState(false), mouseDownedOnPaper = _k[0], setMouseDownedOnPaper = _k[1];
8746
+ var paperEventEmitter = React.useContext(paperEventEmitterContext);
8747
+ var paperContainerRef = React.useRef(null);
8748
+ var tempLinkRef = React.useRef(tempLink); //Cache tempLink to avoid re-render when tempLink changed
8749
+ var elementsRef = React.useRef(elements); //Cache elements to avoid re-render when elements changed
9911
8750
  var size = props.size;
9912
- React$1.useEffect(function () {
8751
+ React.useEffect(function () {
9913
8752
  console.log('Render Paper');
9914
8753
  });
9915
- React$1.useEffect(function () {
8754
+ React.useEffect(function () {
9916
8755
  setElements(props.elements);
9917
8756
  }, [props.elements]);
9918
- React$1.useEffect(function () {
8757
+ React.useEffect(function () {
9919
8758
  setLinks(props.links || []);
9920
8759
  }, [props.links]);
9921
- React$1.useEffect(function () {
8760
+ React.useEffect(function () {
9922
8761
  setTexts(props.texts);
9923
8762
  }, [props.texts]);
9924
- React$1.useEffect(function () {
8763
+ React.useEffect(function () {
9925
8764
  var off = props.onManuallyTriggerRenderElement(function (elementId) {
9926
8765
  console.log('onManuallyTriggerRenderElement');
9927
8766
  setElements(function (prev) { return __spreadArray([], prev, true); });
@@ -9931,7 +8770,7 @@ var Paper = function (props) {
9931
8770
  };
9932
8771
  }, [props.onManuallyTriggerRenderElement]);
9933
8772
  //Cache elements to avoid re-render when elements changed
9934
- React$1.useEffect(function () {
8773
+ React.useEffect(function () {
9935
8774
  elementsRef.current = elements;
9936
8775
  }, [elements]);
9937
8776
  useKeyboardCommands({
@@ -9942,11 +8781,11 @@ var Paper = function (props) {
9942
8781
  setElementsInTree(parsedElementsInTree);
9943
8782
  };
9944
8783
  //Cache tempLink to avoid re-render when tempLink changed
9945
- React$1.useEffect(function () {
8784
+ React.useEffect(function () {
9946
8785
  tempLinkRef.current = tempLink;
9947
8786
  }, [tempLink]);
9948
8787
  //Listen text is selected
9949
- React$1.useEffect(function () {
8788
+ React.useEffect(function () {
9950
8789
  var textSelectedListener = paperEventEmitter.onTextSelected(function (text) {
9951
8790
  var _a;
9952
8791
  setSelectedElement(undefined);
@@ -9960,7 +8799,7 @@ var Paper = function (props) {
9960
8799
  };
9961
8800
  }, []);
9962
8801
  //Listen port is selected
9963
- React$1.useEffect(function () {
8802
+ React.useEffect(function () {
9964
8803
  var portSelectedListener = paperEventEmitter.onPortSelected(function (port, elementId) {
9965
8804
  var _a;
9966
8805
  setSelectedElement(undefined);
@@ -9976,11 +8815,12 @@ var Paper = function (props) {
9976
8815
  portSelectedListener.off();
9977
8816
  };
9978
8817
  }, []);
9979
- React$1.useEffect(function () {
8818
+ React.useEffect(function () {
9980
8819
  //Listen parent of elements changed, then update elements tree
9981
8820
  var parentChangedCancelers = elementsRef.current.map(function (element) {
9982
8821
  var _a;
9983
8822
  return (_a = element.onParentChanged) === null || _a === void 0 ? void 0 : _a.call(element, function (newPa, oldPa) {
8823
+ console.log('onParentChanged');
9984
8824
  updateElementsTree();
9985
8825
  });
9986
8826
  });
@@ -10002,9 +8842,9 @@ var Paper = function (props) {
10002
8842
  parentChangedCancelers.forEach(function (canceller) { return canceller === null || canceller === void 0 ? void 0 : canceller(); });
10003
8843
  addedPortCancelers.forEach(function (canceller) { return canceller(); });
10004
8844
  };
10005
- }, []);
8845
+ }, [elements]);
10006
8846
  //Update elements tree when length of elements change
10007
- React$1.useEffect(function () {
8847
+ React.useEffect(function () {
10008
8848
  updateElementsTree();
10009
8849
  }, [elements]);
10010
8850
  //Get all child elements of the deleted element
@@ -10018,7 +8858,7 @@ var Paper = function (props) {
10018
8858
  return __spreadArray(__spreadArray([], childElms, true), childOfChildElements, true);
10019
8859
  };
10020
8860
  //Listen command delete selected for element
10021
- React$1.useEffect(function () {
8861
+ React.useEffect(function () {
10022
8862
  var _a;
10023
8863
  var listener = paperEventEmitter.onCommandDeleteSelectedElement(function () {
10024
8864
  if (selectedElement) {
@@ -10039,7 +8879,7 @@ var Paper = function (props) {
10039
8879
  };
10040
8880
  }, [selectedElement]);
10041
8881
  //Listen command delete selected for link
10042
- React$1.useEffect(function () {
8882
+ React.useEffect(function () {
10043
8883
  var _a;
10044
8884
  var listener = paperEventEmitter.onCommandDeleteSelectedLink(function () {
10045
8885
  if (selectedLink) {
@@ -10056,7 +8896,7 @@ var Paper = function (props) {
10056
8896
  };
10057
8897
  }, [selectedLink]);
10058
8898
  //Listen command delete selected for Text
10059
- React$1.useEffect(function () {
8899
+ React.useEffect(function () {
10060
8900
  var _a;
10061
8901
  var listener = paperEventEmitter.onCommandDeleteSelectedText(function () {
10062
8902
  if (selectedText) {
@@ -10073,8 +8913,11 @@ var Paper = function (props) {
10073
8913
  };
10074
8914
  }, [selectedText]);
10075
8915
  //Automatically add points on the link so that the link does not cross elements, default maximum 10 points
10076
- var automationAddPointsToLink = React$1.useCallback(function (eleLink, limitPoint) {
8916
+ var automationAddPointsToLink = React.useCallback(function (eleLink, limitPoint) {
10077
8917
  if (limitPoint === void 0) { limitPoint = 10; }
8918
+ if (!eleLink.targetElement) {
8919
+ throw new Error("Target element is not found in element link");
8920
+ }
10078
8921
  var sourceElement = eleLink.sourceElement, sourcePort = eleLink.sourcePort, targetElement = eleLink.targetElement, targetPort = eleLink.targetPort;
10079
8922
  var sourcePosition = {
10080
8923
  x: sourceElement.position.x + sourcePort.position.x,
@@ -10084,6 +8927,20 @@ var Paper = function (props) {
10084
8927
  x: targetElement.position.x + targetPort.position.x,
10085
8928
  y: targetElement.position.y + targetPort.position.y
10086
8929
  };
8930
+ var fourVertexesOfSourceEleBBox = getFourVertexesOfBBoxFromElement(sourceElement);
8931
+ var fourVertexesOfTargetEleBBox = getFourVertexesOfBBoxFromElement(targetElement);
8932
+ var projectedSourcePositionOnBBox = findNearestProjectedPoint(sourcePosition, [
8933
+ [fourVertexesOfSourceEleBBox[0], fourVertexesOfSourceEleBBox[1]],
8934
+ [fourVertexesOfSourceEleBBox[1], fourVertexesOfSourceEleBBox[2]],
8935
+ [fourVertexesOfSourceEleBBox[2], fourVertexesOfSourceEleBBox[3]],
8936
+ [fourVertexesOfSourceEleBBox[3], fourVertexesOfSourceEleBBox[0]],
8937
+ ]);
8938
+ var projectedTargetPositionOnBBox = findNearestProjectedPoint(targetPosition, [
8939
+ [fourVertexesOfTargetEleBBox[0], fourVertexesOfTargetEleBBox[1]],
8940
+ [fourVertexesOfTargetEleBBox[1], fourVertexesOfTargetEleBBox[2]],
8941
+ [fourVertexesOfTargetEleBBox[2], fourVertexesOfTargetEleBBox[3]],
8942
+ [fourVertexesOfTargetEleBBox[3], fourVertexesOfTargetEleBBox[0]],
8943
+ ]);
10087
8944
  var numberOfPoints = 0;
10088
8945
  //create points between the start and end points, to create a line segment that passes through the points without intersecting the elements
10089
8946
  function generatePositions(sourcePosition, targetPosition, elements) {
@@ -10103,7 +8960,7 @@ var Paper = function (props) {
10103
8960
  return __spreadArray(__spreadArray(__spreadArray([], prependedPoints, true), [replacementPosition], false), appendedPoints, true);
10104
8961
  }
10105
8962
  var elements = elementsRef.current;
10106
- var points = generatePositions(sourcePosition, targetPosition, elements);
8963
+ var points = generatePositions(projectedSourcePositionOnBBox, projectedTargetPositionOnBBox, elements);
10107
8964
  return __assign(__assign({}, eleLink), { points: points });
10108
8965
  }, []);
10109
8966
  var handlePaperMouseMove = function (ev) {
@@ -10168,7 +9025,7 @@ var Paper = function (props) {
10168
9025
  y: ev.clientY
10169
9026
  });
10170
9027
  };
10171
- var handlePathChange = React$1.useCallback(function (path, id) {
9028
+ var handlePathChange = React.useCallback(function (path, id) {
10172
9029
  //Update path of element link, that changed
10173
9030
  setLinks(function (prevLinks) {
10174
9031
  var updatedLinkIndex = prevLinks.findIndex(function (l) { return l.id === id; });
@@ -10176,7 +9033,7 @@ var Paper = function (props) {
10176
9033
  return __spreadArray([], prevLinks, true);
10177
9034
  });
10178
9035
  }, []);
10179
- var handlePortMoved = React$1.useCallback(function (port, elementId, oldPosition, newPosition) {
9036
+ var handlePortMoved = React.useCallback(function (port, elementId, oldPosition, newPosition) {
10180
9037
  var element = elementsRef.current.find(function (e) { return e.id === elementId; });
10181
9038
  if (element) {
10182
9039
  //set links equals a clone links to re-render links with new position
@@ -10208,23 +9065,27 @@ var Paper = function (props) {
10208
9065
  }
10209
9066
  }, [props.onPortMoved]);
10210
9067
  //Handle creating a new element link
10211
- var handlePortMouseDown = React$1.useCallback(function (ev, port, elementId) {
9068
+ var handlePortMouseDown = React.useCallback(function (ev, port, elementId) {
9069
+ var _a;
10212
9070
  ev.stopPropagation();
10213
- //Return if creating a new element link
10214
- if (tempLinkRef.current)
10215
- return;
10216
- var sourceElement = elementsRef.current.find(function (e) { return e.id === elementId; });
10217
- //handle create temp element link;
10218
- var newLink = {
10219
- id: generateUniqueId(),
10220
- points: [],
10221
- sourceElement: sourceElement,
10222
- sourcePort: port,
10223
- };
10224
- setTempLink(newLink);
10225
- paperEventEmitter.emitElementLinkStarted(newLink);
10226
- }, [paperEventEmitter]);
10227
- var createElementLink = React$1.useCallback(function (sourcePort, sourceElement, targetPort, targetElement) {
9071
+ var element = elementsRef.current.find(function (e) { return e.id === elementId; });
9072
+ //broadcast port mouse down to parent component
9073
+ if (element) {
9074
+ (_a = props.onPortMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, port, element);
9075
+ }
9076
+ if (!tempLinkRef.current && element) {
9077
+ //handle create temp element link;
9078
+ var newLink = {
9079
+ id: generateUniqueId(),
9080
+ points: [],
9081
+ sourceElement: element,
9082
+ sourcePort: port,
9083
+ };
9084
+ setTempLink(newLink);
9085
+ paperEventEmitter.emitElementLinkStarted(newLink);
9086
+ }
9087
+ }, [paperEventEmitter, props.onPortMouseDown]);
9088
+ var createElementLink = React.useCallback(function (sourcePort, sourceElement, targetPort, targetElement) {
10228
9089
  //if no onCreatingLink prop, no link will be created
10229
9090
  if (!props.onCreatingLink) {
10230
9091
  return null;
@@ -10238,15 +9099,21 @@ var Paper = function (props) {
10238
9099
  }
10239
9100
  return newElementLink;
10240
9101
  }, [props.onCreatingLink, automationAddPointsToLink]);
10241
- var handlePortMouseUp = React$1.useCallback(function (ev, port, elementId) {
9102
+ var handlePortMouseUp = React.useCallback(function (ev, port, elementId) {
9103
+ var _a;
10242
9104
  ev.stopPropagation();
9105
+ var element = elementsRef.current.find(function (e) { return e.id === elementId; });
9106
+ //broadcast port mouse down to parent component
9107
+ if (element) {
9108
+ (_a = props.onPortMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, port, element);
9109
+ }
10243
9110
  //Create new element link, if has tempLink
10244
9111
  if (tempLinkRef.current) {
10245
9112
  //Check if mouse up point is mouse down point or not
10246
9113
  var isMouseUpOnNotSelf = tempLinkRef.current.sourcePort.id !== port.id || tempLinkRef.current.sourceElement.id !== elementId;
10247
9114
  var newElementLink_1 = null;
10248
9115
  if (isMouseUpOnNotSelf) {
10249
- var _a = tempLinkRef.current, sourcePort = _a.sourcePort, sourceElement = _a.sourceElement;
9116
+ var _b = tempLinkRef.current, sourcePort = _b.sourcePort, sourceElement = _b.sourceElement;
10250
9117
  var targetElement = elementsRef.current.find(function (e) { return e.id === elementId; });
10251
9118
  newElementLink_1 = createElementLink(sourcePort, sourceElement, port, targetElement);
10252
9119
  }
@@ -10259,8 +9126,8 @@ var Paper = function (props) {
10259
9126
  }
10260
9127
  setTempLink(null);
10261
9128
  }
10262
- }, [paperEventEmitter, createElementLink]);
10263
- var handleLinkLabelMoved = React$1.useCallback(function (offsetX, offsetY, index, labelType) {
9129
+ }, [paperEventEmitter, createElementLink, props.onPortMouseUp]);
9130
+ var handleLinkLabelMoved = React.useCallback(function (offsetX, offsetY, index, labelType) {
10264
9131
  setLinks(function (prevLinks) {
10265
9132
  var newLinks = __spreadArray([], prevLinks, true);
10266
9133
  var currentLink = newLinks[index];
@@ -10296,7 +9163,7 @@ var Paper = function (props) {
10296
9163
  return newLinks;
10297
9164
  });
10298
9165
  }, []);
10299
- var handleLinkLabelResized = React$1.useCallback(function (width, height, index, labelType) {
9166
+ var handleLinkLabelResized = React.useCallback(function (width, height, index, labelType) {
10300
9167
  setLinks(function (prevLinks) {
10301
9168
  var newLinks = __spreadArray([], prevLinks, true);
10302
9169
  var currentLink = newLinks[index];
@@ -10329,7 +9196,7 @@ var Paper = function (props) {
10329
9196
  return newLinks;
10330
9197
  });
10331
9198
  }, []);
10332
- var handleLinkLabelContentChanged = React$1.useCallback(function (newValue, index, labelType) {
9199
+ var handleLinkLabelContentChanged = React.useCallback(function (newValue, index, labelType) {
10333
9200
  setLinks(function (prevLinks) {
10334
9201
  var newLinks = __spreadArray([], prevLinks, true);
10335
9202
  var currentLink = newLinks[index];
@@ -10413,7 +9280,7 @@ var Paper = function (props) {
10413
9280
  Cache to avoid re-initializing the function when the component re-renders to
10414
9281
  avoid causing the components using it to re-render unnecessarily
10415
9282
  */
10416
- var onLabelMoved = React$1.useCallback(function (index) {
9283
+ var onLabelMoved = React.useCallback(function (index) {
10417
9284
  return function (offsetX, offsetY, labelType) {
10418
9285
  handleLinkLabelMoved(offsetX, offsetY, index, labelType);
10419
9286
  };
@@ -10422,7 +9289,7 @@ var Paper = function (props) {
10422
9289
  Cache to avoid re-initializing the function when the component re-renders to
10423
9290
  avoid causing the components using it to re-render unnecessarily
10424
9291
  */
10425
- var onLabelResized = React$1.useCallback(function (index) {
9292
+ var onLabelResized = React.useCallback(function (index) {
10426
9293
  return function (width, height, labelType) {
10427
9294
  handleLinkLabelResized(width, height, index, labelType);
10428
9295
  };
@@ -10431,12 +9298,12 @@ var Paper = function (props) {
10431
9298
  Cache to avoid re-initializing the function when the component re-renders to
10432
9299
  avoid causing the components using it to re-render unnecessarily
10433
9300
  */
10434
- var onLabelContentChanged = React$1.useCallback(function (index) {
9301
+ var onLabelContentChanged = React.useCallback(function (index) {
10435
9302
  return function (newValue, labelType) {
10436
9303
  handleLinkLabelContentChanged(newValue, index, labelType);
10437
9304
  };
10438
9305
  }, [handleLinkLabelContentChanged]);
10439
- var handleClickLinkDelete = React$1.useCallback(function (link, index) {
9306
+ var handleClickLinkDelete = React.useCallback(function (link, index) {
10440
9307
  return function () {
10441
9308
  setLinks(function (prevLinks) {
10442
9309
  var newLinks = __spreadArray([], prevLinks, true);
@@ -10445,7 +9312,7 @@ var Paper = function (props) {
10445
9312
  });
10446
9313
  };
10447
9314
  }, []);
10448
- var handleMouseUpAtLinkedPortPlaceholder = React$1.useCallback(function (link, position, targetElementId) {
9315
+ var handleMouseUpAtLinkedPortPlaceholder = React.useCallback(function (link, position, targetElementId) {
10449
9316
  var targetElement = elementsRef.current.find(function (e) { return e.id === targetElementId; });
10450
9317
  if (!targetElement)
10451
9318
  return;
@@ -10472,7 +9339,7 @@ var Paper = function (props) {
10472
9339
  setTempLink(null);
10473
9340
  paperEventEmitter.emitElementLinkEnded();
10474
9341
  }, [props.onCreatingPortByLinking, createElementLink, paperEventEmitter]);
10475
- var handleElementTextChange = React$1.useCallback(function (elementId, textId, newContent) {
9342
+ var handleElementTextChange = React.useCallback(function (elementId, textId, newContent) {
10476
9343
  setElements(function (prevElms) {
10477
9344
  return prevElms.map(function (curEle) {
10478
9345
  //Find changed text of element to update the content for it.
@@ -10486,7 +9353,7 @@ var Paper = function (props) {
10486
9353
  });
10487
9354
  });
10488
9355
  }, []);
10489
- var handleElementClicked = React$1.useCallback(function (elementId, e, ref) {
9356
+ var handleElementClicked = React.useCallback(function (elementId, e, ref) {
10490
9357
  e.stopPropagation();
10491
9358
  var tempLink = tempLinkRef.current;
10492
9359
  if (tempLink) {
@@ -10504,7 +9371,7 @@ var Paper = function (props) {
10504
9371
  }
10505
9372
  setMouseDownedOnPaper(false);
10506
9373
  }, [paperEventEmitter]);
10507
- var handleContextMenu = React$1.useCallback(function (elementId, e, ref) {
9374
+ var handleContextMenu = React.useCallback(function (elementId, e, ref) {
10508
9375
  var _a;
10509
9376
  e.preventDefault();
10510
9377
  var element = elementsRef.current.find(function (e) { return e.id === elementId; });
@@ -10513,34 +9380,54 @@ var Paper = function (props) {
10513
9380
  (_a = props.onElementContextMenu) === null || _a === void 0 ? void 0 : _a.call(props, element, e);
10514
9381
  }
10515
9382
  }, [props.onElementContextMenu, handleElementClicked]);
10516
- var renderElementInTree = React$1.useCallback(function (element) {
9383
+ var handleMouseUp = React.useCallback(function (ev, elementId) {
9384
+ var _a;
9385
+ var element = elementsRef.current.find(function (ele) { return ele.id === elementId; });
9386
+ if (element) {
9387
+ (_a = props.onElementMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, ev, element);
9388
+ }
9389
+ }, [props.onElementMouseUp]);
9390
+ var handleMouseMove = React.useCallback(function (ev, elementId) {
9391
+ var _a;
9392
+ var element = elementsRef.current.find(function (ele) { return ele.id === elementId; });
9393
+ if (element) {
9394
+ (_a = props.onElementMouseMove) === null || _a === void 0 ? void 0 : _a.call(props, ev, element);
9395
+ }
9396
+ }, [props.onElementMouseMove]);
9397
+ var handleMouseLeave = React.useCallback(function (ev, elementId) {
9398
+ var _a;
9399
+ var element = elementsRef.current.find(function (ele) { return ele.id === elementId; });
9400
+ if (element) {
9401
+ (_a = props.onElementMouseLeave) === null || _a === void 0 ? void 0 : _a.call(props, ev, element);
9402
+ }
9403
+ }, [props.onElementMouseLeave]);
9404
+ var renderElementInTree = React.useCallback(function (element) {
10517
9405
  var _a, _b;
10518
9406
  //use the defined react element or the default Element component
10519
9407
  var ReactElement = element.reactElement || Element$1;
10520
- console.log("Render element ".concat(element.id));
10521
- return (React$1.createElement("g", { key: element.id },
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,
9408
+ return (React.createElement("g", { key: element.id },
9409
+ 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
9410
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
10524
9411
  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$1.useEffect(function () {
9412
+ }, [handleElementClicked, handleContextMenu, handlePortMoved, handlePortMouseDown, handlePortMouseUp, handleMouseUpAtLinkedPortPlaceholder, handleElementTextChange, handleMouseUp, handleMouseMove, handleMouseLeave]);
9413
+ React.useEffect(function () {
10527
9414
  console.log('elementsInTree');
10528
9415
  }, [elementsInTree]);
10529
- React$1.useEffect(function () {
9416
+ React.useEffect(function () {
10530
9417
  console.log('renderElementInTree');
10531
9418
  }, [renderElementInTree]);
10532
- var ElementsInTree = React$1.useMemo(function () {
9419
+ var ElementsInTree = React.useMemo(function () {
10533
9420
  return elementsInTree.map(function (element, index) {
10534
9421
  return renderElementInTree(element);
10535
9422
  });
10536
9423
  }, [elementsInTree, renderElementInTree]);
10537
- return (React$1.createElement("div", { style: { position: "relative" } },
10538
- React$1.createElement(Ruler, { squareSize: 100, border: '1px dashed grey' }),
10539
- React$1.createElement("svg", { tabIndex: 0, width: size.width, height: size.height, ref: paperContainerRef, id: "paper-container", onMouseMove: handlePaperMouseMove, onMouseDown: handleMouseDownOnPaper, onMouseUp: handleMouseUpOnPaper },
9424
+ return (React.createElement("div", { style: { position: "relative" } },
9425
+ React.createElement(Ruler, { squareSize: 100, border: '1px dashed grey' }),
9426
+ React.createElement("svg", { tabIndex: 0, width: size.width, height: size.height, ref: paperContainerRef, id: "paper-container", onMouseMove: handlePaperMouseMove, onMouseDown: handleMouseDownOnPaper, onMouseUp: handleMouseUpOnPaper },
10540
9427
  paperContainerRef.current ? ElementsInTree : "",
10541
9428
  links && links.map(function (link, index) {
10542
9429
  var _a, _b, _c, _d;
10543
- return (React$1.createElement(ElementLink, { key: link.id, id: link.id, path: link.path, sourcePosition: {
9430
+ return (React.createElement(ElementLink, { key: link.id, id: link.id, path: link.path, sourcePosition: {
10544
9431
  x: link.sourceElement.position.x + link.sourcePort.position.x,
10545
9432
  y: link.sourceElement.position.y + link.sourcePort.position.y
10546
9433
  }, targetPosition: {
@@ -10548,40 +9435,40 @@ var Paper = function (props) {
10548
9435
  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
9436
  }, 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
9437
  }),
10551
- (tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React$1.createElement(ElementLink, { id: tempLink.id, points: tempLink.points, sourcePosition: {
9438
+ (tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React.createElement(ElementLink, { id: tempLink.id, points: tempLink.points, sourcePosition: {
10552
9439
  x: tempLink.sourceElement.position.x + tempLink.sourcePort.position.x,
10553
9440
  y: tempLink.sourceElement.position.y + tempLink.sourcePort.position.y
10554
9441
  }, 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$1.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, fontSize: text.fontSize, border: text.border, container: paperContainerRef.current, content: text.content, align: text.align, onSelected: function () {
9442
+ 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
9443
  setSelectedText(text);
10557
9444
  } })); })),
10558
- React$1.createElement(BBoxDebugger, { elementSVG: selectedElementSVG }),
10559
- React$1.createElement(LinkDebugger, { links: links, svgContainer: paperContainerRef.current })));
9445
+ React.createElement(BBoxDebugger, { elementSVG: selectedElementSVG }),
9446
+ React.createElement(LinkDebugger, { links: links, svgContainer: paperContainerRef.current })));
10560
9447
  };
10561
- var Paper$1 = React$1.memo(Paper);
9448
+ var Paper$1 = React.memo(Paper);
10562
9449
 
10563
9450
  var Editor = function (_a) {
10564
9451
  var editorContext = _a.editorContext, width = _a.width, height = _a.height;
10565
- var _b = React$1.useState([]), elements = _b[0], setElements = _b[1];
10566
- var _c = React$1.useState([]), links = _c[0], setLinks = _c[1];
10567
- var _d = React$1.useState([]), texts = _d[0], setTexts = _d[1];
9452
+ var _b = React.useState([]), elements = _b[0], setElements = _b[1];
9453
+ var _c = React.useState([]), links = _c[0], setLinks = _c[1];
9454
+ var _d = React.useState([]), texts = _d[0], setTexts = _d[1];
10568
9455
  if (!width) {
10569
9456
  width = 3000;
10570
9457
  }
10571
9458
  if (!height) {
10572
9459
  height = 3000;
10573
9460
  }
10574
- var setEditorStates = React$1.useCallback(function (ctx) {
9461
+ var setEditorStates = React.useCallback(function (ctx) {
10575
9462
  setElements(__spreadArray([], ctx.elements, true));
10576
9463
  setLinks(__spreadArray([], ctx.links, true));
10577
9464
  setTexts(__spreadArray([], ctx.texts, true));
10578
9465
  }, []);
10579
- React$1.useEffect(function () {
9466
+ React.useEffect(function () {
10580
9467
  if (editorContext) {
10581
9468
  setEditorStates(editorContext);
10582
9469
  }
10583
9470
  }, [editorContext, setEditorStates]);
10584
- React$1.useEffect(function () {
9471
+ React.useEffect(function () {
10585
9472
  var offs = [];
10586
9473
  if (editorContext) {
10587
9474
  offs.push(editorContext.onEditorContextUpdated(function () {
@@ -10593,55 +9480,70 @@ var Editor = function (_a) {
10593
9480
  offs.forEach(function (off) { return off(); });
10594
9481
  };
10595
9482
  }, [editorContext, setEditorStates]);
10596
- var handlePaperClicked = React$1.useCallback(function (position) {
9483
+ var handlePaperClicked = React.useCallback(function (position) {
10597
9484
  editorContext.onPaperClickedHandler(position);
10598
9485
  }, [editorContext]);
10599
- var handlePortMoved = React$1.useCallback(function (position, port, element) {
9486
+ var handlePortMouseDown = React.useCallback(function (port, element) {
9487
+ editorContext.onPortMouseDownHandler(port, element);
9488
+ }, [editorContext]);
9489
+ var handlePortMouseUp = React.useCallback(function (port, element) {
9490
+ editorContext.onPortMouseUpHandler(port, element);
9491
+ }, [editorContext]);
9492
+ var handlePortMoved = React.useCallback(function (position, port, element) {
10600
9493
  editorContext.onPortMovedHandler(position, port, element);
10601
9494
  }, [editorContext]);
10602
- var handlePortSelected = React$1.useCallback(function (port, element) {
9495
+ var handlePortSelected = React.useCallback(function (port, element) {
10603
9496
  editorContext.onPortSelectedHandler(port, element);
10604
9497
  }, [editorContext]);
10605
- var handleElementContextMenu = React$1.useCallback(function (element, event) {
9498
+ var handleElementContextMenu = React.useCallback(function (element, event) {
10606
9499
  editorContext.onElementContextMenuHandler(element, event);
10607
9500
  }, [editorContext]);
10608
- var handleElementMoved = React$1.useCallback(function (position, element) {
9501
+ var handleElementMoved = React.useCallback(function (position, element) {
10609
9502
  editorContext.onElementMovedHandler(position, element);
10610
9503
  }, [editorContext]);
10611
- var handleElementResized = React$1.useCallback(function (size, element) {
9504
+ var handleElementResized = React.useCallback(function (size, element) {
10612
9505
  editorContext.onElementResizedHandler(size, element);
10613
9506
  }, [editorContext]);
10614
- var handleElementSelected = React$1.useCallback(function (element) {
9507
+ var handleElementSelected = React.useCallback(function (element) {
10615
9508
  editorContext.onElementSelectedHandler(element);
10616
9509
  }, [editorContext]);
10617
- var handleLinkSelected = React$1.useCallback(function (link) {
9510
+ var handleElementMouseLeave = React.useCallback(function (ev, element) {
9511
+ editorContext.onElementMouseLeaveHandler(ev, element);
9512
+ }, [editorContext]);
9513
+ var handleElementMouseMove = React.useCallback(function (ev, element) {
9514
+ editorContext.onElementMouseMoveHandler(ev, element);
9515
+ }, [editorContext]);
9516
+ var handleElementMouseUp = React.useCallback(function (ev, element) {
9517
+ editorContext.onElementMouseUpHandler(ev, element);
9518
+ }, [editorContext]);
9519
+ var handleLinkSelected = React.useCallback(function (link) {
10618
9520
  editorContext.onLinkSelectedHandler(link);
10619
9521
  }, [editorContext]);
10620
- var handleTextSelected = React$1.useCallback(function (text) {
9522
+ var handleTextSelected = React.useCallback(function (text) {
10621
9523
  editorContext.onTextSelectedHandler(text);
10622
9524
  }, [editorContext]);
10623
- var handleOnCreatingLink = React$1.useCallback(function (sourcePort, sourceElement, targetPort, targetElement) {
9525
+ var handleOnCreatingLink = React.useCallback(function (sourcePort, sourceElement, targetPort, targetElement) {
10624
9526
  if (editorContext.onCreatingLinkHandler) {
10625
9527
  return editorContext.onCreatingLinkHandler(sourcePort, sourceElement, targetPort, targetElement);
10626
9528
  }
10627
9529
  return null;
10628
9530
  }, [editorContext]);
10629
- var handleOnCreatingPortByLinking = React$1.useCallback(function (sourceElement, sourcePort, targetElement, position) {
9531
+ var handleOnCreatingPortByLinking = React.useCallback(function (sourceElement, sourcePort, targetElement, position) {
10630
9532
  if (editorContext.onCreatingPortByLinkingHandler) {
10631
9533
  return editorContext.onCreatingPortByLinkingHandler(sourceElement, sourcePort, targetElement, position);
10632
9534
  }
10633
9535
  return null;
10634
9536
  }, [editorContext]);
10635
- var handlePaperMouseMoved = React$1.useCallback(function (position) {
9537
+ var handlePaperMouseMoved = React.useCallback(function (position) {
10636
9538
  editorContext.onPaperMouseMovedHandler(position);
10637
9539
  }, [editorContext]);
10638
- var handlePaperMouseDown = React$1.useCallback(function (position) {
9540
+ var handlePaperMouseDown = React.useCallback(function (position) {
10639
9541
  editorContext.onPaperMouseDownHandler(position);
10640
9542
  }, [editorContext]);
10641
- var handlePaperMouseUp = React$1.useCallback(function (position) {
9543
+ var handlePaperMouseUp = React.useCallback(function (position) {
10642
9544
  editorContext.onPaperMouseUpHandler(position);
10643
9545
  }, [editorContext]);
10644
- return (React$1.createElement(Paper$1, { key: "paper", size: { width: width, height: height }, elements: elements, links: links, texts: texts, onPaperClicked: handlePaperClicked, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onTextSelected: handleTextSelected, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseUp, onPaperMouseDown: handlePaperMouseDown, onManuallyTriggerRenderElement: editorContext.onManuallyTriggerRenderElement.bind(editorContext), onManuallyTriggerRenderPort: editorContext.onManuallyTriggerRenderPort.bind(editorContext) }));
9546
+ 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
9547
  };
10646
9548
 
10647
9549
  exports.CircleRC = Circle;