orcasvn-react-diagrams 0.1.35 → 0.1.38
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 +750 -461
- package/dist/cjs/types/components/elements/element.d.ts +1 -1
- package/dist/cjs/types/logs/Logger.d.ts +14 -0
- package/dist/cjs/types/logs/configureLogger.d.ts +4 -0
- package/dist/cjs/types/main.d.ts +2 -0
- package/dist/cjs/types/mocks/editorContextElementMoveAsPort.d.ts +2 -0
- package/dist/cjs/types/mocks/editorContextWithElementAnchorCenter.d.ts +2 -0
- package/dist/cjs/types/models/IElement.d.ts +3 -0
- package/dist/cjs/types/models/IElementProps.d.ts +1 -0
- package/dist/cjs/types/models/IElementSelectorProps.d.ts +0 -1
- package/dist/cjs/types/models/IPortProps.d.ts +1 -0
- package/dist/cjs/types/models/ITextProps.d.ts +4 -2
- package/dist/cjs/types/models/implementations/Element.d.ts +3 -0
- package/dist/cjs/types/utils/index.d.ts +8 -0
- package/dist/cjs/types/utils/positionUtil.d.ts +5 -0
- package/dist/esm/index.js +719 -463
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/elements/element.d.ts +1 -1
- package/dist/esm/types/logs/Logger.d.ts +14 -0
- package/dist/esm/types/logs/configureLogger.d.ts +4 -0
- package/dist/esm/types/main.d.ts +2 -0
- package/dist/esm/types/mocks/editorContextElementMoveAsPort.d.ts +2 -0
- package/dist/esm/types/mocks/editorContextWithElementAnchorCenter.d.ts +2 -0
- package/dist/esm/types/models/IElement.d.ts +3 -0
- package/dist/esm/types/models/IElementProps.d.ts +1 -0
- package/dist/esm/types/models/IElementSelectorProps.d.ts +0 -1
- package/dist/esm/types/models/IPortProps.d.ts +1 -0
- package/dist/esm/types/models/ITextProps.d.ts +4 -2
- package/dist/esm/types/models/implementations/Element.d.ts +3 -0
- package/dist/esm/types/utils/index.d.ts +8 -0
- package/dist/esm/types/utils/positionUtil.d.ts +5 -0
- package/dist/index.d.ts +108 -20
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -486,6 +486,7 @@ function generateUniqueId() {
|
|
|
486
486
|
var Element$2 = /** @class */ (function () {
|
|
487
487
|
function Element(x, y, width, height, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection, parentElement, textsPlaceHolderClassName, textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition) {
|
|
488
488
|
if (portMovealeAreas === void 0) { portMovealeAreas = []; }
|
|
489
|
+
this.positionAnchor = exports.PositioningAnchor.TopLeft;
|
|
489
490
|
this._childrenElements = [];
|
|
490
491
|
this.resizability = {
|
|
491
492
|
enabled: true,
|
|
@@ -1192,80 +1193,87 @@ var LINK_TARGET_LABEL_POSITION_FROM_TARGET_PORT = { x: 15, y: 15 };
|
|
|
1192
1193
|
var LINK_LABEL_POSITION_FROM_LINK_MID_POINT = { x: 0, y: 40 };
|
|
1193
1194
|
var PORT_LABEL_POSITION = { x: 15, y: 0 };
|
|
1194
1195
|
var TEXT_FONT_SIZE = 12;
|
|
1195
|
-
var TEXT_MOVING_OFFSET_THRESHOLD = 10;
|
|
1196
1196
|
//PORT
|
|
1197
1197
|
var PORT_PLACEHOLDER_DEFAULT_SIZE = 8;
|
|
1198
1198
|
var PORT_PLACEHOLDER_DEFAULT_STROKE = 'green';
|
|
1199
1199
|
var PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH = 20;
|
|
1200
|
-
var PORT_MOVING_OFFSET_THRESHOLD = 15;
|
|
1201
1200
|
var PORT_DEFAULT_SIZE = 20;
|
|
1202
1201
|
|
|
1203
1202
|
var SelectionFrame = function (props) {
|
|
1204
|
-
var _a;
|
|
1205
|
-
var
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
var
|
|
1209
|
-
var
|
|
1210
|
-
var
|
|
1203
|
+
var _a, _b;
|
|
1204
|
+
var propTargetSVGElement = props.targetSVGElement, propWidth = props.width, propHeight = props.height, propFramePadding = props.framePadding,
|
|
1205
|
+
// movingOffsetThreshold: propMovingOffsetThreshold,
|
|
1206
|
+
propMovingRate = props.movingRate, propOnMove = props.onMove, propContainer = props.container, propResizability = props.resizability, propOnResize = props.onResize, PropDragDropHandlerElement = props.dragDropHandlerElement, propStrokeWidth = props.strokeWidth, propAnchor = props.anchor;
|
|
1207
|
+
var bbox = propTargetSVGElement === null || propTargetSVGElement === void 0 ? void 0 : propTargetSVGElement.getBBox();
|
|
1208
|
+
var _c = React.useState(propWidth || (bbox === null || bbox === void 0 ? void 0 : bbox.width) || MIN_ELEMENT_SIZE), width = _c[0], setWidth = _c[1];
|
|
1209
|
+
var _d = React.useState(propHeight || (bbox === null || bbox === void 0 ? void 0 : bbox.height) || MIN_ELEMENT_SIZE), height = _d[0], setHeight = _d[1];
|
|
1210
|
+
var _e = React.useState((_a = props.x) !== null && _a !== void 0 ? _a : 0), x = _e[0], setX = _e[1];
|
|
1211
|
+
var _f = React.useState((_b = props.y) !== null && _b !== void 0 ? _b : 0), y = _f[0], setY = _f[1];
|
|
1212
|
+
var framePadding = propFramePadding || 0;
|
|
1211
1213
|
var r = 5;
|
|
1212
|
-
var
|
|
1213
|
-
var
|
|
1214
|
-
var
|
|
1215
|
-
var
|
|
1216
|
-
var
|
|
1214
|
+
var _g = React.useState(false), draggingRect = _g[0], setDraggingRect = _g[1];
|
|
1215
|
+
var _h = React.useState(false), draggingCircle = _h[0], setDraggingCircle = _h[1];
|
|
1216
|
+
var _j = React.useState(0), startX = _j[0], setStartX = _j[1];
|
|
1217
|
+
var _k = React.useState(0), startY = _k[0], setStartY = _k[1];
|
|
1218
|
+
var _l = React.useState(0), xFromMouse = _l[0], setXFromMouse = _l[1];
|
|
1219
|
+
var _m = React.useState(0), yFromMouse = _m[0], setYFromMouse = _m[1];
|
|
1220
|
+
var _o = React.useState(0), lastMoveTime = _o[0], setLastMoveTime = _o[1];
|
|
1221
|
+
var getMousePosition = function (event) {
|
|
1222
|
+
var elementBounding = propContainer.getBoundingClientRect();
|
|
1223
|
+
//Coordinates of mouse on paper.
|
|
1224
|
+
var mousePosition = {
|
|
1225
|
+
x: event.clientX - elementBounding.left,
|
|
1226
|
+
y: event.clientY - elementBounding.top
|
|
1227
|
+
};
|
|
1228
|
+
return mousePosition;
|
|
1229
|
+
};
|
|
1217
1230
|
var addRectHandleMouseDown = function (event) {
|
|
1218
1231
|
event.stopPropagation();
|
|
1219
1232
|
if (!draggingCircle) {
|
|
1220
|
-
//mouse down on rect
|
|
1221
1233
|
setDraggingRect(true);
|
|
1222
1234
|
setStartX(event.clientX);
|
|
1223
1235
|
setStartY(event.clientY);
|
|
1236
|
+
var mousePosition = getMousePosition(event);
|
|
1237
|
+
var xFromMouse_1 = x - mousePosition.x;
|
|
1238
|
+
var yFromMouse_1 = y - mousePosition.y;
|
|
1239
|
+
setXFromMouse(xFromMouse_1);
|
|
1240
|
+
setYFromMouse(yFromMouse_1);
|
|
1224
1241
|
}
|
|
1225
1242
|
};
|
|
1226
1243
|
var rectHandleMouseMove = React.useCallback(function (event) {
|
|
1227
1244
|
var mouseEvent = event;
|
|
1228
1245
|
if (draggingRect) {
|
|
1229
|
-
|
|
1230
|
-
var
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
return;
|
|
1239
|
-
}
|
|
1240
|
-
// console.info('Selection frame moved by: ', offsetX, offsetY);
|
|
1241
|
-
if (props.onMove) {
|
|
1242
|
-
props.onMove(offsetX, offsetY);
|
|
1246
|
+
//Coordinates of mouse on paper.
|
|
1247
|
+
var mousePosition = getMousePosition(mouseEvent);
|
|
1248
|
+
var newX = mousePosition.x + xFromMouse;
|
|
1249
|
+
var newY = mousePosition.y + yFromMouse;
|
|
1250
|
+
if (propOnMove) {
|
|
1251
|
+
console.log('newX', newX, 'newY', newY);
|
|
1252
|
+
setX(newX);
|
|
1253
|
+
setY(newY);
|
|
1254
|
+
propOnMove(newX, newY);
|
|
1243
1255
|
setLastMoveTime(Date.now());
|
|
1244
1256
|
setStartX(mouseEvent.clientX);
|
|
1245
1257
|
setStartY(mouseEvent.clientY);
|
|
1246
1258
|
}
|
|
1247
1259
|
}
|
|
1248
|
-
}, [draggingRect,
|
|
1260
|
+
}, [draggingRect, propOnMove, propMovingRate, startX, startY, lastMoveTime, xFromMouse, yFromMouse]);
|
|
1249
1261
|
React.useEffect(function () {
|
|
1250
1262
|
var addRectHandleMouseUp = function () {
|
|
1251
|
-
//mouse up
|
|
1252
1263
|
setDraggingRect(false);
|
|
1264
|
+
setXFromMouse(0);
|
|
1265
|
+
setYFromMouse(0);
|
|
1253
1266
|
};
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
var container = props.container;
|
|
1257
|
-
//add event listeners
|
|
1258
|
-
container === null || container === void 0 ? void 0 : container.addEventListener('mousemove', rectHandleMouseMove);
|
|
1259
|
-
container === null || container === void 0 ? void 0 : container.addEventListener('mouseup', addRectHandleMouseUp);
|
|
1267
|
+
propContainer === null || propContainer === void 0 ? void 0 : propContainer.addEventListener('mousemove', rectHandleMouseMove);
|
|
1268
|
+
propContainer === null || propContainer === void 0 ? void 0 : propContainer.addEventListener('mouseup', addRectHandleMouseUp);
|
|
1260
1269
|
return function () {
|
|
1261
|
-
|
|
1262
|
-
|
|
1270
|
+
propContainer === null || propContainer === void 0 ? void 0 : propContainer.removeEventListener('mousemove', rectHandleMouseMove);
|
|
1271
|
+
propContainer === null || propContainer === void 0 ? void 0 : propContainer.removeEventListener('mouseup', addRectHandleMouseUp);
|
|
1263
1272
|
};
|
|
1264
|
-
}, [
|
|
1273
|
+
}, [propContainer, rectHandleMouseMove]);
|
|
1265
1274
|
var circleHandleMouseDown = function (event) {
|
|
1266
1275
|
event.stopPropagation();
|
|
1267
1276
|
if (!draggingRect) {
|
|
1268
|
-
// mouse down on resizing circle
|
|
1269
1277
|
setStartX(event.clientX);
|
|
1270
1278
|
setStartY(event.clientY);
|
|
1271
1279
|
setDraggingCircle(true);
|
|
@@ -1277,7 +1285,7 @@ var SelectionFrame = function (props) {
|
|
|
1277
1285
|
if (draggingCircle) {
|
|
1278
1286
|
var offsetX = mouseEvent.clientX - startX;
|
|
1279
1287
|
var offsetY = mouseEvent.clientY - startY;
|
|
1280
|
-
if (Date.now() - lastMoveTime < (
|
|
1288
|
+
if (Date.now() - lastMoveTime < (propMovingRate || 0)) {
|
|
1281
1289
|
return;
|
|
1282
1290
|
}
|
|
1283
1291
|
setStartX(mouseEvent.clientX);
|
|
@@ -1285,7 +1293,7 @@ var SelectionFrame = function (props) {
|
|
|
1285
1293
|
setLastMoveTime(Date.now());
|
|
1286
1294
|
var newWidth = width;
|
|
1287
1295
|
var newHeight = height;
|
|
1288
|
-
if (
|
|
1296
|
+
if (propResizability.keepRatio) {
|
|
1289
1297
|
var resizingRatio = Math.abs(offsetX) > Math.abs(offsetY) ? (Math.abs(offsetX) / width) : (Math.abs(offsetY) / height);
|
|
1290
1298
|
var increasing = Math.abs(offsetX) > Math.abs(offsetY) ? offsetX > 0 : offsetY > 0;
|
|
1291
1299
|
offsetX = increasing ? resizingRatio * width : -resizingRatio * width;
|
|
@@ -1301,36 +1309,33 @@ var SelectionFrame = function (props) {
|
|
|
1301
1309
|
}
|
|
1302
1310
|
setWidth(newWidth);
|
|
1303
1311
|
setHeight(newHeight);
|
|
1304
|
-
if (
|
|
1305
|
-
|
|
1312
|
+
if (propOnResize) {
|
|
1313
|
+
propOnResize(newWidth, newHeight);
|
|
1306
1314
|
}
|
|
1307
|
-
//}
|
|
1308
1315
|
}
|
|
1309
1316
|
};
|
|
1310
1317
|
var circleHandleMouseUp = function () {
|
|
1311
1318
|
setDraggingCircle(false);
|
|
1312
1319
|
};
|
|
1313
|
-
|
|
1314
|
-
//const container = typeof props.container === 'string' ? document.querySelector(props.container) : props.container;
|
|
1315
|
-
var container = props.container;
|
|
1320
|
+
var container = propContainer;
|
|
1316
1321
|
container.addEventListener('mousemove', circleHandleMouseMove);
|
|
1317
1322
|
container.addEventListener('mouseup', circleHandleMouseUp);
|
|
1318
1323
|
return function () {
|
|
1319
1324
|
container.removeEventListener('mousemove', circleHandleMouseMove);
|
|
1320
1325
|
container.removeEventListener('mouseup', circleHandleMouseUp);
|
|
1321
1326
|
};
|
|
1322
|
-
}, [draggingCircle,
|
|
1327
|
+
}, [draggingCircle, width, height, lastMoveTime, propContainer, propMovingRate, propOnResize, propResizability, startX, startY]);
|
|
1323
1328
|
var rectangleSize = Math.max(width, height);
|
|
1324
1329
|
var leftX = framePadding;
|
|
1325
1330
|
var topY = framePadding;
|
|
1326
|
-
if (
|
|
1331
|
+
if (propAnchor === exports.PositioningAnchor.Center) {
|
|
1327
1332
|
leftX -= rectangleSize / 2;
|
|
1328
1333
|
topY -= rectangleSize / 2;
|
|
1329
1334
|
}
|
|
1330
1335
|
return (React.createElement(React.Fragment, null,
|
|
1331
|
-
|
|
1332
|
-
React.createElement("rect", { vectorEffect: "non-scaling-stroke", x: leftX, y: topY, width: width, height: height, fill: 'none', stroke: 'blue', strokeWidth:
|
|
1333
|
-
|
|
1336
|
+
PropDragDropHandlerElement && React.createElement(PropDragDropHandlerElement, { dragging: draggingRect, onMouseDown: addRectHandleMouseDown }),
|
|
1337
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", x: leftX, y: topY, width: width, height: height, fill: 'none', stroke: 'blue', strokeWidth: propStrokeWidth || 5, cursor: draggingRect ? 'grabbing' : 'grab', onMouseDown: addRectHandleMouseDown }),
|
|
1338
|
+
propResizability.enabled ?
|
|
1334
1339
|
(React.createElement("circle", { cursor: 'se-resize', cx: leftX + width, cy: topY + height, r: r, fill: 'blue', stroke: 'blue', onMouseDown: circleHandleMouseDown })) : null));
|
|
1335
1340
|
};
|
|
1336
1341
|
|
|
@@ -1600,9 +1605,17 @@ var paperEventEmitterContext = React.createContext({
|
|
|
1600
1605
|
});
|
|
1601
1606
|
|
|
1602
1607
|
var Text = React.forwardRef(function (_a, ref) {
|
|
1603
|
-
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;
|
|
1608
|
+
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, parentAbsolutePosition = _a.parentAbsolutePosition, onSelected = _a.onSelected, onMoved = _a.onMoved, onResized = _a.onResized, onContentChanged = _a.onContentChanged;
|
|
1609
|
+
console.log(content, x, y, parentAbsolutePosition);
|
|
1604
1610
|
var _c = React.useState(false), isSelected = _c[0], setIsSelected = _c[1];
|
|
1605
1611
|
var _d = React.useState(false), isEditing = _d[0], setIsEditing = _d[1];
|
|
1612
|
+
var absolutePosition = React.useMemo(function () {
|
|
1613
|
+
var _a, _b;
|
|
1614
|
+
return {
|
|
1615
|
+
x: ((_a = parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.x) !== null && _a !== void 0 ? _a : 0) + x,
|
|
1616
|
+
y: ((_b = parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.y) !== null && _b !== void 0 ? _b : 0) + y,
|
|
1617
|
+
};
|
|
1618
|
+
}, [x, y, parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.x, parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.y]);
|
|
1606
1619
|
var svgRef = React.useRef();
|
|
1607
1620
|
var _e = React.useContext(paperEventEmitterContext), onPaperClicked = _e.onPaperClicked, emitTextSelected = _e.emitTextSelected, onPortSelected = _e.onPortSelected, onElementSelected = _e.onElementSelected, onTextSelected = _e.onTextSelected;
|
|
1608
1621
|
React.useEffect(function () {
|
|
@@ -1638,7 +1651,7 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1638
1651
|
//Handle click on svg element
|
|
1639
1652
|
var handleClick = function (ev) {
|
|
1640
1653
|
ev.stopPropagation();
|
|
1641
|
-
var position =
|
|
1654
|
+
var position = {
|
|
1642
1655
|
x: x,
|
|
1643
1656
|
y: y,
|
|
1644
1657
|
};
|
|
@@ -1662,6 +1675,8 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1662
1675
|
onContentChanged === null || onContentChanged === void 0 ? void 0 : onContentChanged(ev, ev.target.value);
|
|
1663
1676
|
};
|
|
1664
1677
|
useSelectionFrame({
|
|
1678
|
+
x: absolutePosition === null || absolutePosition === void 0 ? void 0 : absolutePosition.x,
|
|
1679
|
+
y: absolutePosition === null || absolutePosition === void 0 ? void 0 : absolutePosition.y,
|
|
1665
1680
|
container: container,
|
|
1666
1681
|
targetSVGElement: (isSelected && svgRef.current) ? svgRef.current : undefined,
|
|
1667
1682
|
resizability: {
|
|
@@ -1671,7 +1686,6 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1671
1686
|
onMove: onMoved,
|
|
1672
1687
|
onResize: onResized,
|
|
1673
1688
|
strokeWidth: 3,
|
|
1674
|
-
movingOffsetThreshold: TEXT_MOVING_OFFSET_THRESHOLD,
|
|
1675
1689
|
});
|
|
1676
1690
|
var textAlign = React.useMemo(function () {
|
|
1677
1691
|
switch (align) {
|
|
@@ -1731,217 +1745,6 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1731
1745
|
});
|
|
1732
1746
|
var Text$1 = React.memo(Text);
|
|
1733
1747
|
|
|
1734
|
-
var Port1 = React.forwardRef(function (props, ref) {
|
|
1735
|
-
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,
|
|
1736
|
-
// onManuallyTriggerRenderHandler,
|
|
1737
|
-
renderShape = props.renderShape;
|
|
1738
|
-
var _a = React.useState(false); _a[0]; _a[1];
|
|
1739
|
-
var textRef = React.useRef(null);
|
|
1740
|
-
// useEffect(() => {
|
|
1741
|
-
// const off = onManuallyTriggerRenderHandler?.(() => {
|
|
1742
|
-
// setUpdated(prev => !prev);
|
|
1743
|
-
// });
|
|
1744
|
-
// return () => {
|
|
1745
|
-
// off?.();
|
|
1746
|
-
// }
|
|
1747
|
-
// }, [])
|
|
1748
|
-
var rotationAngle = React.useMemo(function () {
|
|
1749
|
-
if (!calculateRotationAngle)
|
|
1750
|
-
return 0;
|
|
1751
|
-
return calculateRotationAngle(x, y);
|
|
1752
|
-
}, [calculateRotationAngle, x, y]);
|
|
1753
|
-
React.useEffect(function () {
|
|
1754
|
-
console.info('Testing - rendering Port ' + id);
|
|
1755
|
-
});
|
|
1756
|
-
var renderLabel = function (label) {
|
|
1757
|
-
var content = label.content, size = label.size;
|
|
1758
|
-
var position = label.position || PORT_LABEL_POSITION;
|
|
1759
|
-
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); } });
|
|
1760
|
-
};
|
|
1761
|
-
var renderedShape = React.useMemo(function () {
|
|
1762
|
-
if (renderShape) {
|
|
1763
|
-
var RenderShape = renderShape;
|
|
1764
|
-
return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
|
|
1765
|
-
}
|
|
1766
|
-
else {
|
|
1767
|
-
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" });
|
|
1768
|
-
}
|
|
1769
|
-
}, [props]);
|
|
1770
|
-
return (React.createElement(React.Fragment, null,
|
|
1771
|
-
renderedShape,
|
|
1772
|
-
label && renderLabel(label)));
|
|
1773
|
-
});
|
|
1774
|
-
var Port = React.memo(Port1);
|
|
1775
|
-
|
|
1776
|
-
// Render the svg <path> element
|
|
1777
|
-
function getCurvePathData(points, smoothing, closed) {
|
|
1778
|
-
if (smoothing === void 0) { smoothing = 0.2; }
|
|
1779
|
-
// Properties of a line
|
|
1780
|
-
var line = function (pointA, pointB) {
|
|
1781
|
-
var lengthX = pointB.x - pointA.x;
|
|
1782
|
-
var lengthY = pointB.y - pointA.y;
|
|
1783
|
-
return {
|
|
1784
|
-
length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)),
|
|
1785
|
-
angle: Math.atan2(lengthY, lengthX)
|
|
1786
|
-
};
|
|
1787
|
-
};
|
|
1788
|
-
// Position of a control point
|
|
1789
|
-
var controlPoint = function (current, previous, next, reverse) {
|
|
1790
|
-
var p = previous || current;
|
|
1791
|
-
var n = next || current;
|
|
1792
|
-
var o = line(p, n);
|
|
1793
|
-
var angle = o.angle + (reverse ? Math.PI : 0);
|
|
1794
|
-
var length = o.length * smoothing;
|
|
1795
|
-
var x = current.x + Math.cos(angle) * length;
|
|
1796
|
-
var y = current.y + Math.sin(angle) * length;
|
|
1797
|
-
return { x: x, y: y };
|
|
1798
|
-
};
|
|
1799
|
-
var pathData = [];
|
|
1800
|
-
pathData.push({ type: "M", values: [points[0].x, points[0].y] });
|
|
1801
|
-
for (var i = 1; i < points.length; i++) {
|
|
1802
|
-
var point = points[i];
|
|
1803
|
-
var cp1 = controlPoint(points[i - 1], points[i - 2], point);
|
|
1804
|
-
var cp2 = controlPoint(point, points[i - 1], points[i + 1], true);
|
|
1805
|
-
var command = {
|
|
1806
|
-
type: "C",
|
|
1807
|
-
values: [cp1.x, cp1.y, cp2.x, cp2.y, point.x, point.y]
|
|
1808
|
-
};
|
|
1809
|
-
pathData.push(command);
|
|
1810
|
-
}
|
|
1811
|
-
return pathData;
|
|
1812
|
-
}
|
|
1813
|
-
// convert pathdata to d attribute string
|
|
1814
|
-
function pathDataToD(pathData, decimals) {
|
|
1815
|
-
if (decimals === void 0) { decimals = 3; }
|
|
1816
|
-
var d = pathData
|
|
1817
|
-
.map(function (com) {
|
|
1818
|
-
return "".concat(com.type).concat(com.values.map(function (value) { return +value.toFixed(decimals); }).join(" "));
|
|
1819
|
-
})
|
|
1820
|
-
.join(" ");
|
|
1821
|
-
return d;
|
|
1822
|
-
}
|
|
1823
|
-
function createSmoothPathString(points, smoothing, close) {
|
|
1824
|
-
var pathData = getCurvePathData(points, smoothing);
|
|
1825
|
-
var pathString = pathDataToD(pathData);
|
|
1826
|
-
return pathString;
|
|
1827
|
-
}
|
|
1828
|
-
// a helper function to measure the distance between 2 points
|
|
1829
|
-
function dist(p1, p2) {
|
|
1830
|
-
var dx = p2.x - p1.x;
|
|
1831
|
-
var dy = p2.y - p1.y;
|
|
1832
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
1833
|
-
}
|
|
1834
|
-
//find distance from starting point of path to a point
|
|
1835
|
-
function getLengthForPoint(p, thePath, precision) {
|
|
1836
|
-
if (precision === void 0) { precision = 50; }
|
|
1837
|
-
var pathLength = thePath.getTotalLength();
|
|
1838
|
-
var theRecord = pathLength; //length of path
|
|
1839
|
-
var division = pathLength / precision;
|
|
1840
|
-
var theSegment;
|
|
1841
|
-
for (var i = 0; i < precision; i++) {
|
|
1842
|
-
// get a point on the path for thia distance
|
|
1843
|
-
var _p = thePath.getPointAtLength(i * division);
|
|
1844
|
-
// get the distance between the new point _p and the point p
|
|
1845
|
-
var theDistance = dist(_p, p);
|
|
1846
|
-
if (theDistance < theRecord) {
|
|
1847
|
-
// if the distance is smaller than the record set the new record
|
|
1848
|
-
theRecord = theDistance;
|
|
1849
|
-
theSegment = i;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
return (theSegment * division);
|
|
1853
|
-
}
|
|
1854
|
-
//Add points to the list of points in the correct position
|
|
1855
|
-
function addPointToList(point, listPoints, path) {
|
|
1856
|
-
var getAddIndex = function (startIndex, endIndex) {
|
|
1857
|
-
//Add in the middle if there are only 2 points
|
|
1858
|
-
if ((endIndex - startIndex) === 1) {
|
|
1859
|
-
return startIndex + 1;
|
|
1860
|
-
}
|
|
1861
|
-
var middleIndex = Math.ceil((startIndex + endIndex) / 2);
|
|
1862
|
-
var lengthOfMiddlePoint = getLengthForPoint(listPoints[middleIndex], path); //distance from start point to mid point
|
|
1863
|
-
var lengthOfAddedPoint = getLengthForPoint(point, path); //distance from adding point to mid point
|
|
1864
|
-
//compare if lengthOfMiddlePoint is less than lengthOfAddedPoint,
|
|
1865
|
-
//then new point can be added in the range of mid point to end point,
|
|
1866
|
-
//otherwise it can be added in the range of start point to middle point.
|
|
1867
|
-
if (lengthOfAddedPoint < lengthOfMiddlePoint) {
|
|
1868
|
-
return getAddIndex(startIndex, middleIndex);
|
|
1869
|
-
}
|
|
1870
|
-
else {
|
|
1871
|
-
return getAddIndex(middleIndex, endIndex);
|
|
1872
|
-
}
|
|
1873
|
-
};
|
|
1874
|
-
var addedIndex = getAddIndex(0, listPoints.length - 1);
|
|
1875
|
-
listPoints.splice(addedIndex, 0, point);
|
|
1876
|
-
return __spreadArray([], listPoints, true);
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1879
|
-
// const topLeftOffsetOfSquareHoldingRect = (x: number, y: number, rectWidth: number, rectHeight: number, rotation?: number): IPosition => {
|
|
1880
|
-
// rotation = rotation || 0;
|
|
1881
|
-
// const rotationInRadians = rotation * Math.PI / 180;
|
|
1882
|
-
// //calculate the bouding edge of the square that holds the rectangle with the given width and height and rotation, knowing that the square is always parallel to the x and y axis
|
|
1883
|
-
// //calculate a1 equal sin of rotation * height
|
|
1884
|
-
// const a1 = Math.abs(Math.sin(rotationInRadians) * rectHeight);
|
|
1885
|
-
// //calculate a2 equal cos of rotation * width
|
|
1886
|
-
// const a2 = Math.abs(Math.cos(rotationInRadians) * rectWidth);
|
|
1887
|
-
// const a = a1 + a2;
|
|
1888
|
-
// console.info(`a1: ${a1}, a2: ${a2}, a: ${a}`);
|
|
1889
|
-
// //calculate b1 equal cos of rotation * height
|
|
1890
|
-
// const b1 = Math.abs(Math.cos(rotationInRadians) * rectHeight);
|
|
1891
|
-
// //calculate b2 equal sin of rotation * width
|
|
1892
|
-
// const b2 = Math.abs(Math.sin(rotationInRadians) * rectWidth);
|
|
1893
|
-
// const b = b1 + b2;
|
|
1894
|
-
// console.info(`b1: ${b1}, b2: ${b2}, b: ${b}`);
|
|
1895
|
-
// //const squareEdge = Math.max(rectWidth, rectHeight);
|
|
1896
|
-
// return {x, y};
|
|
1897
|
-
// return { x: x - (b - rectWidth) / 2, y: y - (a - rectHeight) / 2 };
|
|
1898
|
-
// }
|
|
1899
|
-
function degreeToRadian(degree) {
|
|
1900
|
-
return degree * (Math.PI / 180);
|
|
1901
|
-
}
|
|
1902
|
-
//rotate the four vertices of the rectangle
|
|
1903
|
-
function getRotatedRectangleCoordinates(actualPoints, centerX, centerY, angle) {
|
|
1904
|
-
var coordinatesAfterRotation = [];
|
|
1905
|
-
for (var i = 0; i < 4; i++) {
|
|
1906
|
-
var point = actualPoints[i];
|
|
1907
|
-
var tempX = point.x - centerX;
|
|
1908
|
-
var tempY = point.y - centerY;
|
|
1909
|
-
var rotatedX = tempX * Math.cos(degreeToRadian(angle)) - tempY * Math.sin(degreeToRadian(angle));
|
|
1910
|
-
var rotatedY = tempX * Math.sin(degreeToRadian(angle)) + tempY * Math.cos(degreeToRadian(angle));
|
|
1911
|
-
point.x = rotatedX + centerX;
|
|
1912
|
-
point.y = rotatedY + centerY;
|
|
1913
|
-
coordinatesAfterRotation.push({ x: point.x, y: point.y });
|
|
1914
|
-
}
|
|
1915
|
-
return coordinatesAfterRotation;
|
|
1916
|
-
}
|
|
1917
|
-
//Calculate the angle between 2 points relative to the OX axis
|
|
1918
|
-
function calculateAngleWithOx(pStart, pEnd) {
|
|
1919
|
-
var deltaX = pEnd.x - pStart.x;
|
|
1920
|
-
var deltaY = pEnd.y - pStart.y;
|
|
1921
|
-
// Calculate the angle in radians
|
|
1922
|
-
var angleInRadians = Math.atan2(deltaY, deltaX);
|
|
1923
|
-
// Convert to degrees (optional)
|
|
1924
|
-
var angleInDegrees = angleInRadians * (180 / Math.PI);
|
|
1925
|
-
// Ensure the angle is positive (optional, depending on use case)
|
|
1926
|
-
if (angleInDegrees < 0) {
|
|
1927
|
-
angleInDegrees += 360;
|
|
1928
|
-
}
|
|
1929
|
-
return angleInDegrees;
|
|
1930
|
-
}
|
|
1931
|
-
|
|
1932
|
-
//Defined remove icon for element link, shown when element link is selected.
|
|
1933
|
-
function CloseIcon(_a) {
|
|
1934
|
-
var onClick = _a.onClick;
|
|
1935
|
-
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' },
|
|
1936
|
-
React.createElement("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0", transform: "translate(3.84,3.84), scale(0.68)" },
|
|
1937
|
-
React.createElement("rect", { x: "0", y: "0", width: "24.00", height: "24.00", rx: "12", fill: "#ffffff", strokeWidth: "0" })),
|
|
1938
|
-
React.createElement("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round", stroke: "#CCCCCC", "stroke-width": "0.048" }),
|
|
1939
|
-
React.createElement("g", { id: "SVGRepo_iconCarrier" },
|
|
1940
|
-
React.createElement("g", null,
|
|
1941
|
-
React.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
|
|
1942
|
-
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" })))));
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
1748
|
/**
|
|
1946
1749
|
* Created by Alex Bol on 2/18/2017.
|
|
1947
1750
|
*/
|
|
@@ -7482,38 +7285,131 @@ var checkPositionOnLine = function (position, line) {
|
|
|
7482
7285
|
return _line.contains(point);
|
|
7483
7286
|
};
|
|
7484
7287
|
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
var
|
|
7490
|
-
if (
|
|
7491
|
-
|
|
7492
|
-
};
|
|
7493
|
-
function removeDuplicatePosition(positions) {
|
|
7494
|
-
return positions.reduce(function (acc, p) { return acc.some(function (_p) { return _p.x === p.x && _p.y === p.y; }) ? acc : __spreadArray(__spreadArray([], acc, true), [p], false); }, []);
|
|
7495
|
-
}
|
|
7496
|
-
/**
|
|
7497
|
-
* Find the closest point from a list of points to the destination point
|
|
7498
|
-
*/
|
|
7499
|
-
var findNearestPosition = function (listPositions, targetPosition) {
|
|
7500
|
-
var nearestPoint = listPositions[0];
|
|
7501
|
-
if (listPositions.length === 1)
|
|
7502
|
-
return nearestPoint;
|
|
7503
|
-
for (var i = 1; i < listPositions.length; i++) {
|
|
7504
|
-
var curPoint = listPositions[i];
|
|
7505
|
-
var nearestDistance = Flatten$1.point(nearestPoint.x, nearestPoint.y).distanceTo(Flatten$1.point(targetPosition.x, targetPosition.y))[0];
|
|
7506
|
-
var curDistance = Flatten$1.point(curPoint.x, curPoint.y).distanceTo(Flatten$1.point(targetPosition.x, targetPosition.y))[0];
|
|
7507
|
-
nearestPoint = curDistance < nearestDistance ? curPoint : nearestPoint;
|
|
7288
|
+
// Calculate the position of the 4 vertices of a rectangle relative to its parent svg
|
|
7289
|
+
var getRectangleCorners = function (rectSVG) {
|
|
7290
|
+
var ownerSVG = rectSVG.ownerSVGElement;
|
|
7291
|
+
var rectStrokeWidth = Number(rectSVG.getAttribute('stroke-width')) || 0;
|
|
7292
|
+
var strokeWidthOffset = rectStrokeWidth / 2;
|
|
7293
|
+
if (!ownerSVG) {
|
|
7294
|
+
throw new Error('Rectangle does not wrapper by svg.');
|
|
7508
7295
|
}
|
|
7509
|
-
|
|
7296
|
+
var ownerX = ownerSVG.x.baseVal.value;
|
|
7297
|
+
var ownerY = ownerSVG.y.baseVal.value;
|
|
7298
|
+
var ownerWidth = ownerSVG.width.baseVal.value;
|
|
7299
|
+
var ownerHeight = ownerSVG.height.baseVal.value;
|
|
7300
|
+
var a = { x: ownerX + strokeWidthOffset, y: ownerY + strokeWidthOffset };
|
|
7301
|
+
var b = { x: ownerX + ownerWidth - strokeWidthOffset, y: ownerY + strokeWidthOffset };
|
|
7302
|
+
var c = { x: ownerX + ownerWidth - strokeWidthOffset, y: ownerY + ownerHeight - strokeWidthOffset };
|
|
7303
|
+
var d = { x: ownerX + strokeWidthOffset, y: ownerY + ownerHeight - strokeWidthOffset };
|
|
7304
|
+
return [a, b, c, d];
|
|
7510
7305
|
};
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7306
|
+
//find rotation angle of svg element on g element
|
|
7307
|
+
var getElementRotationInfo = function (element) {
|
|
7308
|
+
var gElement = element;
|
|
7309
|
+
var rotationAngle = 0;
|
|
7310
|
+
while (!(gElement instanceof SVGGElement)) {
|
|
7311
|
+
gElement = gElement.parentElement;
|
|
7312
|
+
}
|
|
7313
|
+
var transform = gElement.getAttribute('transform');
|
|
7314
|
+
if (transform) {
|
|
7315
|
+
// Match the rotation value using a regular expression
|
|
7316
|
+
var rotateMatch = transform.match(/rotate\(([-\d.]+)(?:\s+[-\d.]+\s+[-\d.]+)?\)/);
|
|
7317
|
+
if (rotateMatch) {
|
|
7318
|
+
// The first capture group is the rotation angle
|
|
7319
|
+
rotationAngle = parseFloat(rotateMatch[1]);
|
|
7320
|
+
}
|
|
7321
|
+
}
|
|
7322
|
+
return rotationAngle;
|
|
7323
|
+
};
|
|
7324
|
+
|
|
7325
|
+
// const topLeftOffsetOfSquareHoldingRect = (x: number, y: number, rectWidth: number, rectHeight: number, rotation?: number): IPosition => {
|
|
7326
|
+
// rotation = rotation || 0;
|
|
7327
|
+
// const rotationInRadians = rotation * Math.PI / 180;
|
|
7328
|
+
// //calculate the bouding edge of the square that holds the rectangle with the given width and height and rotation, knowing that the square is always parallel to the x and y axis
|
|
7329
|
+
// //calculate a1 equal sin of rotation * height
|
|
7330
|
+
// const a1 = Math.abs(Math.sin(rotationInRadians) * rectHeight);
|
|
7331
|
+
// //calculate a2 equal cos of rotation * width
|
|
7332
|
+
// const a2 = Math.abs(Math.cos(rotationInRadians) * rectWidth);
|
|
7333
|
+
// const a = a1 + a2;
|
|
7334
|
+
// console.info(`a1: ${a1}, a2: ${a2}, a: ${a}`);
|
|
7335
|
+
// //calculate b1 equal cos of rotation * height
|
|
7336
|
+
// const b1 = Math.abs(Math.cos(rotationInRadians) * rectHeight);
|
|
7337
|
+
// //calculate b2 equal sin of rotation * width
|
|
7338
|
+
// const b2 = Math.abs(Math.sin(rotationInRadians) * rectWidth);
|
|
7339
|
+
// const b = b1 + b2;
|
|
7340
|
+
// console.info(`b1: ${b1}, b2: ${b2}, b: ${b}`);
|
|
7341
|
+
// //const squareEdge = Math.max(rectWidth, rectHeight);
|
|
7342
|
+
// return {x, y};
|
|
7343
|
+
// return { x: x - (b - rectWidth) / 2, y: y - (a - rectHeight) / 2 };
|
|
7344
|
+
// }
|
|
7345
|
+
var diamondEdgeInsideSquare = function (squareEdgeSize) {
|
|
7346
|
+
return (squareEdgeSize / 2) * Math.sqrt(2);
|
|
7347
|
+
};
|
|
7348
|
+
function degreeToRadian(degree) {
|
|
7349
|
+
return degree * (Math.PI / 180);
|
|
7350
|
+
}
|
|
7351
|
+
//rotate the four vertices of the rectangle
|
|
7352
|
+
function getRotatedRectangleCoordinates(actualPoints, centerX, centerY, angle) {
|
|
7353
|
+
var coordinatesAfterRotation = [];
|
|
7354
|
+
for (var i = 0; i < 4; i++) {
|
|
7355
|
+
var point = actualPoints[i];
|
|
7356
|
+
var tempX = point.x - centerX;
|
|
7357
|
+
var tempY = point.y - centerY;
|
|
7358
|
+
var rotatedX = tempX * Math.cos(degreeToRadian(angle)) - tempY * Math.sin(degreeToRadian(angle));
|
|
7359
|
+
var rotatedY = tempX * Math.sin(degreeToRadian(angle)) + tempY * Math.cos(degreeToRadian(angle));
|
|
7360
|
+
point.x = rotatedX + centerX;
|
|
7361
|
+
point.y = rotatedY + centerY;
|
|
7362
|
+
coordinatesAfterRotation.push({ x: point.x, y: point.y });
|
|
7363
|
+
}
|
|
7364
|
+
return coordinatesAfterRotation;
|
|
7365
|
+
}
|
|
7366
|
+
//Calculate the angle between 2 points relative to the OX axis
|
|
7367
|
+
function calculateAngleWithOx(pStart, pEnd) {
|
|
7368
|
+
var deltaX = pEnd.x - pStart.x;
|
|
7369
|
+
var deltaY = pEnd.y - pStart.y;
|
|
7370
|
+
// Calculate the angle in radians
|
|
7371
|
+
var angleInRadians = Math.atan2(deltaY, deltaX);
|
|
7372
|
+
// Convert to degrees (optional)
|
|
7373
|
+
var angleInDegrees = angleInRadians * (180 / Math.PI);
|
|
7374
|
+
// Ensure the angle is positive (optional, depending on use case)
|
|
7375
|
+
if (angleInDegrees < 0) {
|
|
7376
|
+
angleInDegrees += 360;
|
|
7377
|
+
}
|
|
7378
|
+
return angleInDegrees;
|
|
7379
|
+
}
|
|
7380
|
+
|
|
7381
|
+
/**
|
|
7382
|
+
* Check if position 1 is within the radius r of position 2
|
|
7383
|
+
* @returns boolean
|
|
7384
|
+
*/
|
|
7385
|
+
var checkSamePosition = function (p1, p2, r) {
|
|
7386
|
+
if (r === void 0) { r = 3; }
|
|
7387
|
+
return (p2.x - r < p1.x && p2.x + r > p1.x) && (p2.y - r < p1.y && p2.y + r > p1.y);
|
|
7388
|
+
};
|
|
7389
|
+
function removeDuplicatePosition(positions) {
|
|
7390
|
+
return positions.reduce(function (acc, p) { return acc.some(function (_p) { return _p.x === p.x && _p.y === p.y; }) ? acc : __spreadArray(__spreadArray([], acc, true), [p], false); }, []);
|
|
7391
|
+
}
|
|
7392
|
+
/**
|
|
7393
|
+
* Find the closest point from a list of points to the destination point
|
|
7394
|
+
*/
|
|
7395
|
+
var findNearestPosition = function (listPositions, targetPosition) {
|
|
7396
|
+
var nearestPoint = listPositions[0];
|
|
7397
|
+
if (listPositions.length === 1)
|
|
7398
|
+
return nearestPoint;
|
|
7399
|
+
for (var i = 1; i < listPositions.length; i++) {
|
|
7400
|
+
var curPoint = listPositions[i];
|
|
7401
|
+
var nearestDistance = Flatten$1.point(nearestPoint.x, nearestPoint.y).distanceTo(Flatten$1.point(targetPosition.x, targetPosition.y))[0];
|
|
7402
|
+
var curDistance = Flatten$1.point(curPoint.x, curPoint.y).distanceTo(Flatten$1.point(targetPosition.x, targetPosition.y))[0];
|
|
7403
|
+
nearestPoint = curDistance < nearestDistance ? curPoint : nearestPoint;
|
|
7404
|
+
}
|
|
7405
|
+
return nearestPoint;
|
|
7406
|
+
};
|
|
7407
|
+
/**
|
|
7408
|
+
* From one point find projected Point on the line segment.
|
|
7409
|
+
* @param position
|
|
7410
|
+
* @param linePoints
|
|
7411
|
+
* @returns
|
|
7412
|
+
*/
|
|
7517
7413
|
var findNearestPointOnSegment = function (position, linePoints) {
|
|
7518
7414
|
var beginPosition = linePoints[0], endPosition = linePoints[1];
|
|
7519
7415
|
var point = Flatten$1.point(position.x, position.y);
|
|
@@ -7772,8 +7668,289 @@ var getAbsolutePosition = function (element) {
|
|
|
7772
7668
|
x: x,
|
|
7773
7669
|
y: y,
|
|
7774
7670
|
};
|
|
7671
|
+
};
|
|
7672
|
+
//get absolute position of element
|
|
7673
|
+
var getPortAbsolutePosition = function (port, element) {
|
|
7674
|
+
var elementAbsolutePosition = getAbsolutePosition(element);
|
|
7675
|
+
return {
|
|
7676
|
+
x: elementAbsolutePosition.x + port.position.x,
|
|
7677
|
+
y: elementAbsolutePosition.y + port.position.y,
|
|
7678
|
+
};
|
|
7679
|
+
};
|
|
7680
|
+
var transformAbsPositionToElementRelativePosition = function (position, element) {
|
|
7681
|
+
var parentElement = element.parentElement;
|
|
7682
|
+
if (!parentElement) {
|
|
7683
|
+
return position;
|
|
7684
|
+
}
|
|
7685
|
+
var absoluteParentElement = getAbsolutePosition(parentElement);
|
|
7686
|
+
return {
|
|
7687
|
+
x: position.x - absoluteParentElement.x,
|
|
7688
|
+
y: position.y - absoluteParentElement.y,
|
|
7689
|
+
};
|
|
7690
|
+
};
|
|
7691
|
+
var transformAbsPositionToRelativePositionInsideElement = function (absolutePosition, parentAbsolutePosition) {
|
|
7692
|
+
var _a, _b;
|
|
7693
|
+
var position = {
|
|
7694
|
+
x: absolutePosition.x - ((_a = parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.x) !== null && _a !== void 0 ? _a : 0),
|
|
7695
|
+
y: absolutePosition.y - ((_b = parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.y) !== null && _b !== void 0 ? _b : 0),
|
|
7696
|
+
};
|
|
7697
|
+
return position;
|
|
7698
|
+
};
|
|
7699
|
+
var correctPortPositionInElement = function (elementRelativePosition, elementWidth, elementHeight, portMoveableAreas, portSlideRailSVGClassName, element) {
|
|
7700
|
+
//Normalize a point so that it can lie exactly on an area
|
|
7701
|
+
var normalizePortPositionOnMoveableAreas = function (moveableAreas, position) {
|
|
7702
|
+
var lines = moveableAreas.filter(function (area) { return area.length === 2; });
|
|
7703
|
+
var polygons = moveableAreas.filter(function (area) { return area.length >= 3; });
|
|
7704
|
+
var normalizedPosition;
|
|
7705
|
+
//If moveableAreas is lines
|
|
7706
|
+
if (lines.length > 0) {
|
|
7707
|
+
var newPosition_1 = findNearestProjectedPoint({ x: position.x, y: position.y }, lines);
|
|
7708
|
+
if (newPosition_1) {
|
|
7709
|
+
normalizedPosition = newPosition_1;
|
|
7710
|
+
}
|
|
7711
|
+
}
|
|
7712
|
+
//If moveableAreas is polygons
|
|
7713
|
+
else if (polygons.length > 0) {
|
|
7714
|
+
var newPosition_2 = { x: position.x, y: position.y };
|
|
7715
|
+
var isContainsInPolygons = polygons.some(function (p) { return checkPointContainsPolygon(newPosition_2, p); });
|
|
7716
|
+
if (isContainsInPolygons) {
|
|
7717
|
+
normalizedPosition = newPosition_2;
|
|
7718
|
+
}
|
|
7719
|
+
}
|
|
7720
|
+
return normalizedPosition;
|
|
7721
|
+
};
|
|
7722
|
+
var getSlideRailSVG = function (portSlideRailSVGClassName) {
|
|
7723
|
+
if (!element)
|
|
7724
|
+
return;
|
|
7725
|
+
var slideRailSVG = element.querySelector(".".concat(portSlideRailSVGClassName));
|
|
7726
|
+
return slideRailSVG;
|
|
7727
|
+
};
|
|
7728
|
+
//Calculate the position of the 4 vertices of a rectangle relative to element
|
|
7729
|
+
var calculateSlideRailRectSVGPositions = function (slideRailSVG) {
|
|
7730
|
+
var coordinates = getRectangleCorners(slideRailSVG);
|
|
7731
|
+
var ownerSVG = slideRailSVG.ownerSVGElement;
|
|
7732
|
+
var rotationAngle = getElementRotationInfo(ownerSVG);
|
|
7733
|
+
if (rotationAngle !== 0) {
|
|
7734
|
+
var rotationCenterX = elementWidth / 2;
|
|
7735
|
+
var rotationCenterY = elementHeight / 2;
|
|
7736
|
+
coordinates = getRotatedRectangleCoordinates(coordinates, rotationCenterX, rotationCenterY, rotationAngle);
|
|
7737
|
+
}
|
|
7738
|
+
return coordinates;
|
|
7739
|
+
};
|
|
7740
|
+
var normalizePortPositionOnSlideRailSVG = function (portSlideRailSVGClassName, position) {
|
|
7741
|
+
var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
|
|
7742
|
+
if (!slideRailSVG)
|
|
7743
|
+
return;
|
|
7744
|
+
var moveTo;
|
|
7745
|
+
//check and get new position if Rect element
|
|
7746
|
+
if (slideRailSVG instanceof SVGRectElement) {
|
|
7747
|
+
var _a = calculateSlideRailRectSVGPositions(slideRailSVG), a = _a[0], b = _a[1], c = _a[2], d = _a[3]; //Get 4 vertices of rect element
|
|
7748
|
+
var moveableAreas = [
|
|
7749
|
+
[a, b],
|
|
7750
|
+
[b, c],
|
|
7751
|
+
[c, d],
|
|
7752
|
+
[d, a]
|
|
7753
|
+
];
|
|
7754
|
+
console.info("Port's moveable areas parsed from svg ".concat(portSlideRailSVGClassName), moveableAreas);
|
|
7755
|
+
var newPosition_3 = normalizePortPositionOnMoveableAreas(moveableAreas, position);
|
|
7756
|
+
if (newPosition_3) {
|
|
7757
|
+
moveTo = newPosition_3;
|
|
7758
|
+
}
|
|
7759
|
+
}
|
|
7760
|
+
else if (slideRailSVG instanceof SVGCircleElement) { //check and get new position if circle element
|
|
7761
|
+
var cx = Number(slideRailSVG.getAttribute('cx'));
|
|
7762
|
+
var cy = Number(slideRailSVG.getAttribute('cy'));
|
|
7763
|
+
var r = Number(slideRailSVG.getAttribute('r'));
|
|
7764
|
+
var circle = Flatten$1.circle(Flatten$1.point(cx, cy), r);
|
|
7765
|
+
var _b = circle.distanceTo(Flatten$1.point(position.x, position.y)), num = _b[0], segment = _b[1];
|
|
7766
|
+
if (num <= r) {
|
|
7767
|
+
moveTo = {
|
|
7768
|
+
x: segment.ps.x,
|
|
7769
|
+
y: segment.ps.y,
|
|
7770
|
+
};
|
|
7771
|
+
}
|
|
7772
|
+
}
|
|
7773
|
+
return moveTo;
|
|
7774
|
+
};
|
|
7775
|
+
var newPosition;
|
|
7776
|
+
if (portMoveableAreas && portMoveableAreas.length > 0) { //If moveable areas is defined
|
|
7777
|
+
newPosition = normalizePortPositionOnMoveableAreas(portMoveableAreas, elementRelativePosition);
|
|
7778
|
+
}
|
|
7779
|
+
else if (portSlideRailSVGClassName) { //If port slide rail svg classname is defined
|
|
7780
|
+
newPosition = normalizePortPositionOnSlideRailSVG(portSlideRailSVGClassName, elementRelativePosition);
|
|
7781
|
+
}
|
|
7782
|
+
return newPosition || elementRelativePosition;
|
|
7775
7783
|
};
|
|
7776
7784
|
|
|
7785
|
+
var Port1 = React.forwardRef(function (props, ref) {
|
|
7786
|
+
var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, container = props.container, label = props.label, parentAbsolutePosition = props.parentAbsolutePosition, 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,
|
|
7787
|
+
// onManuallyTriggerRenderHandler,
|
|
7788
|
+
renderShape = props.renderShape;
|
|
7789
|
+
var textRef = React.useRef(null);
|
|
7790
|
+
var rotationAngle = React.useMemo(function () {
|
|
7791
|
+
if (!calculateRotationAngle)
|
|
7792
|
+
return 0;
|
|
7793
|
+
return calculateRotationAngle(x, y);
|
|
7794
|
+
}, [calculateRotationAngle, x, y]);
|
|
7795
|
+
var renderLabel = function (label) {
|
|
7796
|
+
var content = label.content, size = label.size;
|
|
7797
|
+
var position = label.position || PORT_LABEL_POSITION;
|
|
7798
|
+
return React.createElement(Text$1, { id: label.id, ref: textRef, x: x + position.x, y: y + position.y, parentAbsolutePosition: parentAbsolutePosition, width: size.width, height: size.height, editable: label.editable, content: content, fontSize: label.fontSize, border: label.border, container: container, onMoved: function (xOnPaper, yOnPaper) {
|
|
7799
|
+
if (onPortLabelMoved) {
|
|
7800
|
+
var relativePosInSideEle = transformAbsPositionToRelativePositionInsideElement({ x: xOnPaper, y: yOnPaper }, parentAbsolutePosition);
|
|
7801
|
+
var newXPort = relativePosInSideEle.x - x;
|
|
7802
|
+
var newYPort = relativePosInSideEle.y - y;
|
|
7803
|
+
onPortLabelMoved(newXPort, newYPort, id);
|
|
7804
|
+
}
|
|
7805
|
+
}, 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); } });
|
|
7806
|
+
};
|
|
7807
|
+
var renderedShape = React.useMemo(function () {
|
|
7808
|
+
if (renderShape) {
|
|
7809
|
+
var RenderShape = renderShape;
|
|
7810
|
+
return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
|
|
7811
|
+
}
|
|
7812
|
+
else {
|
|
7813
|
+
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" });
|
|
7814
|
+
}
|
|
7815
|
+
}, [props]);
|
|
7816
|
+
return (React.createElement(React.Fragment, null,
|
|
7817
|
+
renderedShape,
|
|
7818
|
+
label && renderLabel(label)));
|
|
7819
|
+
});
|
|
7820
|
+
var Port = React.memo(Port1);
|
|
7821
|
+
|
|
7822
|
+
// Render the svg <path> element
|
|
7823
|
+
function getCurvePathData(points, smoothing, closed) {
|
|
7824
|
+
if (smoothing === void 0) { smoothing = 0.2; }
|
|
7825
|
+
// append first 2 points for closed paths
|
|
7826
|
+
if (closed) {
|
|
7827
|
+
points = points.concat(points.slice(0, 2));
|
|
7828
|
+
}
|
|
7829
|
+
// Properties of a line
|
|
7830
|
+
var line = function (pointA, pointB) {
|
|
7831
|
+
var lengthX = pointB.x - pointA.x;
|
|
7832
|
+
var lengthY = pointB.y - pointA.y;
|
|
7833
|
+
return {
|
|
7834
|
+
length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)),
|
|
7835
|
+
angle: Math.atan2(lengthY, lengthX)
|
|
7836
|
+
};
|
|
7837
|
+
};
|
|
7838
|
+
// Position of a control point
|
|
7839
|
+
var controlPoint = function (current, previous, next, reverse) {
|
|
7840
|
+
var p = previous || current;
|
|
7841
|
+
var n = next || current;
|
|
7842
|
+
var o = line(p, n);
|
|
7843
|
+
var angle = o.angle + (reverse ? Math.PI : 0);
|
|
7844
|
+
var length = o.length * smoothing;
|
|
7845
|
+
var x = current.x + Math.cos(angle) * length;
|
|
7846
|
+
var y = current.y + Math.sin(angle) * length;
|
|
7847
|
+
return { x: x, y: y };
|
|
7848
|
+
};
|
|
7849
|
+
var pathData = [];
|
|
7850
|
+
pathData.push({ type: "M", values: [points[0].x, points[0].y] });
|
|
7851
|
+
for (var i = 1; i < points.length; i++) {
|
|
7852
|
+
var point = points[i];
|
|
7853
|
+
var cp1 = controlPoint(points[i - 1], points[i - 2], point);
|
|
7854
|
+
var cp2 = controlPoint(point, points[i - 1], points[i + 1], true);
|
|
7855
|
+
var command = {
|
|
7856
|
+
type: "C",
|
|
7857
|
+
values: [cp1.x, cp1.y, cp2.x, cp2.y, point.x, point.y]
|
|
7858
|
+
};
|
|
7859
|
+
pathData.push(command);
|
|
7860
|
+
}
|
|
7861
|
+
// copy last commands 1st controlpoint to first curveto
|
|
7862
|
+
if (closed) {
|
|
7863
|
+
var comLast = pathData[pathData.length - 1];
|
|
7864
|
+
var valuesLastC = comLast.values;
|
|
7865
|
+
var valuesFirstC = pathData[1].values;
|
|
7866
|
+
pathData[1] = {
|
|
7867
|
+
type: "C",
|
|
7868
|
+
values: [valuesLastC[0], valuesLastC[1], valuesFirstC.slice(2)].flat()
|
|
7869
|
+
};
|
|
7870
|
+
// delete last curveto
|
|
7871
|
+
pathData = pathData.slice(0, pathData.length - 1);
|
|
7872
|
+
}
|
|
7873
|
+
return pathData;
|
|
7874
|
+
}
|
|
7875
|
+
// convert pathdata to d attribute string
|
|
7876
|
+
function pathDataToD(pathData, decimals) {
|
|
7877
|
+
if (decimals === void 0) { decimals = 3; }
|
|
7878
|
+
var d = pathData
|
|
7879
|
+
.map(function (com) {
|
|
7880
|
+
return "".concat(com.type).concat(com.values.map(function (value) { return +value.toFixed(decimals); }).join(" "));
|
|
7881
|
+
})
|
|
7882
|
+
.join(" ");
|
|
7883
|
+
return d;
|
|
7884
|
+
}
|
|
7885
|
+
function createSmoothPathString(points, smoothing, close) {
|
|
7886
|
+
var pathData = getCurvePathData(points, smoothing, close);
|
|
7887
|
+
var pathString = pathDataToD(pathData);
|
|
7888
|
+
return pathString;
|
|
7889
|
+
}
|
|
7890
|
+
// a helper function to measure the distance between 2 points
|
|
7891
|
+
function dist(p1, p2) {
|
|
7892
|
+
var dx = p2.x - p1.x;
|
|
7893
|
+
var dy = p2.y - p1.y;
|
|
7894
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
7895
|
+
}
|
|
7896
|
+
//find distance from starting point of path to a point
|
|
7897
|
+
function getLengthForPoint(p, thePath, precision) {
|
|
7898
|
+
if (precision === void 0) { precision = 50; }
|
|
7899
|
+
var pathLength = thePath.getTotalLength();
|
|
7900
|
+
var theRecord = pathLength; //length of path
|
|
7901
|
+
var division = pathLength / precision;
|
|
7902
|
+
var theSegment;
|
|
7903
|
+
for (var i = 0; i < precision; i++) {
|
|
7904
|
+
// get a point on the path for thia distance
|
|
7905
|
+
var _p = thePath.getPointAtLength(i * division);
|
|
7906
|
+
// get the distance between the new point _p and the point p
|
|
7907
|
+
var theDistance = dist(_p, p);
|
|
7908
|
+
if (theDistance < theRecord) {
|
|
7909
|
+
// if the distance is smaller than the record set the new record
|
|
7910
|
+
theRecord = theDistance;
|
|
7911
|
+
theSegment = i;
|
|
7912
|
+
}
|
|
7913
|
+
}
|
|
7914
|
+
return (theSegment * division);
|
|
7915
|
+
}
|
|
7916
|
+
//Add points to the list of points in the correct position
|
|
7917
|
+
function addPointToList(point, listPoints, path) {
|
|
7918
|
+
var getAddIndex = function (startIndex, endIndex) {
|
|
7919
|
+
//Add in the middle if there are only 2 points
|
|
7920
|
+
if ((endIndex - startIndex) === 1) {
|
|
7921
|
+
return startIndex + 1;
|
|
7922
|
+
}
|
|
7923
|
+
var middleIndex = Math.ceil((startIndex + endIndex) / 2);
|
|
7924
|
+
var lengthOfMiddlePoint = getLengthForPoint(listPoints[middleIndex], path); //distance from start point to mid point
|
|
7925
|
+
var lengthOfAddedPoint = getLengthForPoint(point, path); //distance from adding point to mid point
|
|
7926
|
+
//compare if lengthOfMiddlePoint is less than lengthOfAddedPoint,
|
|
7927
|
+
//then new point can be added in the range of mid point to end point,
|
|
7928
|
+
//otherwise it can be added in the range of start point to middle point.
|
|
7929
|
+
if (lengthOfAddedPoint < lengthOfMiddlePoint) {
|
|
7930
|
+
return getAddIndex(startIndex, middleIndex);
|
|
7931
|
+
}
|
|
7932
|
+
else {
|
|
7933
|
+
return getAddIndex(middleIndex, endIndex);
|
|
7934
|
+
}
|
|
7935
|
+
};
|
|
7936
|
+
var addedIndex = getAddIndex(0, listPoints.length - 1);
|
|
7937
|
+
listPoints.splice(addedIndex, 0, point);
|
|
7938
|
+
return __spreadArray([], listPoints, true);
|
|
7939
|
+
}
|
|
7940
|
+
|
|
7941
|
+
//Defined remove icon for element link, shown when element link is selected.
|
|
7942
|
+
function CloseIcon(_a) {
|
|
7943
|
+
var onClick = _a.onClick;
|
|
7944
|
+
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' },
|
|
7945
|
+
React.createElement("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0", transform: "translate(3.84,3.84), scale(0.68)" },
|
|
7946
|
+
React.createElement("rect", { x: "0", y: "0", width: "24.00", height: "24.00", rx: "12", fill: "#ffffff", strokeWidth: "0" })),
|
|
7947
|
+
React.createElement("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round", stroke: "#CCCCCC", "stroke-width": "0.048" }),
|
|
7948
|
+
React.createElement("g", { id: "SVGRepo_iconCarrier" },
|
|
7949
|
+
React.createElement("g", null,
|
|
7950
|
+
React.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
|
|
7951
|
+
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" })))));
|
|
7952
|
+
}
|
|
7953
|
+
|
|
7777
7954
|
var makerStart = React.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
|
|
7778
7955
|
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>
|
|
7779
7956
|
var IElementLink = function (_a) {
|
|
@@ -7792,6 +7969,11 @@ var IElementLink = function (_a) {
|
|
|
7792
7969
|
var labelRef = React.useRef(null);
|
|
7793
7970
|
var sourceLabelRef = React.useRef(null);
|
|
7794
7971
|
var targetLabelRef = React.useRef(null);
|
|
7972
|
+
var angleMarkerStart = '0';
|
|
7973
|
+
var angleMarkerEnd = '0';
|
|
7974
|
+
var markerStartPosition;
|
|
7975
|
+
var markerEndPosition;
|
|
7976
|
+
var centerPathPosition = undefined;
|
|
7795
7977
|
React.useEffect(function () {
|
|
7796
7978
|
var paperClickListener = onPaperClicked(function () {
|
|
7797
7979
|
setSelectedLabelRef({
|
|
@@ -7818,7 +8000,7 @@ var IElementLink = function (_a) {
|
|
|
7818
8000
|
}, []);
|
|
7819
8001
|
React.useLayoutEffect(function () {
|
|
7820
8002
|
var pointsList = __spreadArray(__spreadArray([sourcePosition], points, true), [targetPosition], false);
|
|
7821
|
-
var _pathStr = createSmoothPathString(pointsList, undefined);
|
|
8003
|
+
var _pathStr = createSmoothPathString(pointsList, undefined, false);
|
|
7822
8004
|
setPathStr(_pathStr);
|
|
7823
8005
|
}, [sourcePosition, points, targetPosition]);
|
|
7824
8006
|
React.useEffect(function () {
|
|
@@ -7908,16 +8090,22 @@ var IElementLink = function (_a) {
|
|
|
7908
8090
|
setDraggingPointIndex(_draggingPointIndex);
|
|
7909
8091
|
setPoints(pointsWithoutStartEndPoint);
|
|
7910
8092
|
};
|
|
7911
|
-
var handleLabelMoved = function (
|
|
8093
|
+
var handleLabelMoved = function (newX, newY) {
|
|
8094
|
+
if (!onLabelMoved)
|
|
8095
|
+
return;
|
|
8096
|
+
var newPosition;
|
|
7912
8097
|
switch (selectedLabelRef.current) {
|
|
7913
8098
|
case labelRef.current:
|
|
7914
|
-
|
|
8099
|
+
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY }, centerPathPosition);
|
|
8100
|
+
onLabelMoved(newPosition.x, newPosition.y, 'middle');
|
|
7915
8101
|
break;
|
|
7916
8102
|
case sourceLabelRef.current:
|
|
7917
|
-
|
|
8103
|
+
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY }, sourcePosition);
|
|
8104
|
+
onLabelMoved(newPosition.x, newPosition.y, 'source');
|
|
7918
8105
|
break;
|
|
7919
8106
|
case targetLabelRef.current:
|
|
7920
|
-
|
|
8107
|
+
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY }, targetPosition);
|
|
8108
|
+
onLabelMoved(newPosition.x, newPosition.y, 'target');
|
|
7921
8109
|
break;
|
|
7922
8110
|
}
|
|
7923
8111
|
};
|
|
@@ -7952,7 +8140,6 @@ var IElementLink = function (_a) {
|
|
|
7952
8140
|
onSelected === null || onSelected === void 0 ? void 0 : onSelected();
|
|
7953
8141
|
};
|
|
7954
8142
|
var renderLabel = function (label, labelType, relativePositionTo) {
|
|
7955
|
-
if (relativePositionTo === void 0) { relativePositionTo = { x: 0, y: 0 }; }
|
|
7956
8143
|
var content = label.content, size = label.size;
|
|
7957
8144
|
var relativePosition = label.position;
|
|
7958
8145
|
var curLabelRef;
|
|
@@ -7979,16 +8166,15 @@ var IElementLink = function (_a) {
|
|
|
7979
8166
|
throw new Error('This type of label does not exist.');
|
|
7980
8167
|
}
|
|
7981
8168
|
var position = {
|
|
7982
|
-
x: relativePosition.x
|
|
7983
|
-
y: relativePosition.y
|
|
8169
|
+
x: relativePosition.x,
|
|
8170
|
+
y: relativePosition.y,
|
|
7984
8171
|
};
|
|
8172
|
+
if (relativePositionTo) {
|
|
8173
|
+
position.x += relativePositionTo.x;
|
|
8174
|
+
position.y += relativePositionTo.y;
|
|
8175
|
+
}
|
|
7985
8176
|
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 }));
|
|
7986
8177
|
};
|
|
7987
|
-
var angleMarkerStart = '0';
|
|
7988
|
-
var angleMarkerEnd = '0';
|
|
7989
|
-
var markerStartPosition;
|
|
7990
|
-
var markerEndPosition;
|
|
7991
|
-
var centerPathPosition;
|
|
7992
8178
|
if ((_b = pathRef.current) === null || _b === void 0 ? void 0 : _b.getAttribute('d')) {
|
|
7993
8179
|
if (markerStart) {
|
|
7994
8180
|
markerStartPosition = pathRef.current.getPointAtLength(markerDistanceFromPort);
|
|
@@ -8015,6 +8201,129 @@ var IElementLink = function (_a) {
|
|
|
8015
8201
|
};
|
|
8016
8202
|
var ElementLink = React.memo(IElementLink);
|
|
8017
8203
|
|
|
8204
|
+
var getSVGBBoxOutsideTransformedParent = function (svgElement) {
|
|
8205
|
+
var bbox = svgElement.getBBox(); // Get bounding box of the element
|
|
8206
|
+
var matrix = svgElement.getCTM(); // Get the current transformation matrix of the parent element
|
|
8207
|
+
// Define the four corners of the bounding box
|
|
8208
|
+
var corners = [
|
|
8209
|
+
{ x: bbox.x, y: bbox.y },
|
|
8210
|
+
{ x: bbox.x + bbox.width, y: bbox.y },
|
|
8211
|
+
{ x: bbox.x + bbox.width, y: bbox.y + bbox.height },
|
|
8212
|
+
{ x: bbox.x, y: bbox.y + bbox.height } // Bottom-left
|
|
8213
|
+
];
|
|
8214
|
+
// Function to apply the transformation matrix to a point
|
|
8215
|
+
function transformPoint(x, y, matrix) {
|
|
8216
|
+
return {
|
|
8217
|
+
x: matrix.a * x + matrix.c * y + matrix.e,
|
|
8218
|
+
y: matrix.b * x + matrix.d * y + matrix.f
|
|
8219
|
+
};
|
|
8220
|
+
}
|
|
8221
|
+
// Transform each corner according to the matrix
|
|
8222
|
+
if (matrix) {
|
|
8223
|
+
return corners.map(function (corner) {
|
|
8224
|
+
return transformPoint(corner.x, corner.y, matrix);
|
|
8225
|
+
});
|
|
8226
|
+
}
|
|
8227
|
+
else {
|
|
8228
|
+
return corners;
|
|
8229
|
+
}
|
|
8230
|
+
};
|
|
8231
|
+
//function returns the array of corners of the bbox of the element after applying the transformation matrix of the parent element
|
|
8232
|
+
var getRotatedSVGBBox = function (svgElement) {
|
|
8233
|
+
var bbox = svgElement.getBBox(); // Get bounding box of the element
|
|
8234
|
+
var matrix = svgElement.getCTM(); // Get the current transformation matrix of the parent element
|
|
8235
|
+
// Define the four corners of the bounding box
|
|
8236
|
+
var corners = [
|
|
8237
|
+
{ x: bbox.x, y: bbox.y },
|
|
8238
|
+
{ x: bbox.x + bbox.width, y: bbox.y },
|
|
8239
|
+
{ x: bbox.x + bbox.width, y: bbox.y + bbox.height },
|
|
8240
|
+
{ x: bbox.x, y: bbox.y + bbox.height } // Bottom-left
|
|
8241
|
+
];
|
|
8242
|
+
// Function to apply the transformation matrix to a point
|
|
8243
|
+
function transformPoint(x, y, matrix) {
|
|
8244
|
+
return {
|
|
8245
|
+
x: matrix.a * x + matrix.c * y,
|
|
8246
|
+
y: matrix.b * x + matrix.d * y // + matrix.f
|
|
8247
|
+
};
|
|
8248
|
+
}
|
|
8249
|
+
// Transform each corner according to the matrix
|
|
8250
|
+
if (matrix) {
|
|
8251
|
+
return corners.map(function (corner) {
|
|
8252
|
+
return transformPoint(corner.x, corner.y, matrix);
|
|
8253
|
+
});
|
|
8254
|
+
}
|
|
8255
|
+
else {
|
|
8256
|
+
return corners;
|
|
8257
|
+
}
|
|
8258
|
+
};
|
|
8259
|
+
|
|
8260
|
+
var Logger = /** @class */ (function () {
|
|
8261
|
+
function Logger() {
|
|
8262
|
+
this.level = 'info';
|
|
8263
|
+
this.customLogger = null;
|
|
8264
|
+
}
|
|
8265
|
+
Logger.prototype.setLevel = function (level) {
|
|
8266
|
+
this.level = level;
|
|
8267
|
+
};
|
|
8268
|
+
Logger.prototype.setCustomLogger = function (logger) {
|
|
8269
|
+
this.customLogger = logger;
|
|
8270
|
+
};
|
|
8271
|
+
Logger.prototype.log = function (level, message) {
|
|
8272
|
+
var _a;
|
|
8273
|
+
var optionalParams = [];
|
|
8274
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
8275
|
+
optionalParams[_i - 2] = arguments[_i];
|
|
8276
|
+
}
|
|
8277
|
+
var levels = ['error', 'warn', 'info', 'debug'];
|
|
8278
|
+
if (this.level && levels.indexOf(level) <= levels.indexOf(this.level)) {
|
|
8279
|
+
if (this.customLogger) {
|
|
8280
|
+
this.customLogger.apply(this, __spreadArray([level, message], optionalParams, false));
|
|
8281
|
+
}
|
|
8282
|
+
else {
|
|
8283
|
+
console[level] ? (_a = console)[level].apply(_a, __spreadArray([message], optionalParams, false)) : console.log.apply(console, __spreadArray([message], optionalParams, false));
|
|
8284
|
+
}
|
|
8285
|
+
}
|
|
8286
|
+
};
|
|
8287
|
+
Logger.prototype.error = function (msg) {
|
|
8288
|
+
var optionalParams = [];
|
|
8289
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
8290
|
+
optionalParams[_i - 1] = arguments[_i];
|
|
8291
|
+
}
|
|
8292
|
+
this.log.apply(this, __spreadArray(['error', msg], optionalParams, false));
|
|
8293
|
+
};
|
|
8294
|
+
Logger.prototype.warn = function (msg) {
|
|
8295
|
+
var optionalParams = [];
|
|
8296
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
8297
|
+
optionalParams[_i - 1] = arguments[_i];
|
|
8298
|
+
}
|
|
8299
|
+
this.log.apply(this, __spreadArray(['warn', msg], optionalParams, false));
|
|
8300
|
+
};
|
|
8301
|
+
Logger.prototype.info = function (msg) {
|
|
8302
|
+
var optionalParams = [];
|
|
8303
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
8304
|
+
optionalParams[_i - 1] = arguments[_i];
|
|
8305
|
+
}
|
|
8306
|
+
this.log.apply(this, __spreadArray(['info', msg], optionalParams, false));
|
|
8307
|
+
};
|
|
8308
|
+
Logger.prototype.debug = function (msg) {
|
|
8309
|
+
var optionalParams = [];
|
|
8310
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
8311
|
+
optionalParams[_i - 1] = arguments[_i];
|
|
8312
|
+
}
|
|
8313
|
+
this.log.apply(this, __spreadArray(['debug', msg], optionalParams, false));
|
|
8314
|
+
};
|
|
8315
|
+
return Logger;
|
|
8316
|
+
}());
|
|
8317
|
+
var logger = new Logger();
|
|
8318
|
+
|
|
8319
|
+
function configureLogger(_a) {
|
|
8320
|
+
var level = _a.level, customLogger = _a.customLogger;
|
|
8321
|
+
if (level !== undefined)
|
|
8322
|
+
logger.setLevel(level);
|
|
8323
|
+
if (customLogger)
|
|
8324
|
+
logger.setCustomLogger(customLogger);
|
|
8325
|
+
}
|
|
8326
|
+
|
|
8018
8327
|
var Ruler = function (_a) {
|
|
8019
8328
|
var squareSize = _a.squareSize, border = _a.border;
|
|
8020
8329
|
var numColumns = Math.ceil(3000 / squareSize);
|
|
@@ -8054,46 +8363,9 @@ var ElementWrapper = React.forwardRef(function (_a, ref) {
|
|
|
8054
8363
|
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));
|
|
8055
8364
|
});
|
|
8056
8365
|
|
|
8057
|
-
|
|
8058
|
-
var getRectangleCorners = function (rectSVG) {
|
|
8059
|
-
var ownerSVG = rectSVG.ownerSVGElement;
|
|
8060
|
-
var rectStrokeWidth = Number(rectSVG.getAttribute('stroke-width')) || 0;
|
|
8061
|
-
var strokeWidthOffset = rectStrokeWidth / 2;
|
|
8062
|
-
if (!ownerSVG) {
|
|
8063
|
-
throw new Error('Rectangle does not wrapper by svg.');
|
|
8064
|
-
}
|
|
8065
|
-
var ownerX = ownerSVG.x.baseVal.value;
|
|
8066
|
-
var ownerY = ownerSVG.y.baseVal.value;
|
|
8067
|
-
var ownerWidth = ownerSVG.width.baseVal.value;
|
|
8068
|
-
var ownerHeight = ownerSVG.height.baseVal.value;
|
|
8069
|
-
var a = { x: ownerX + strokeWidthOffset, y: ownerY + strokeWidthOffset };
|
|
8070
|
-
var b = { x: ownerX + ownerWidth - strokeWidthOffset, y: ownerY + strokeWidthOffset };
|
|
8071
|
-
var c = { x: ownerX + ownerWidth - strokeWidthOffset, y: ownerY + ownerHeight - strokeWidthOffset };
|
|
8072
|
-
var d = { x: ownerX + strokeWidthOffset, y: ownerY + ownerHeight - strokeWidthOffset };
|
|
8073
|
-
return [a, b, c, d];
|
|
8074
|
-
};
|
|
8075
|
-
//find rotation angle of svg element on g element
|
|
8076
|
-
var getElementRotationInfo = function (element) {
|
|
8077
|
-
var gElement = element;
|
|
8078
|
-
var rotationAngle = 0;
|
|
8079
|
-
while (!(gElement instanceof SVGGElement)) {
|
|
8080
|
-
gElement = gElement.parentElement;
|
|
8081
|
-
}
|
|
8082
|
-
var transform = gElement.getAttribute('transform');
|
|
8083
|
-
if (transform) {
|
|
8084
|
-
// Match the rotation value using a regular expression
|
|
8085
|
-
var rotateMatch = transform.match(/rotate\(([-\d.]+)(?:\s+[-\d.]+\s+[-\d.]+)?\)/);
|
|
8086
|
-
if (rotateMatch) {
|
|
8087
|
-
// The first capture group is the rotation angle
|
|
8088
|
-
rotationAngle = parseFloat(rotateMatch[1]);
|
|
8089
|
-
}
|
|
8090
|
-
}
|
|
8091
|
-
return rotationAngle;
|
|
8092
|
-
};
|
|
8093
|
-
|
|
8094
|
-
var Element = function (props) {
|
|
8366
|
+
var Element = React.forwardRef(function (props, forwardedRef) {
|
|
8095
8367
|
var _a, _b;
|
|
8096
|
-
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;
|
|
8368
|
+
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, parentAbsolutePosition = props.parentAbsolutePosition; 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;
|
|
8097
8369
|
var _c = React.useState(), selectedPort = _c[0], setSelectedPort = _c[1];
|
|
8098
8370
|
var _d = React.useState(), hoveredPort = _d[0], setHoveredPort = _d[1];
|
|
8099
8371
|
var _e = React.useState([]), ports = _e[0], setPorts = _e[1];
|
|
@@ -8101,14 +8373,28 @@ var Element = function (props) {
|
|
|
8101
8373
|
var _g = React.useState(), potentialPortPosition = _g[0], setPotentialPortPosition = _g[1];
|
|
8102
8374
|
var _paperEventEmitterContext = React.useContext(paperEventEmitterContext);
|
|
8103
8375
|
var elementRef = React.useRef(null);
|
|
8376
|
+
React.useImperativeHandle(forwardedRef, function () { return elementRef.current; });
|
|
8104
8377
|
var elementLinkStarted = React.useRef();
|
|
8105
8378
|
var portsRef = React.useRef(ports);
|
|
8379
|
+
var getElementAbsPosition = React.useCallback(function () {
|
|
8380
|
+
var position = {
|
|
8381
|
+
x: x,
|
|
8382
|
+
y: y,
|
|
8383
|
+
};
|
|
8384
|
+
if (parentAbsolutePosition) {
|
|
8385
|
+
position.x += parentAbsolutePosition.x;
|
|
8386
|
+
position.y += parentAbsolutePosition.y;
|
|
8387
|
+
}
|
|
8388
|
+
return position;
|
|
8389
|
+
}, [x, y, parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.x, parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.y]);
|
|
8390
|
+
var elementAbsPosition = React.useMemo(function () { return getElementAbsPosition(); }, [getElementAbsPosition]);
|
|
8106
8391
|
//Listen to manually trigger render event
|
|
8107
8392
|
React.useEffect(function () {
|
|
8108
8393
|
var _a;
|
|
8109
8394
|
var off = (_a = props.onManuallyTriggerRenderPort) === null || _a === void 0 ? void 0 : _a.call(props, function (portId, elementId) {
|
|
8110
8395
|
if (elementId !== id)
|
|
8111
8396
|
return;
|
|
8397
|
+
logger.info('onManuallyTriggerRenderPort', id);
|
|
8112
8398
|
setPorts(function (prev) { return __spreadArray([], prev, true); });
|
|
8113
8399
|
});
|
|
8114
8400
|
return function () {
|
|
@@ -8119,13 +8405,9 @@ var Element = function (props) {
|
|
|
8119
8405
|
React.useEffect(function () {
|
|
8120
8406
|
portsRef.current = ports;
|
|
8121
8407
|
}, [ports]);
|
|
8122
|
-
React.useEffect(function () {
|
|
8123
|
-
var _a;
|
|
8124
|
-
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);
|
|
8125
|
-
});
|
|
8126
8408
|
//Listen a new port is created, after add new port to ports state
|
|
8127
8409
|
React.useEffect(function () {
|
|
8128
|
-
|
|
8410
|
+
logger.info('Ports changed', props.ports);
|
|
8129
8411
|
setPorts(function (prev) {
|
|
8130
8412
|
var _a, _b;
|
|
8131
8413
|
return (_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p, index) {
|
|
@@ -8239,28 +8521,6 @@ var Element = function (props) {
|
|
|
8239
8521
|
setSelectedPort(port);
|
|
8240
8522
|
_paperEventEmitterContext.emitPortSelected(port, id);
|
|
8241
8523
|
}, [_paperEventEmitterContext]);
|
|
8242
|
-
//Normalize a point so that it can lie exactly on an area
|
|
8243
|
-
var normalizePortPositionOnMoveableAreas = function (moveableAreas, position) {
|
|
8244
|
-
var lines = moveableAreas.filter(function (area) { return area.length === 2; });
|
|
8245
|
-
var polygons = moveableAreas.filter(function (area) { return area.length >= 3; });
|
|
8246
|
-
var normalizedPosition;
|
|
8247
|
-
//If moveableAreas is lines
|
|
8248
|
-
if (lines.length > 0) {
|
|
8249
|
-
var newPosition = findNearestProjectedPoint({ x: position.x, y: position.y }, lines);
|
|
8250
|
-
if (newPosition) {
|
|
8251
|
-
normalizedPosition = newPosition;
|
|
8252
|
-
}
|
|
8253
|
-
}
|
|
8254
|
-
//If moveableAreas is polygons
|
|
8255
|
-
else if (polygons.length > 0) {
|
|
8256
|
-
var newPosition_1 = { x: position.x, y: position.y };
|
|
8257
|
-
var isContainsInPolygons = polygons.some(function (p) { return checkPointContainsPolygon(newPosition_1, p); });
|
|
8258
|
-
if (isContainsInPolygons) {
|
|
8259
|
-
normalizedPosition = newPosition_1;
|
|
8260
|
-
}
|
|
8261
|
-
}
|
|
8262
|
-
return normalizedPosition;
|
|
8263
|
-
};
|
|
8264
8524
|
//Calculate the position of the 4 vertices of a rectangle relative to element
|
|
8265
8525
|
var calculateSlideRailRectSVGPositions = function (slideRailSVG) {
|
|
8266
8526
|
var coordinates = getRectangleCorners(slideRailSVG);
|
|
@@ -8277,57 +8537,20 @@ var Element = function (props) {
|
|
|
8277
8537
|
var _a;
|
|
8278
8538
|
var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
|
|
8279
8539
|
return slideRailSVG;
|
|
8280
|
-
}, [
|
|
8281
|
-
var normalizePortPositionOnSlideRailSVG = function (portSlideRailSVGClassName, position) {
|
|
8282
|
-
var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
|
|
8283
|
-
if (!slideRailSVG)
|
|
8284
|
-
return;
|
|
8285
|
-
var moveTo;
|
|
8286
|
-
//check and get new position if Rect element
|
|
8287
|
-
if (slideRailSVG instanceof SVGRectElement) {
|
|
8288
|
-
var _a = calculateSlideRailRectSVGPositions(slideRailSVG), a = _a[0], b = _a[1], c = _a[2], d = _a[3]; //Get 4 vertices of rect element
|
|
8289
|
-
var moveableAreas = [
|
|
8290
|
-
[a, b],
|
|
8291
|
-
[b, c],
|
|
8292
|
-
[c, d],
|
|
8293
|
-
[d, a]
|
|
8294
|
-
];
|
|
8295
|
-
var newPosition = normalizePortPositionOnMoveableAreas(moveableAreas, position);
|
|
8296
|
-
if (newPosition) {
|
|
8297
|
-
moveTo = newPosition;
|
|
8298
|
-
}
|
|
8299
|
-
}
|
|
8300
|
-
else if (slideRailSVG instanceof SVGCircleElement) { //check and get new position if circle element
|
|
8301
|
-
var cx = Number(slideRailSVG.getAttribute('cx'));
|
|
8302
|
-
var cy = Number(slideRailSVG.getAttribute('cy'));
|
|
8303
|
-
var r = Number(slideRailSVG.getAttribute('r'));
|
|
8304
|
-
var circle = Flatten$1.circle(Flatten$1.point(cx, cy), r);
|
|
8305
|
-
var _b = circle.distanceTo(Flatten$1.point(position.x, position.y)), num = _b[0], segment = _b[1];
|
|
8306
|
-
if (num <= r) {
|
|
8307
|
-
moveTo = {
|
|
8308
|
-
x: segment.ps.x,
|
|
8309
|
-
y: segment.ps.y,
|
|
8310
|
-
};
|
|
8311
|
-
}
|
|
8312
|
-
}
|
|
8313
|
-
return moveTo;
|
|
8314
|
-
};
|
|
8540
|
+
}, []);
|
|
8315
8541
|
//Normalize port position
|
|
8316
8542
|
var normalizePortPosition = function (tempNewPosition) {
|
|
8317
|
-
var newPosition;
|
|
8318
|
-
if (portMoveableAreas && portMoveableAreas.length > 0) { //If moveable areas is defined
|
|
8319
|
-
newPosition = normalizePortPositionOnMoveableAreas(portMoveableAreas, tempNewPosition);
|
|
8320
|
-
}
|
|
8321
|
-
else if (portSlideRailSVGClassName) { //If port slide rail svg classname is defined
|
|
8322
|
-
newPosition = normalizePortPositionOnSlideRailSVG(portSlideRailSVGClassName, tempNewPosition);
|
|
8323
|
-
}
|
|
8543
|
+
var newPosition = correctPortPositionInElement(tempNewPosition, width, height, portMoveableAreas, portSlideRailSVGClassName, elementRef.current || undefined);
|
|
8324
8544
|
return newPosition || tempNewPosition;
|
|
8325
8545
|
};
|
|
8326
|
-
var handlePortMove = function (
|
|
8546
|
+
var handlePortMove = function (newX, newY) {
|
|
8327
8547
|
if (!selectedPort)
|
|
8328
8548
|
return;
|
|
8329
8549
|
var oldPosition = __assign({}, selectedPort.position);
|
|
8330
|
-
var tempNewPosition = {
|
|
8550
|
+
var tempNewPosition = transformAbsPositionToRelativePositionInsideElement({
|
|
8551
|
+
x: newX,
|
|
8552
|
+
y: newY,
|
|
8553
|
+
}, elementAbsPosition);
|
|
8331
8554
|
//handle to keep the port always in the correct allowed position
|
|
8332
8555
|
var newPosition = normalizePortPosition(tempNewPosition);
|
|
8333
8556
|
if (newPosition) {
|
|
@@ -8360,15 +8583,17 @@ var Element = function (props) {
|
|
|
8360
8583
|
}
|
|
8361
8584
|
}, [_paperEventEmitterContext, potentialPortPosition]);
|
|
8362
8585
|
//Update state when label of port is moved
|
|
8363
|
-
var handlePortLabelMoved = React.useCallback(function (
|
|
8586
|
+
var handlePortLabelMoved = React.useCallback(function (newX, newY, portId) {
|
|
8364
8587
|
setPorts(function (prevPorts) {
|
|
8365
8588
|
return prevPorts.map(function (p) {
|
|
8366
8589
|
if (p.id === portId && p.label) {
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8371
|
-
|
|
8590
|
+
var newLabel = Object.assign(Object.create(Object.getPrototypeOf(p.label)), p.label);
|
|
8591
|
+
var newPosition = {
|
|
8592
|
+
x: newX,
|
|
8593
|
+
y: newY
|
|
8594
|
+
};
|
|
8595
|
+
newLabel.position = newPosition;
|
|
8596
|
+
p.label = newLabel;
|
|
8372
8597
|
}
|
|
8373
8598
|
return p;
|
|
8374
8599
|
});
|
|
@@ -8467,7 +8692,7 @@ var Element = function (props) {
|
|
|
8467
8692
|
}, [someElementLinkStarted]);
|
|
8468
8693
|
//Get rotate angle of port by port direction is defined.
|
|
8469
8694
|
var rotatePort = React.useCallback(function (x, y) {
|
|
8470
|
-
//
|
|
8695
|
+
// logger.info('calculating port rotation', x, y)
|
|
8471
8696
|
if (!portSlideRailSVGClassName)
|
|
8472
8697
|
return 0;
|
|
8473
8698
|
var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
|
|
@@ -8527,9 +8752,11 @@ var Element = function (props) {
|
|
|
8527
8752
|
enabled: false,
|
|
8528
8753
|
keepRatio: false
|
|
8529
8754
|
},
|
|
8755
|
+
x: selectedPort ? elementAbsPosition.x + selectedPort.position.x : undefined,
|
|
8756
|
+
y: selectedPort ? elementAbsPosition.y + selectedPort.position.y : undefined,
|
|
8530
8757
|
// width: selectedPort?.size.width,
|
|
8531
8758
|
// height: selectedPort?.size.height,
|
|
8532
|
-
movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
|
|
8759
|
+
// movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
|
|
8533
8760
|
onMove: handlePortMove
|
|
8534
8761
|
});
|
|
8535
8762
|
useSelectionFrame({
|
|
@@ -8547,7 +8774,7 @@ var Element = function (props) {
|
|
|
8547
8774
|
: 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 :
|
|
8548
8775
|
ports.map(function (p, index) {
|
|
8549
8776
|
var _a, _b, _c, _d, _e, _f;
|
|
8550
|
-
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,
|
|
8777
|
+
return React.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, parentAbsolutePosition: elementAbsPosition, 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,
|
|
8551
8778
|
// rotation={rotatePort(p)}
|
|
8552
8779
|
calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: handlePortLabelMoved, onPortLabelResized: handlePortLabelResized, onPortLabelContentChanged: handlePortLabelContentChanged, onSelected: handleSelectedPort, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, onMouseMove: handlePortMouseMove,
|
|
8553
8780
|
// onMouseEnter={() => {
|
|
@@ -8559,10 +8786,10 @@ var Element = function (props) {
|
|
|
8559
8786
|
}), texts === null || texts === void 0 ? void 0 :
|
|
8560
8787
|
texts.map(function (t, index) {
|
|
8561
8788
|
var _a, _b;
|
|
8562
|
-
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); } });
|
|
8789
|
+
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) || 0, y: ((_b = t.position) === null || _b === void 0 ? void 0 : _b.y) || 0, 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, parentAbsolutePosition: elementAbsPosition, onContentChanged: function (ev, newContent) { return onTextUpdated === null || onTextUpdated === void 0 ? void 0 : onTextUpdated(id, t.id, newContent); } });
|
|
8563
8790
|
}),
|
|
8564
8791
|
children));
|
|
8565
|
-
};
|
|
8792
|
+
});
|
|
8566
8793
|
var Element$1 = React.memo(Element);
|
|
8567
8794
|
|
|
8568
8795
|
var createRect = function (x, y, width, height, strokeWidth, transformOrigin, transform) {
|
|
@@ -8815,6 +9042,15 @@ var automationAddPointsToLink = function (eleLink, elements, limitPoint) {
|
|
|
8815
9042
|
return eleLink;
|
|
8816
9043
|
};
|
|
8817
9044
|
|
|
9045
|
+
function adjustElementPositionOnParentPortArea(element, toBeAdjustedRelativePosition) {
|
|
9046
|
+
var _a;
|
|
9047
|
+
if (element.moveAsPortOnParent && element.parentElement) {
|
|
9048
|
+
var parentDOM = (_a = element.parentElementInTree) === null || _a === void 0 ? void 0 : _a.DOM;
|
|
9049
|
+
var newRelativePosition = transformAbsPositionToElementRelativePosition(toBeAdjustedRelativePosition, element);
|
|
9050
|
+
return correctPortPositionInElement(newRelativePosition, element.size.width, element.size.height, element.parentElement.portMoveableAreas, element.parentElement.portSlideRailSVGClassName, parentDOM);
|
|
9051
|
+
}
|
|
9052
|
+
return toBeAdjustedRelativePosition;
|
|
9053
|
+
}
|
|
8818
9054
|
function convertElementsToTree(elements) {
|
|
8819
9055
|
//Find child elements in the child elements, that is possible child of element, then return element with child of it.
|
|
8820
9056
|
function findChildElementsOfNode(elementNodeInTree, possibleChildElements) {
|
|
@@ -8826,6 +9062,11 @@ function convertElementsToTree(elements) {
|
|
|
8826
9062
|
var orphanedElements = possibleChildElements.filter(function (ele) { var _a; return ((_a = ele.parentElement) === null || _a === void 0 ? void 0 : _a.id) !== elementNodeInTree.id; });
|
|
8827
9063
|
var childElementsWithChild = foundChildElements.map(function (_elementNodeInTree) {
|
|
8828
9064
|
var newNode = findChildElementsOfNode(_elementNodeInTree, orphanedElements);
|
|
9065
|
+
newNode.parentElementInTree = elementNodeInTree;
|
|
9066
|
+
//Adjust position of element if it should move as a port on parent port area
|
|
9067
|
+
if (newNode.moveAsPortOnParent && newNode.parentElementInTree) {
|
|
9068
|
+
newNode.position = adjustElementPositionOnParentPortArea(newNode, newNode.position);
|
|
9069
|
+
}
|
|
8829
9070
|
return newNode;
|
|
8830
9071
|
});
|
|
8831
9072
|
elementNodeInTree.childrenElementsInTree = childElementsWithChild;
|
|
@@ -8857,6 +9098,7 @@ var Paper = function (props) {
|
|
|
8857
9098
|
var linksRef = React.useRef(links); //Cache links to avoid re-render when links changed
|
|
8858
9099
|
var textsRef = React.useRef(texts); //Cache texts to avoid re-render when texts changed
|
|
8859
9100
|
var size = props.size;
|
|
9101
|
+
var selectedElementAbsPosition = React.useMemo(function () { return selectedElement ? getAbsolutePosition(selectedElement) : null; }, [selectedElement]);
|
|
8860
9102
|
React.useEffect(function () {
|
|
8861
9103
|
setElements(props.elements);
|
|
8862
9104
|
}, [props.elements]);
|
|
@@ -8936,6 +9178,7 @@ var Paper = function (props) {
|
|
|
8936
9178
|
var parentChangedCancelers = elementsRef.current.map(function (element) {
|
|
8937
9179
|
var _a;
|
|
8938
9180
|
return (_a = element.onParentChanged) === null || _a === void 0 ? void 0 : _a.call(element, function (newPa, oldPa) {
|
|
9181
|
+
logger.info('onParentChanged');
|
|
8939
9182
|
updateElementsTree();
|
|
8940
9183
|
});
|
|
8941
9184
|
});
|
|
@@ -8943,7 +9186,7 @@ var Paper = function (props) {
|
|
|
8943
9186
|
var addedPortCancelers = elementsRef.current.map(function (element) {
|
|
8944
9187
|
var _a;
|
|
8945
9188
|
return (_a = element.onAddedPort) === null || _a === void 0 ? void 0 : _a.call(element, function (newPort) {
|
|
8946
|
-
|
|
9189
|
+
logger.info("A new port has been added to element ".concat(element.id));
|
|
8947
9190
|
var prevElements = elementsRef.current;
|
|
8948
9191
|
var newElements = prevElements.map(function (ele) {
|
|
8949
9192
|
if (ele.id === element.id) {
|
|
@@ -9235,35 +9478,24 @@ var Paper = function (props) {
|
|
|
9235
9478
|
setTempLink(null);
|
|
9236
9479
|
}
|
|
9237
9480
|
}, [paperEventEmitter, createElementLink, props.onPortMouseUp, props.onLinksChanged]);
|
|
9238
|
-
var handleLinkLabelMoved = React.useCallback(function (
|
|
9481
|
+
var handleLinkLabelMoved = React.useCallback(function (newX, newY, index, labelType) {
|
|
9239
9482
|
var prevLinks = linksRef.current;
|
|
9240
9483
|
var newLinks = __spreadArray([], prevLinks, true);
|
|
9241
9484
|
var currentLink = newLinks[index];
|
|
9485
|
+
var newPosition = {
|
|
9486
|
+
x: newX,
|
|
9487
|
+
y: newY,
|
|
9488
|
+
};
|
|
9242
9489
|
switch (labelType) {
|
|
9243
9490
|
case 'middle': {
|
|
9244
|
-
var oldPosition = currentLink.label.position || LINK_LABEL_POSITION_FROM_LINK_MID_POINT;
|
|
9245
|
-
var newPosition = {
|
|
9246
|
-
x: oldPosition.x + offsetX,
|
|
9247
|
-
y: oldPosition.y + offsetY,
|
|
9248
|
-
};
|
|
9249
9491
|
currentLink.label.position = newPosition;
|
|
9250
9492
|
break;
|
|
9251
9493
|
}
|
|
9252
9494
|
case 'source': {
|
|
9253
|
-
var oldPosition = currentLink.sourceLabel.position || LINK_SOURCE_LABEL_POSITION_FROM_SOURCE_PORT;
|
|
9254
|
-
var newPosition = {
|
|
9255
|
-
x: oldPosition.x + offsetX,
|
|
9256
|
-
y: oldPosition.y + offsetY,
|
|
9257
|
-
};
|
|
9258
9495
|
currentLink.sourceLabel.position = newPosition;
|
|
9259
9496
|
break;
|
|
9260
9497
|
}
|
|
9261
9498
|
case 'target': {
|
|
9262
|
-
var oldPosition = currentLink.targetLabel.position || LINK_TARGET_LABEL_POSITION_FROM_TARGET_PORT;
|
|
9263
|
-
var newPosition = {
|
|
9264
|
-
x: oldPosition.x + offsetX,
|
|
9265
|
-
y: oldPosition.y + offsetY,
|
|
9266
|
-
};
|
|
9267
9499
|
currentLink.targetLabel.position = newPosition;
|
|
9268
9500
|
break;
|
|
9269
9501
|
}
|
|
@@ -9338,9 +9570,16 @@ var Paper = function (props) {
|
|
|
9338
9570
|
setSelectedLink(undefined);
|
|
9339
9571
|
};
|
|
9340
9572
|
//update absolute position of element and absolute position of children elements
|
|
9341
|
-
var updateElementPosition = function (element,
|
|
9342
|
-
|
|
9343
|
-
|
|
9573
|
+
var updateElementPosition = function (element, x, y, isRelativePosition) {
|
|
9574
|
+
if (isRelativePosition) {
|
|
9575
|
+
element.position.x = x;
|
|
9576
|
+
element.position.y = y;
|
|
9577
|
+
}
|
|
9578
|
+
else {
|
|
9579
|
+
var relativePosition = transformAbsPositionToElementRelativePosition({ x: x, y: y }, element);
|
|
9580
|
+
element.position.x = relativePosition.x;
|
|
9581
|
+
element.position.y = relativePosition.y;
|
|
9582
|
+
}
|
|
9344
9583
|
return element;
|
|
9345
9584
|
};
|
|
9346
9585
|
//use selection frame
|
|
@@ -9351,21 +9590,37 @@ var Paper = function (props) {
|
|
|
9351
9590
|
enabled: true,
|
|
9352
9591
|
keepRatio: true
|
|
9353
9592
|
},
|
|
9593
|
+
x: selectedElementAbsPosition === null || selectedElementAbsPosition === void 0 ? void 0 : selectedElementAbsPosition.x,
|
|
9594
|
+
y: selectedElementAbsPosition === null || selectedElementAbsPosition === void 0 ? void 0 : selectedElementAbsPosition.y,
|
|
9354
9595
|
width: selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.size.width,
|
|
9355
9596
|
height: selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.size.height,
|
|
9356
9597
|
//movingOffsetThreshold: ELEMENT_MOVING_OFFSET_THRESHOLD,
|
|
9357
|
-
onMove: function (
|
|
9598
|
+
onMove: function (newX, newY) {
|
|
9358
9599
|
if (!selectedElement)
|
|
9359
9600
|
return;
|
|
9360
9601
|
var oldPosition = __assign({}, selectedElement.position);
|
|
9361
|
-
var
|
|
9602
|
+
var newPosition = {
|
|
9603
|
+
x: newX,
|
|
9604
|
+
y: newY
|
|
9605
|
+
};
|
|
9606
|
+
console.info("Element ".concat(selectedElement.id, " is dragging to position ").concat(JSON.stringify(newPosition)));
|
|
9607
|
+
//Adjust position of element if it should move as a port on parent port area
|
|
9608
|
+
if (selectedElement.moveAsPortOnParent && selectedElement.parentElement) {
|
|
9609
|
+
newPosition = adjustElementPositionOnParentPortArea(selectedElement, newPosition);
|
|
9610
|
+
updateElementPosition(selectedElement, newPosition.x, newPosition.y, true);
|
|
9611
|
+
}
|
|
9612
|
+
else {
|
|
9613
|
+
updateElementPosition(selectedElement, newPosition.x, newPosition.y, false);
|
|
9614
|
+
}
|
|
9615
|
+
//let newElementPosition = updateElementPosition(selectedElement, newPosition.x, newPosition.y, true)
|
|
9362
9616
|
var indexSelectedElement = elements.findIndex(function (e) { return e.id === selectedElement.id; });
|
|
9617
|
+
console.info("Element ".concat(selectedElement.id, " is moving to relative position ").concat(JSON.stringify(selectedElement.position)));
|
|
9363
9618
|
//Set state to re-render UI with new position
|
|
9364
9619
|
setElementsInTree(function (prev) { return __spreadArray([], prev, true); });
|
|
9365
9620
|
if (props.onElementMoved) {
|
|
9366
|
-
props.onElementMoved(
|
|
9621
|
+
props.onElementMoved(selectedElement.position, selectedElement, indexSelectedElement);
|
|
9367
9622
|
}
|
|
9368
|
-
paperEventEmitter.emitElementMoved(selectedElement, oldPosition,
|
|
9623
|
+
paperEventEmitter.emitElementMoved(selectedElement, oldPosition, selectedElement.position);
|
|
9369
9624
|
setMouseDownedOnPaper(false);
|
|
9370
9625
|
},
|
|
9371
9626
|
onResize: function (width, height) {
|
|
@@ -9392,8 +9647,8 @@ var Paper = function (props) {
|
|
|
9392
9647
|
avoid causing the components using it to re-render unnecessarily
|
|
9393
9648
|
*/
|
|
9394
9649
|
var onLabelMoved = React.useCallback(function (index) {
|
|
9395
|
-
return function (
|
|
9396
|
-
handleLinkLabelMoved(
|
|
9650
|
+
return function (newX, newY, labelType) {
|
|
9651
|
+
handleLinkLabelMoved(newX, newY, index, labelType);
|
|
9397
9652
|
};
|
|
9398
9653
|
}, [handleLinkLabelMoved]);
|
|
9399
9654
|
/*
|
|
@@ -9429,7 +9684,7 @@ var Paper = function (props) {
|
|
|
9429
9684
|
var targetElement = elementsRef.current.find(function (e) { return e.id === targetElementId; });
|
|
9430
9685
|
if (!targetElement)
|
|
9431
9686
|
return;
|
|
9432
|
-
|
|
9687
|
+
logger.info("A port could have been created at position ".concat(JSON.stringify(position), " on element ").concat(targetElementId, " by linking from element ").concat(link.sourceElement.id));
|
|
9433
9688
|
if (props.onCreatingPortByLinking) {
|
|
9434
9689
|
var sourcePort = link.sourcePort, sourceElement = link.sourceElement;
|
|
9435
9690
|
//Handle create port via onCreatingPortByLinking prop
|
|
@@ -9526,9 +9781,9 @@ var Paper = function (props) {
|
|
|
9526
9781
|
//use the defined react element or the default Element component
|
|
9527
9782
|
var ReactElement = element.reactElement || Element$1;
|
|
9528
9783
|
return (React.createElement("g", { id: "group-of-element-".concat(element.id), key: element.id },
|
|
9529
|
-
React.createElement(ReactElement, { key: "element-".concat(element.id), id: element.id, height: element.size.height, width: element.size.width, x: element.position.x, y: element.position.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,
|
|
9784
|
+
React.createElement(ReactElement, { key: "element-".concat(element.id), id: element.id, ref: function (refDOM) { return element.DOM = refDOM; }, height: element.size.height, width: element.size.width, x: element.positionAnchor === exports.PositioningAnchor.Center ? element.position.x - element.size.width / 2 : element.position.x, y: element.positionAnchor === exports.PositioningAnchor.Center ? element.position.y - element.size.height / 2 : element.position.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,
|
|
9530
9785
|
// portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
|
|
9531
|
-
onMouseUpAtLinkedPortPlaceholder: handleMouseUpAtLinkedPortPlaceholder, onTextUpdated: handleElementTextChange, onManuallyTriggerRenderPort: props.onManuallyTriggerRenderPort, textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition }, element.childrenElementsInTree && element.childrenElementsInTree.map(renderElementInTree))));
|
|
9786
|
+
onMouseUpAtLinkedPortPlaceholder: handleMouseUpAtLinkedPortPlaceholder, onTextUpdated: handleElementTextChange, onManuallyTriggerRenderPort: props.onManuallyTriggerRenderPort, textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition, parentAbsolutePosition: element.parentElement ? getAbsolutePosition(element.parentElement) : undefined }, element.childrenElementsInTree && element.childrenElementsInTree.map(renderElementInTree))));
|
|
9532
9787
|
}, [handleElementClicked, handleContextMenu, handlePortMoved, handlePortMouseDown, handlePortMouseUp, handleMouseUpAtLinkedPortPlaceholder, handleElementTextChange, handleMouseUp, handleMouseMove, handleMouseLeave]);
|
|
9533
9788
|
var ElementsInTree = React.useMemo(function () {
|
|
9534
9789
|
return elementsInTree.map(function (element, index) {
|
|
@@ -9587,6 +9842,7 @@ var Editor = function (_a) {
|
|
|
9587
9842
|
var offs = [];
|
|
9588
9843
|
if (editorContext) {
|
|
9589
9844
|
offs.push(editorContext.onEditorContextUpdated(function () {
|
|
9845
|
+
logger.info("onEditorContextUpdated");
|
|
9590
9846
|
setEditorStates(editorContext);
|
|
9591
9847
|
}));
|
|
9592
9848
|
}
|
|
@@ -9683,4 +9939,37 @@ exports.RectangularFrameRC = RectangularFrame;
|
|
|
9683
9939
|
exports.ShapeWrapperRC = ShapeWrapper;
|
|
9684
9940
|
exports.Text = Text$2;
|
|
9685
9941
|
exports.TextRC = Text$1;
|
|
9942
|
+
exports.addPointToList = addPointToList;
|
|
9943
|
+
exports.calculateAngleWithOx = calculateAngleWithOx;
|
|
9944
|
+
exports.checkPointContainsPolygon = checkPointContainsPolygon;
|
|
9945
|
+
exports.checkPositionOnLine = checkPositionOnLine;
|
|
9946
|
+
exports.checkSamePosition = checkSamePosition;
|
|
9947
|
+
exports.configureLogger = configureLogger;
|
|
9948
|
+
exports.correctPortPositionInElement = correctPortPositionInElement;
|
|
9949
|
+
exports.createSmoothPathString = createSmoothPathString;
|
|
9686
9950
|
exports.default = Editor;
|
|
9951
|
+
exports.degreeToRadian = degreeToRadian;
|
|
9952
|
+
exports.diamondEdgeInsideSquare = diamondEdgeInsideSquare;
|
|
9953
|
+
exports.dist = dist;
|
|
9954
|
+
exports.findNearestPointOnSegment = findNearestPointOnSegment;
|
|
9955
|
+
exports.findNearestPosition = findNearestPosition;
|
|
9956
|
+
exports.findNearestProjectedPoint = findNearestProjectedPoint;
|
|
9957
|
+
exports.generateSubstitutePosition = generateSubstitutePosition;
|
|
9958
|
+
exports.generateUniqueId = generateUniqueId;
|
|
9959
|
+
exports.getAbsolutePosition = getAbsolutePosition;
|
|
9960
|
+
exports.getCurvePathData = getCurvePathData;
|
|
9961
|
+
exports.getElementRotationInfo = getElementRotationInfo;
|
|
9962
|
+
exports.getFirstIntersection = getFirstIntersection;
|
|
9963
|
+
exports.getFourVertexesOfBBoxFromElement = getFourVertexesOfBBoxFromElement;
|
|
9964
|
+
exports.getIntersectionPositions = getIntersectionPositions;
|
|
9965
|
+
exports.getPortAbsolutePosition = getPortAbsolutePosition;
|
|
9966
|
+
exports.getRectangleCorners = getRectangleCorners;
|
|
9967
|
+
exports.getRelativePosition = getRelativePosition;
|
|
9968
|
+
exports.getRotatedRectangleCoordinates = getRotatedRectangleCoordinates;
|
|
9969
|
+
exports.getRotatedSVGBBox = getRotatedSVGBBox;
|
|
9970
|
+
exports.getSVGBBoxOutsideTransformedParent = getSVGBBoxOutsideTransformedParent;
|
|
9971
|
+
exports.makePolygonOfElement = makePolygonOfElement;
|
|
9972
|
+
exports.pathDataToD = pathDataToD;
|
|
9973
|
+
exports.removeDuplicatePosition = removeDuplicatePosition;
|
|
9974
|
+
exports.transformAbsPositionToElementRelativePosition = transformAbsPositionToElementRelativePosition;
|
|
9975
|
+
exports.transformAbsPositionToRelativePositionInsideElement = transformAbsPositionToRelativePositionInsideElement;
|