orcasvn-react-diagrams 0.1.34 → 0.1.36
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 +628 -514
- package/dist/cjs/types/components/paper.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/EditorContext.d.ts +3 -0
- package/dist/cjs/types/utils/positionUtil.d.ts +4 -0
- package/dist/esm/index.js +629 -515
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/paper.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/EditorContext.d.ts +3 -0
- package/dist/esm/types/utils/positionUtil.d.ts +4 -0
- package/dist/index.d.ts +8 -3
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -837,6 +837,9 @@ var EditorContext = /** @class */ (function () {
|
|
|
837
837
|
get: function () {
|
|
838
838
|
return this._elements;
|
|
839
839
|
},
|
|
840
|
+
set: function (value) {
|
|
841
|
+
this._elements = value;
|
|
842
|
+
},
|
|
840
843
|
enumerable: false,
|
|
841
844
|
configurable: true
|
|
842
845
|
});
|
|
@@ -844,6 +847,9 @@ var EditorContext = /** @class */ (function () {
|
|
|
844
847
|
get: function () {
|
|
845
848
|
return this._links;
|
|
846
849
|
},
|
|
850
|
+
set: function (value) {
|
|
851
|
+
this._links = value;
|
|
852
|
+
},
|
|
847
853
|
enumerable: false,
|
|
848
854
|
configurable: true
|
|
849
855
|
});
|
|
@@ -851,6 +857,9 @@ var EditorContext = /** @class */ (function () {
|
|
|
851
857
|
get: function () {
|
|
852
858
|
return this._texts;
|
|
853
859
|
},
|
|
860
|
+
set: function (value) {
|
|
861
|
+
this._texts = value;
|
|
862
|
+
},
|
|
854
863
|
enumerable: false,
|
|
855
864
|
configurable: true
|
|
856
865
|
});
|
|
@@ -858,6 +867,10 @@ var EditorContext = /** @class */ (function () {
|
|
|
858
867
|
return this._elements.find(function (e) { return e.id === elementId; });
|
|
859
868
|
};
|
|
860
869
|
EditorContext.prototype.addElement = function (element) {
|
|
870
|
+
//check if element with the same id already exists
|
|
871
|
+
if (this._elements.find(function (e) { return e.id === element.id; })) {
|
|
872
|
+
throw new Error("Element with id ".concat(element.id, " already exists"));
|
|
873
|
+
}
|
|
861
874
|
this._elements = __spreadArray(__spreadArray([], this._elements, true), [element], false);
|
|
862
875
|
this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
|
|
863
876
|
};
|
|
@@ -869,6 +882,10 @@ var EditorContext = /** @class */ (function () {
|
|
|
869
882
|
return this._links.find(function (l) { return l.id === linkId; });
|
|
870
883
|
};
|
|
871
884
|
EditorContext.prototype.addLink = function (link) {
|
|
885
|
+
//check if link with the same id already exists
|
|
886
|
+
if (this._links.find(function (l) { return l.id === link.id; })) {
|
|
887
|
+
throw new Error("Link with id ".concat(link.id, " already exists"));
|
|
888
|
+
}
|
|
872
889
|
this._links = __spreadArray(__spreadArray([], this._links, true), [link], false);
|
|
873
890
|
this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
|
|
874
891
|
};
|
|
@@ -880,6 +897,10 @@ var EditorContext = /** @class */ (function () {
|
|
|
880
897
|
return this._texts.find(function (t) { return t.id === textId; });
|
|
881
898
|
};
|
|
882
899
|
EditorContext.prototype.addText = function (text) {
|
|
900
|
+
//check if text with the same id already exists
|
|
901
|
+
if (this._texts.find(function (t) { return t.id === text.id; })) {
|
|
902
|
+
throw new Error("Text with id ".concat(text.id, " already exists"));
|
|
903
|
+
}
|
|
883
904
|
this._texts = __spreadArray(__spreadArray([], this._texts, true), [text], false);
|
|
884
905
|
this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
|
|
885
906
|
};
|
|
@@ -1171,80 +1192,87 @@ var LINK_TARGET_LABEL_POSITION_FROM_TARGET_PORT = { x: 15, y: 15 };
|
|
|
1171
1192
|
var LINK_LABEL_POSITION_FROM_LINK_MID_POINT = { x: 0, y: 40 };
|
|
1172
1193
|
var PORT_LABEL_POSITION = { x: 15, y: 0 };
|
|
1173
1194
|
var TEXT_FONT_SIZE = 12;
|
|
1174
|
-
var TEXT_MOVING_OFFSET_THRESHOLD = 10;
|
|
1175
1195
|
//PORT
|
|
1176
1196
|
var PORT_PLACEHOLDER_DEFAULT_SIZE = 8;
|
|
1177
1197
|
var PORT_PLACEHOLDER_DEFAULT_STROKE = 'green';
|
|
1178
1198
|
var PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH = 20;
|
|
1179
|
-
var PORT_MOVING_OFFSET_THRESHOLD = 15;
|
|
1180
1199
|
var PORT_DEFAULT_SIZE = 20;
|
|
1181
1200
|
|
|
1182
1201
|
var SelectionFrame = function (props) {
|
|
1183
|
-
var _a;
|
|
1184
|
-
var
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
var
|
|
1188
|
-
var
|
|
1189
|
-
var
|
|
1202
|
+
var _a, _b;
|
|
1203
|
+
var propTargetSVGElement = props.targetSVGElement, propWidth = props.width, propHeight = props.height, propFramePadding = props.framePadding,
|
|
1204
|
+
// movingOffsetThreshold: propMovingOffsetThreshold,
|
|
1205
|
+
propMovingRate = props.movingRate, propOnMove = props.onMove, propContainer = props.container, propResizability = props.resizability, propOnResize = props.onResize, PropDragDropHandlerElement = props.dragDropHandlerElement, propStrokeWidth = props.strokeWidth, propAnchor = props.anchor;
|
|
1206
|
+
var bbox = propTargetSVGElement === null || propTargetSVGElement === void 0 ? void 0 : propTargetSVGElement.getBBox();
|
|
1207
|
+
var _c = React.useState(propWidth || (bbox === null || bbox === void 0 ? void 0 : bbox.width) || MIN_ELEMENT_SIZE), width = _c[0], setWidth = _c[1];
|
|
1208
|
+
var _d = React.useState(propHeight || (bbox === null || bbox === void 0 ? void 0 : bbox.height) || MIN_ELEMENT_SIZE), height = _d[0], setHeight = _d[1];
|
|
1209
|
+
var _e = React.useState((_a = props.x) !== null && _a !== void 0 ? _a : 0), x = _e[0], setX = _e[1];
|
|
1210
|
+
var _f = React.useState((_b = props.y) !== null && _b !== void 0 ? _b : 0), y = _f[0], setY = _f[1];
|
|
1211
|
+
var framePadding = propFramePadding || 0;
|
|
1190
1212
|
var r = 5;
|
|
1191
|
-
var
|
|
1192
|
-
var
|
|
1193
|
-
var
|
|
1194
|
-
var
|
|
1195
|
-
var
|
|
1213
|
+
var _g = React.useState(false), draggingRect = _g[0], setDraggingRect = _g[1];
|
|
1214
|
+
var _h = React.useState(false), draggingCircle = _h[0], setDraggingCircle = _h[1];
|
|
1215
|
+
var _j = React.useState(0), startX = _j[0], setStartX = _j[1];
|
|
1216
|
+
var _k = React.useState(0), startY = _k[0], setStartY = _k[1];
|
|
1217
|
+
var _l = React.useState(0), xFromMouse = _l[0], setXFromMouse = _l[1];
|
|
1218
|
+
var _m = React.useState(0), yFromMouse = _m[0], setYFromMouse = _m[1];
|
|
1219
|
+
var _o = React.useState(0), lastMoveTime = _o[0], setLastMoveTime = _o[1];
|
|
1220
|
+
var getMousePosition = function (event) {
|
|
1221
|
+
var elementBounding = propContainer.getBoundingClientRect();
|
|
1222
|
+
//Coordinates of mouse on paper.
|
|
1223
|
+
var mousePosition = {
|
|
1224
|
+
x: event.clientX - elementBounding.left,
|
|
1225
|
+
y: event.clientY - elementBounding.top
|
|
1226
|
+
};
|
|
1227
|
+
return mousePosition;
|
|
1228
|
+
};
|
|
1196
1229
|
var addRectHandleMouseDown = function (event) {
|
|
1197
1230
|
event.stopPropagation();
|
|
1198
1231
|
if (!draggingCircle) {
|
|
1199
|
-
//mouse down on rect
|
|
1200
1232
|
setDraggingRect(true);
|
|
1201
1233
|
setStartX(event.clientX);
|
|
1202
1234
|
setStartY(event.clientY);
|
|
1235
|
+
var mousePosition = getMousePosition(event);
|
|
1236
|
+
var xFromMouse_1 = x - mousePosition.x;
|
|
1237
|
+
var yFromMouse_1 = y - mousePosition.y;
|
|
1238
|
+
setXFromMouse(xFromMouse_1);
|
|
1239
|
+
setYFromMouse(yFromMouse_1);
|
|
1203
1240
|
}
|
|
1204
1241
|
};
|
|
1205
1242
|
var rectHandleMouseMove = React.useCallback(function (event) {
|
|
1206
1243
|
var mouseEvent = event;
|
|
1207
1244
|
if (draggingRect) {
|
|
1208
|
-
|
|
1209
|
-
var
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
return;
|
|
1218
|
-
}
|
|
1219
|
-
// console.info('Selection frame moved by: ', offsetX, offsetY);
|
|
1220
|
-
if (props.onMove) {
|
|
1221
|
-
props.onMove(offsetX, offsetY);
|
|
1245
|
+
//Coordinates of mouse on paper.
|
|
1246
|
+
var mousePosition = getMousePosition(mouseEvent);
|
|
1247
|
+
var newX = mousePosition.x + xFromMouse;
|
|
1248
|
+
var newY = mousePosition.y + yFromMouse;
|
|
1249
|
+
if (propOnMove) {
|
|
1250
|
+
console.log('newX', newX, 'newY', newY);
|
|
1251
|
+
setX(newX);
|
|
1252
|
+
setY(newY);
|
|
1253
|
+
propOnMove(newX, newY);
|
|
1222
1254
|
setLastMoveTime(Date.now());
|
|
1223
1255
|
setStartX(mouseEvent.clientX);
|
|
1224
1256
|
setStartY(mouseEvent.clientY);
|
|
1225
1257
|
}
|
|
1226
1258
|
}
|
|
1227
|
-
}, [draggingRect,
|
|
1259
|
+
}, [draggingRect, propOnMove, propMovingRate, startX, startY, lastMoveTime, xFromMouse, yFromMouse]);
|
|
1228
1260
|
React.useEffect(function () {
|
|
1229
1261
|
var addRectHandleMouseUp = function () {
|
|
1230
|
-
//mouse up
|
|
1231
1262
|
setDraggingRect(false);
|
|
1263
|
+
setXFromMouse(0);
|
|
1264
|
+
setYFromMouse(0);
|
|
1232
1265
|
};
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
var container = props.container;
|
|
1236
|
-
//add event listeners
|
|
1237
|
-
container === null || container === void 0 ? void 0 : container.addEventListener('mousemove', rectHandleMouseMove);
|
|
1238
|
-
container === null || container === void 0 ? void 0 : container.addEventListener('mouseup', addRectHandleMouseUp);
|
|
1266
|
+
propContainer === null || propContainer === void 0 ? void 0 : propContainer.addEventListener('mousemove', rectHandleMouseMove);
|
|
1267
|
+
propContainer === null || propContainer === void 0 ? void 0 : propContainer.addEventListener('mouseup', addRectHandleMouseUp);
|
|
1239
1268
|
return function () {
|
|
1240
|
-
|
|
1241
|
-
|
|
1269
|
+
propContainer === null || propContainer === void 0 ? void 0 : propContainer.removeEventListener('mousemove', rectHandleMouseMove);
|
|
1270
|
+
propContainer === null || propContainer === void 0 ? void 0 : propContainer.removeEventListener('mouseup', addRectHandleMouseUp);
|
|
1242
1271
|
};
|
|
1243
|
-
}, [
|
|
1272
|
+
}, [propContainer, rectHandleMouseMove]);
|
|
1244
1273
|
var circleHandleMouseDown = function (event) {
|
|
1245
1274
|
event.stopPropagation();
|
|
1246
1275
|
if (!draggingRect) {
|
|
1247
|
-
// mouse down on resizing circle
|
|
1248
1276
|
setStartX(event.clientX);
|
|
1249
1277
|
setStartY(event.clientY);
|
|
1250
1278
|
setDraggingCircle(true);
|
|
@@ -1256,7 +1284,7 @@ var SelectionFrame = function (props) {
|
|
|
1256
1284
|
if (draggingCircle) {
|
|
1257
1285
|
var offsetX = mouseEvent.clientX - startX;
|
|
1258
1286
|
var offsetY = mouseEvent.clientY - startY;
|
|
1259
|
-
if (Date.now() - lastMoveTime < (
|
|
1287
|
+
if (Date.now() - lastMoveTime < (propMovingRate || 0)) {
|
|
1260
1288
|
return;
|
|
1261
1289
|
}
|
|
1262
1290
|
setStartX(mouseEvent.clientX);
|
|
@@ -1264,7 +1292,7 @@ var SelectionFrame = function (props) {
|
|
|
1264
1292
|
setLastMoveTime(Date.now());
|
|
1265
1293
|
var newWidth = width;
|
|
1266
1294
|
var newHeight = height;
|
|
1267
|
-
if (
|
|
1295
|
+
if (propResizability.keepRatio) {
|
|
1268
1296
|
var resizingRatio = Math.abs(offsetX) > Math.abs(offsetY) ? (Math.abs(offsetX) / width) : (Math.abs(offsetY) / height);
|
|
1269
1297
|
var increasing = Math.abs(offsetX) > Math.abs(offsetY) ? offsetX > 0 : offsetY > 0;
|
|
1270
1298
|
offsetX = increasing ? resizingRatio * width : -resizingRatio * width;
|
|
@@ -1280,36 +1308,33 @@ var SelectionFrame = function (props) {
|
|
|
1280
1308
|
}
|
|
1281
1309
|
setWidth(newWidth);
|
|
1282
1310
|
setHeight(newHeight);
|
|
1283
|
-
if (
|
|
1284
|
-
|
|
1311
|
+
if (propOnResize) {
|
|
1312
|
+
propOnResize(newWidth, newHeight);
|
|
1285
1313
|
}
|
|
1286
|
-
//}
|
|
1287
1314
|
}
|
|
1288
1315
|
};
|
|
1289
1316
|
var circleHandleMouseUp = function () {
|
|
1290
1317
|
setDraggingCircle(false);
|
|
1291
1318
|
};
|
|
1292
|
-
|
|
1293
|
-
//const container = typeof props.container === 'string' ? document.querySelector(props.container) : props.container;
|
|
1294
|
-
var container = props.container;
|
|
1319
|
+
var container = propContainer;
|
|
1295
1320
|
container.addEventListener('mousemove', circleHandleMouseMove);
|
|
1296
1321
|
container.addEventListener('mouseup', circleHandleMouseUp);
|
|
1297
1322
|
return function () {
|
|
1298
1323
|
container.removeEventListener('mousemove', circleHandleMouseMove);
|
|
1299
1324
|
container.removeEventListener('mouseup', circleHandleMouseUp);
|
|
1300
1325
|
};
|
|
1301
|
-
}, [draggingCircle,
|
|
1326
|
+
}, [draggingCircle, width, height, lastMoveTime, propContainer, propMovingRate, propOnResize, propResizability, startX, startY]);
|
|
1302
1327
|
var rectangleSize = Math.max(width, height);
|
|
1303
1328
|
var leftX = framePadding;
|
|
1304
1329
|
var topY = framePadding;
|
|
1305
|
-
if (
|
|
1330
|
+
if (propAnchor === exports.PositioningAnchor.Center) {
|
|
1306
1331
|
leftX -= rectangleSize / 2;
|
|
1307
1332
|
topY -= rectangleSize / 2;
|
|
1308
1333
|
}
|
|
1309
1334
|
return (React.createElement(React.Fragment, null,
|
|
1310
|
-
|
|
1311
|
-
React.createElement("rect", { vectorEffect: "non-scaling-stroke", x: leftX, y: topY, width: width, height: height, fill: 'none', stroke: 'blue', strokeWidth:
|
|
1312
|
-
|
|
1335
|
+
PropDragDropHandlerElement && React.createElement(PropDragDropHandlerElement, { dragging: draggingRect, onMouseDown: addRectHandleMouseDown }),
|
|
1336
|
+
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 }),
|
|
1337
|
+
propResizability.enabled ?
|
|
1313
1338
|
(React.createElement("circle", { cursor: 'se-resize', cx: leftX + width, cy: topY + height, r: r, fill: 'blue', stroke: 'blue', onMouseDown: circleHandleMouseDown })) : null));
|
|
1314
1339
|
};
|
|
1315
1340
|
|
|
@@ -1579,9 +1604,17 @@ var paperEventEmitterContext = React.createContext({
|
|
|
1579
1604
|
});
|
|
1580
1605
|
|
|
1581
1606
|
var Text = React.forwardRef(function (_a, ref) {
|
|
1582
|
-
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;
|
|
1607
|
+
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;
|
|
1608
|
+
console.log(content, x, y, parentAbsolutePosition);
|
|
1583
1609
|
var _c = React.useState(false), isSelected = _c[0], setIsSelected = _c[1];
|
|
1584
1610
|
var _d = React.useState(false), isEditing = _d[0], setIsEditing = _d[1];
|
|
1611
|
+
var absolutePosition = React.useMemo(function () {
|
|
1612
|
+
var _a, _b;
|
|
1613
|
+
return {
|
|
1614
|
+
x: ((_a = parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.x) !== null && _a !== void 0 ? _a : 0) + x,
|
|
1615
|
+
y: ((_b = parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.y) !== null && _b !== void 0 ? _b : 0) + y,
|
|
1616
|
+
};
|
|
1617
|
+
}, [x, y, parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.x, parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.y]);
|
|
1585
1618
|
var svgRef = React.useRef();
|
|
1586
1619
|
var _e = React.useContext(paperEventEmitterContext), onPaperClicked = _e.onPaperClicked, emitTextSelected = _e.emitTextSelected, onPortSelected = _e.onPortSelected, onElementSelected = _e.onElementSelected, onTextSelected = _e.onTextSelected;
|
|
1587
1620
|
React.useEffect(function () {
|
|
@@ -1617,7 +1650,7 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1617
1650
|
//Handle click on svg element
|
|
1618
1651
|
var handleClick = function (ev) {
|
|
1619
1652
|
ev.stopPropagation();
|
|
1620
|
-
var position =
|
|
1653
|
+
var position = {
|
|
1621
1654
|
x: x,
|
|
1622
1655
|
y: y,
|
|
1623
1656
|
};
|
|
@@ -1641,6 +1674,8 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1641
1674
|
onContentChanged === null || onContentChanged === void 0 ? void 0 : onContentChanged(ev, ev.target.value);
|
|
1642
1675
|
};
|
|
1643
1676
|
useSelectionFrame({
|
|
1677
|
+
x: absolutePosition === null || absolutePosition === void 0 ? void 0 : absolutePosition.x,
|
|
1678
|
+
y: absolutePosition === null || absolutePosition === void 0 ? void 0 : absolutePosition.y,
|
|
1644
1679
|
container: container,
|
|
1645
1680
|
targetSVGElement: (isSelected && svgRef.current) ? svgRef.current : undefined,
|
|
1646
1681
|
resizability: {
|
|
@@ -1650,7 +1685,6 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1650
1685
|
onMove: onMoved,
|
|
1651
1686
|
onResize: onResized,
|
|
1652
1687
|
strokeWidth: 3,
|
|
1653
|
-
movingOffsetThreshold: TEXT_MOVING_OFFSET_THRESHOLD,
|
|
1654
1688
|
});
|
|
1655
1689
|
var textAlign = React.useMemo(function () {
|
|
1656
1690
|
switch (align) {
|
|
@@ -1710,217 +1744,6 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1710
1744
|
});
|
|
1711
1745
|
var Text$1 = React.memo(Text);
|
|
1712
1746
|
|
|
1713
|
-
var Port1 = React.forwardRef(function (props, ref) {
|
|
1714
|
-
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,
|
|
1715
|
-
// onManuallyTriggerRenderHandler,
|
|
1716
|
-
renderShape = props.renderShape;
|
|
1717
|
-
var _a = React.useState(false); _a[0]; _a[1];
|
|
1718
|
-
var textRef = React.useRef(null);
|
|
1719
|
-
// useEffect(() => {
|
|
1720
|
-
// const off = onManuallyTriggerRenderHandler?.(() => {
|
|
1721
|
-
// setUpdated(prev => !prev);
|
|
1722
|
-
// });
|
|
1723
|
-
// return () => {
|
|
1724
|
-
// off?.();
|
|
1725
|
-
// }
|
|
1726
|
-
// }, [])
|
|
1727
|
-
var rotationAngle = React.useMemo(function () {
|
|
1728
|
-
if (!calculateRotationAngle)
|
|
1729
|
-
return 0;
|
|
1730
|
-
return calculateRotationAngle(x, y);
|
|
1731
|
-
}, [calculateRotationAngle, x, y]);
|
|
1732
|
-
React.useEffect(function () {
|
|
1733
|
-
console.info('Testing - rendering Port ' + id);
|
|
1734
|
-
});
|
|
1735
|
-
var renderLabel = function (label) {
|
|
1736
|
-
var content = label.content, size = label.size;
|
|
1737
|
-
var position = label.position || PORT_LABEL_POSITION;
|
|
1738
|
-
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); } });
|
|
1739
|
-
};
|
|
1740
|
-
var renderedShape = React.useMemo(function () {
|
|
1741
|
-
if (renderShape) {
|
|
1742
|
-
var RenderShape = renderShape;
|
|
1743
|
-
return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
|
|
1744
|
-
}
|
|
1745
|
-
else {
|
|
1746
|
-
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" });
|
|
1747
|
-
}
|
|
1748
|
-
}, [props]);
|
|
1749
|
-
return (React.createElement(React.Fragment, null,
|
|
1750
|
-
renderedShape,
|
|
1751
|
-
label && renderLabel(label)));
|
|
1752
|
-
});
|
|
1753
|
-
var Port = React.memo(Port1);
|
|
1754
|
-
|
|
1755
|
-
// Render the svg <path> element
|
|
1756
|
-
function getCurvePathData(points, smoothing, closed) {
|
|
1757
|
-
if (smoothing === void 0) { smoothing = 0.2; }
|
|
1758
|
-
// Properties of a line
|
|
1759
|
-
var line = function (pointA, pointB) {
|
|
1760
|
-
var lengthX = pointB.x - pointA.x;
|
|
1761
|
-
var lengthY = pointB.y - pointA.y;
|
|
1762
|
-
return {
|
|
1763
|
-
length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)),
|
|
1764
|
-
angle: Math.atan2(lengthY, lengthX)
|
|
1765
|
-
};
|
|
1766
|
-
};
|
|
1767
|
-
// Position of a control point
|
|
1768
|
-
var controlPoint = function (current, previous, next, reverse) {
|
|
1769
|
-
var p = previous || current;
|
|
1770
|
-
var n = next || current;
|
|
1771
|
-
var o = line(p, n);
|
|
1772
|
-
var angle = o.angle + (reverse ? Math.PI : 0);
|
|
1773
|
-
var length = o.length * smoothing;
|
|
1774
|
-
var x = current.x + Math.cos(angle) * length;
|
|
1775
|
-
var y = current.y + Math.sin(angle) * length;
|
|
1776
|
-
return { x: x, y: y };
|
|
1777
|
-
};
|
|
1778
|
-
var pathData = [];
|
|
1779
|
-
pathData.push({ type: "M", values: [points[0].x, points[0].y] });
|
|
1780
|
-
for (var i = 1; i < points.length; i++) {
|
|
1781
|
-
var point = points[i];
|
|
1782
|
-
var cp1 = controlPoint(points[i - 1], points[i - 2], point);
|
|
1783
|
-
var cp2 = controlPoint(point, points[i - 1], points[i + 1], true);
|
|
1784
|
-
var command = {
|
|
1785
|
-
type: "C",
|
|
1786
|
-
values: [cp1.x, cp1.y, cp2.x, cp2.y, point.x, point.y]
|
|
1787
|
-
};
|
|
1788
|
-
pathData.push(command);
|
|
1789
|
-
}
|
|
1790
|
-
return pathData;
|
|
1791
|
-
}
|
|
1792
|
-
// convert pathdata to d attribute string
|
|
1793
|
-
function pathDataToD(pathData, decimals) {
|
|
1794
|
-
if (decimals === void 0) { decimals = 3; }
|
|
1795
|
-
var d = pathData
|
|
1796
|
-
.map(function (com) {
|
|
1797
|
-
return "".concat(com.type).concat(com.values.map(function (value) { return +value.toFixed(decimals); }).join(" "));
|
|
1798
|
-
})
|
|
1799
|
-
.join(" ");
|
|
1800
|
-
return d;
|
|
1801
|
-
}
|
|
1802
|
-
function createSmoothPathString(points, smoothing, close) {
|
|
1803
|
-
var pathData = getCurvePathData(points, smoothing);
|
|
1804
|
-
var pathString = pathDataToD(pathData);
|
|
1805
|
-
return pathString;
|
|
1806
|
-
}
|
|
1807
|
-
// a helper function to measure the distance between 2 points
|
|
1808
|
-
function dist(p1, p2) {
|
|
1809
|
-
var dx = p2.x - p1.x;
|
|
1810
|
-
var dy = p2.y - p1.y;
|
|
1811
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
1812
|
-
}
|
|
1813
|
-
//find distance from starting point of path to a point
|
|
1814
|
-
function getLengthForPoint(p, thePath, precision) {
|
|
1815
|
-
if (precision === void 0) { precision = 50; }
|
|
1816
|
-
var pathLength = thePath.getTotalLength();
|
|
1817
|
-
var theRecord = pathLength; //length of path
|
|
1818
|
-
var division = pathLength / precision;
|
|
1819
|
-
var theSegment;
|
|
1820
|
-
for (var i = 0; i < precision; i++) {
|
|
1821
|
-
// get a point on the path for thia distance
|
|
1822
|
-
var _p = thePath.getPointAtLength(i * division);
|
|
1823
|
-
// get the distance between the new point _p and the point p
|
|
1824
|
-
var theDistance = dist(_p, p);
|
|
1825
|
-
if (theDistance < theRecord) {
|
|
1826
|
-
// if the distance is smaller than the record set the new record
|
|
1827
|
-
theRecord = theDistance;
|
|
1828
|
-
theSegment = i;
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
return (theSegment * division);
|
|
1832
|
-
}
|
|
1833
|
-
//Add points to the list of points in the correct position
|
|
1834
|
-
function addPointToList(point, listPoints, path) {
|
|
1835
|
-
var getAddIndex = function (startIndex, endIndex) {
|
|
1836
|
-
//Add in the middle if there are only 2 points
|
|
1837
|
-
if ((endIndex - startIndex) === 1) {
|
|
1838
|
-
return startIndex + 1;
|
|
1839
|
-
}
|
|
1840
|
-
var middleIndex = Math.ceil((startIndex + endIndex) / 2);
|
|
1841
|
-
var lengthOfMiddlePoint = getLengthForPoint(listPoints[middleIndex], path); //distance from start point to mid point
|
|
1842
|
-
var lengthOfAddedPoint = getLengthForPoint(point, path); //distance from adding point to mid point
|
|
1843
|
-
//compare if lengthOfMiddlePoint is less than lengthOfAddedPoint,
|
|
1844
|
-
//then new point can be added in the range of mid point to end point,
|
|
1845
|
-
//otherwise it can be added in the range of start point to middle point.
|
|
1846
|
-
if (lengthOfAddedPoint < lengthOfMiddlePoint) {
|
|
1847
|
-
return getAddIndex(startIndex, middleIndex);
|
|
1848
|
-
}
|
|
1849
|
-
else {
|
|
1850
|
-
return getAddIndex(middleIndex, endIndex);
|
|
1851
|
-
}
|
|
1852
|
-
};
|
|
1853
|
-
var addedIndex = getAddIndex(0, listPoints.length - 1);
|
|
1854
|
-
listPoints.splice(addedIndex, 0, point);
|
|
1855
|
-
return __spreadArray([], listPoints, true);
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
// const topLeftOffsetOfSquareHoldingRect = (x: number, y: number, rectWidth: number, rectHeight: number, rotation?: number): IPosition => {
|
|
1859
|
-
// rotation = rotation || 0;
|
|
1860
|
-
// const rotationInRadians = rotation * Math.PI / 180;
|
|
1861
|
-
// //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
|
|
1862
|
-
// //calculate a1 equal sin of rotation * height
|
|
1863
|
-
// const a1 = Math.abs(Math.sin(rotationInRadians) * rectHeight);
|
|
1864
|
-
// //calculate a2 equal cos of rotation * width
|
|
1865
|
-
// const a2 = Math.abs(Math.cos(rotationInRadians) * rectWidth);
|
|
1866
|
-
// const a = a1 + a2;
|
|
1867
|
-
// console.info(`a1: ${a1}, a2: ${a2}, a: ${a}`);
|
|
1868
|
-
// //calculate b1 equal cos of rotation * height
|
|
1869
|
-
// const b1 = Math.abs(Math.cos(rotationInRadians) * rectHeight);
|
|
1870
|
-
// //calculate b2 equal sin of rotation * width
|
|
1871
|
-
// const b2 = Math.abs(Math.sin(rotationInRadians) * rectWidth);
|
|
1872
|
-
// const b = b1 + b2;
|
|
1873
|
-
// console.info(`b1: ${b1}, b2: ${b2}, b: ${b}`);
|
|
1874
|
-
// //const squareEdge = Math.max(rectWidth, rectHeight);
|
|
1875
|
-
// return {x, y};
|
|
1876
|
-
// return { x: x - (b - rectWidth) / 2, y: y - (a - rectHeight) / 2 };
|
|
1877
|
-
// }
|
|
1878
|
-
function degreeToRadian(degree) {
|
|
1879
|
-
return degree * (Math.PI / 180);
|
|
1880
|
-
}
|
|
1881
|
-
//rotate the four vertices of the rectangle
|
|
1882
|
-
function getRotatedRectangleCoordinates(actualPoints, centerX, centerY, angle) {
|
|
1883
|
-
var coordinatesAfterRotation = [];
|
|
1884
|
-
for (var i = 0; i < 4; i++) {
|
|
1885
|
-
var point = actualPoints[i];
|
|
1886
|
-
var tempX = point.x - centerX;
|
|
1887
|
-
var tempY = point.y - centerY;
|
|
1888
|
-
var rotatedX = tempX * Math.cos(degreeToRadian(angle)) - tempY * Math.sin(degreeToRadian(angle));
|
|
1889
|
-
var rotatedY = tempX * Math.sin(degreeToRadian(angle)) + tempY * Math.cos(degreeToRadian(angle));
|
|
1890
|
-
point.x = rotatedX + centerX;
|
|
1891
|
-
point.y = rotatedY + centerY;
|
|
1892
|
-
coordinatesAfterRotation.push({ x: point.x, y: point.y });
|
|
1893
|
-
}
|
|
1894
|
-
return coordinatesAfterRotation;
|
|
1895
|
-
}
|
|
1896
|
-
//Calculate the angle between 2 points relative to the OX axis
|
|
1897
|
-
function calculateAngleWithOx(pStart, pEnd) {
|
|
1898
|
-
var deltaX = pEnd.x - pStart.x;
|
|
1899
|
-
var deltaY = pEnd.y - pStart.y;
|
|
1900
|
-
// Calculate the angle in radians
|
|
1901
|
-
var angleInRadians = Math.atan2(deltaY, deltaX);
|
|
1902
|
-
// Convert to degrees (optional)
|
|
1903
|
-
var angleInDegrees = angleInRadians * (180 / Math.PI);
|
|
1904
|
-
// Ensure the angle is positive (optional, depending on use case)
|
|
1905
|
-
if (angleInDegrees < 0) {
|
|
1906
|
-
angleInDegrees += 360;
|
|
1907
|
-
}
|
|
1908
|
-
return angleInDegrees;
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
//Defined remove icon for element link, shown when element link is selected.
|
|
1912
|
-
function CloseIcon(_a) {
|
|
1913
|
-
var onClick = _a.onClick;
|
|
1914
|
-
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' },
|
|
1915
|
-
React.createElement("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0", transform: "translate(3.84,3.84), scale(0.68)" },
|
|
1916
|
-
React.createElement("rect", { x: "0", y: "0", width: "24.00", height: "24.00", rx: "12", fill: "#ffffff", strokeWidth: "0" })),
|
|
1917
|
-
React.createElement("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round", stroke: "#CCCCCC", "stroke-width": "0.048" }),
|
|
1918
|
-
React.createElement("g", { id: "SVGRepo_iconCarrier" },
|
|
1919
|
-
React.createElement("g", null,
|
|
1920
|
-
React.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
|
|
1921
|
-
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" })))));
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
1747
|
/**
|
|
1925
1748
|
* Created by Alex Bol on 2/18/2017.
|
|
1926
1749
|
*/
|
|
@@ -7751,35 +7574,265 @@ var getAbsolutePosition = function (element) {
|
|
|
7751
7574
|
x: x,
|
|
7752
7575
|
y: y,
|
|
7753
7576
|
};
|
|
7577
|
+
};
|
|
7578
|
+
var transformAbsPositionToElementRelativePosition = function (position, element) {
|
|
7579
|
+
var parentElement = element.parentElement;
|
|
7580
|
+
if (!parentElement) {
|
|
7581
|
+
return position;
|
|
7582
|
+
}
|
|
7583
|
+
var absoluteParentElement = getAbsolutePosition(parentElement);
|
|
7584
|
+
return {
|
|
7585
|
+
x: position.x - absoluteParentElement.x,
|
|
7586
|
+
y: position.y - absoluteParentElement.y,
|
|
7587
|
+
};
|
|
7588
|
+
};
|
|
7589
|
+
var transformAbsPositionToRelativePositionInsideElement = function (absolutePosition, parentAbsolutePosition) {
|
|
7590
|
+
var _a, _b;
|
|
7591
|
+
var position = {
|
|
7592
|
+
x: absolutePosition.x - ((_a = parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.x) !== null && _a !== void 0 ? _a : 0),
|
|
7593
|
+
y: absolutePosition.y - ((_b = parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.y) !== null && _b !== void 0 ? _b : 0),
|
|
7594
|
+
};
|
|
7595
|
+
return position;
|
|
7754
7596
|
};
|
|
7755
7597
|
|
|
7756
|
-
var
|
|
7757
|
-
var
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
var
|
|
7761
|
-
var
|
|
7762
|
-
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7598
|
+
var Port1 = React.forwardRef(function (props, ref) {
|
|
7599
|
+
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,
|
|
7600
|
+
// onManuallyTriggerRenderHandler,
|
|
7601
|
+
renderShape = props.renderShape;
|
|
7602
|
+
var textRef = React.useRef(null);
|
|
7603
|
+
var rotationAngle = React.useMemo(function () {
|
|
7604
|
+
if (!calculateRotationAngle)
|
|
7605
|
+
return 0;
|
|
7606
|
+
return calculateRotationAngle(x, y);
|
|
7607
|
+
}, [calculateRotationAngle, x, y]);
|
|
7608
|
+
var renderLabel = function (label) {
|
|
7609
|
+
var content = label.content, size = label.size;
|
|
7610
|
+
var position = label.position || PORT_LABEL_POSITION;
|
|
7611
|
+
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) {
|
|
7612
|
+
if (onPortLabelMoved) {
|
|
7613
|
+
var relativePosInSideEle = transformAbsPositionToRelativePositionInsideElement({ x: xOnPaper, y: yOnPaper }, parentAbsolutePosition);
|
|
7614
|
+
var newXPort = relativePosInSideEle.x - x;
|
|
7615
|
+
var newYPort = relativePosInSideEle.y - y;
|
|
7616
|
+
onPortLabelMoved(newXPort, newYPort, id);
|
|
7617
|
+
}
|
|
7618
|
+
}, 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); } });
|
|
7619
|
+
};
|
|
7620
|
+
var renderedShape = React.useMemo(function () {
|
|
7621
|
+
if (renderShape) {
|
|
7622
|
+
var RenderShape = renderShape;
|
|
7623
|
+
return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
|
|
7624
|
+
}
|
|
7625
|
+
else {
|
|
7626
|
+
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" });
|
|
7627
|
+
}
|
|
7628
|
+
}, [props]);
|
|
7629
|
+
return (React.createElement(React.Fragment, null,
|
|
7630
|
+
renderedShape,
|
|
7631
|
+
label && renderLabel(label)));
|
|
7632
|
+
});
|
|
7633
|
+
var Port = React.memo(Port1);
|
|
7634
|
+
|
|
7635
|
+
// Render the svg <path> element
|
|
7636
|
+
function getCurvePathData(points, smoothing, closed) {
|
|
7637
|
+
if (smoothing === void 0) { smoothing = 0.2; }
|
|
7638
|
+
// Properties of a line
|
|
7639
|
+
var line = function (pointA, pointB) {
|
|
7640
|
+
var lengthX = pointB.x - pointA.x;
|
|
7641
|
+
var lengthY = pointB.y - pointA.y;
|
|
7642
|
+
return {
|
|
7643
|
+
length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)),
|
|
7644
|
+
angle: Math.atan2(lengthY, lengthX)
|
|
7645
|
+
};
|
|
7646
|
+
};
|
|
7647
|
+
// Position of a control point
|
|
7648
|
+
var controlPoint = function (current, previous, next, reverse) {
|
|
7649
|
+
var p = previous || current;
|
|
7650
|
+
var n = next || current;
|
|
7651
|
+
var o = line(p, n);
|
|
7652
|
+
var angle = o.angle + (reverse ? Math.PI : 0);
|
|
7653
|
+
var length = o.length * smoothing;
|
|
7654
|
+
var x = current.x + Math.cos(angle) * length;
|
|
7655
|
+
var y = current.y + Math.sin(angle) * length;
|
|
7656
|
+
return { x: x, y: y };
|
|
7657
|
+
};
|
|
7658
|
+
var pathData = [];
|
|
7659
|
+
pathData.push({ type: "M", values: [points[0].x, points[0].y] });
|
|
7660
|
+
for (var i = 1; i < points.length; i++) {
|
|
7661
|
+
var point = points[i];
|
|
7662
|
+
var cp1 = controlPoint(points[i - 1], points[i - 2], point);
|
|
7663
|
+
var cp2 = controlPoint(point, points[i - 1], points[i + 1], true);
|
|
7664
|
+
var command = {
|
|
7665
|
+
type: "C",
|
|
7666
|
+
values: [cp1.x, cp1.y, cp2.x, cp2.y, point.x, point.y]
|
|
7667
|
+
};
|
|
7668
|
+
pathData.push(command);
|
|
7669
|
+
}
|
|
7670
|
+
return pathData;
|
|
7671
|
+
}
|
|
7672
|
+
// convert pathdata to d attribute string
|
|
7673
|
+
function pathDataToD(pathData, decimals) {
|
|
7674
|
+
if (decimals === void 0) { decimals = 3; }
|
|
7675
|
+
var d = pathData
|
|
7676
|
+
.map(function (com) {
|
|
7677
|
+
return "".concat(com.type).concat(com.values.map(function (value) { return +value.toFixed(decimals); }).join(" "));
|
|
7678
|
+
})
|
|
7679
|
+
.join(" ");
|
|
7680
|
+
return d;
|
|
7681
|
+
}
|
|
7682
|
+
function createSmoothPathString(points, smoothing, close) {
|
|
7683
|
+
var pathData = getCurvePathData(points, smoothing);
|
|
7684
|
+
var pathString = pathDataToD(pathData);
|
|
7685
|
+
return pathString;
|
|
7686
|
+
}
|
|
7687
|
+
// a helper function to measure the distance between 2 points
|
|
7688
|
+
function dist(p1, p2) {
|
|
7689
|
+
var dx = p2.x - p1.x;
|
|
7690
|
+
var dy = p2.y - p1.y;
|
|
7691
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
7692
|
+
}
|
|
7693
|
+
//find distance from starting point of path to a point
|
|
7694
|
+
function getLengthForPoint(p, thePath, precision) {
|
|
7695
|
+
if (precision === void 0) { precision = 50; }
|
|
7696
|
+
var pathLength = thePath.getTotalLength();
|
|
7697
|
+
var theRecord = pathLength; //length of path
|
|
7698
|
+
var division = pathLength / precision;
|
|
7699
|
+
var theSegment;
|
|
7700
|
+
for (var i = 0; i < precision; i++) {
|
|
7701
|
+
// get a point on the path for thia distance
|
|
7702
|
+
var _p = thePath.getPointAtLength(i * division);
|
|
7703
|
+
// get the distance between the new point _p and the point p
|
|
7704
|
+
var theDistance = dist(_p, p);
|
|
7705
|
+
if (theDistance < theRecord) {
|
|
7706
|
+
// if the distance is smaller than the record set the new record
|
|
7707
|
+
theRecord = theDistance;
|
|
7708
|
+
theSegment = i;
|
|
7709
|
+
}
|
|
7710
|
+
}
|
|
7711
|
+
return (theSegment * division);
|
|
7712
|
+
}
|
|
7713
|
+
//Add points to the list of points in the correct position
|
|
7714
|
+
function addPointToList(point, listPoints, path) {
|
|
7715
|
+
var getAddIndex = function (startIndex, endIndex) {
|
|
7716
|
+
//Add in the middle if there are only 2 points
|
|
7717
|
+
if ((endIndex - startIndex) === 1) {
|
|
7718
|
+
return startIndex + 1;
|
|
7719
|
+
}
|
|
7720
|
+
var middleIndex = Math.ceil((startIndex + endIndex) / 2);
|
|
7721
|
+
var lengthOfMiddlePoint = getLengthForPoint(listPoints[middleIndex], path); //distance from start point to mid point
|
|
7722
|
+
var lengthOfAddedPoint = getLengthForPoint(point, path); //distance from adding point to mid point
|
|
7723
|
+
//compare if lengthOfMiddlePoint is less than lengthOfAddedPoint,
|
|
7724
|
+
//then new point can be added in the range of mid point to end point,
|
|
7725
|
+
//otherwise it can be added in the range of start point to middle point.
|
|
7726
|
+
if (lengthOfAddedPoint < lengthOfMiddlePoint) {
|
|
7727
|
+
return getAddIndex(startIndex, middleIndex);
|
|
7728
|
+
}
|
|
7729
|
+
else {
|
|
7730
|
+
return getAddIndex(middleIndex, endIndex);
|
|
7731
|
+
}
|
|
7732
|
+
};
|
|
7733
|
+
var addedIndex = getAddIndex(0, listPoints.length - 1);
|
|
7734
|
+
listPoints.splice(addedIndex, 0, point);
|
|
7735
|
+
return __spreadArray([], listPoints, true);
|
|
7736
|
+
}
|
|
7737
|
+
|
|
7738
|
+
// const topLeftOffsetOfSquareHoldingRect = (x: number, y: number, rectWidth: number, rectHeight: number, rotation?: number): IPosition => {
|
|
7739
|
+
// rotation = rotation || 0;
|
|
7740
|
+
// const rotationInRadians = rotation * Math.PI / 180;
|
|
7741
|
+
// //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
|
|
7742
|
+
// //calculate a1 equal sin of rotation * height
|
|
7743
|
+
// const a1 = Math.abs(Math.sin(rotationInRadians) * rectHeight);
|
|
7744
|
+
// //calculate a2 equal cos of rotation * width
|
|
7745
|
+
// const a2 = Math.abs(Math.cos(rotationInRadians) * rectWidth);
|
|
7746
|
+
// const a = a1 + a2;
|
|
7747
|
+
// console.info(`a1: ${a1}, a2: ${a2}, a: ${a}`);
|
|
7748
|
+
// //calculate b1 equal cos of rotation * height
|
|
7749
|
+
// const b1 = Math.abs(Math.cos(rotationInRadians) * rectHeight);
|
|
7750
|
+
// //calculate b2 equal sin of rotation * width
|
|
7751
|
+
// const b2 = Math.abs(Math.sin(rotationInRadians) * rectWidth);
|
|
7752
|
+
// const b = b1 + b2;
|
|
7753
|
+
// console.info(`b1: ${b1}, b2: ${b2}, b: ${b}`);
|
|
7754
|
+
// //const squareEdge = Math.max(rectWidth, rectHeight);
|
|
7755
|
+
// return {x, y};
|
|
7756
|
+
// return { x: x - (b - rectWidth) / 2, y: y - (a - rectHeight) / 2 };
|
|
7757
|
+
// }
|
|
7758
|
+
function degreeToRadian(degree) {
|
|
7759
|
+
return degree * (Math.PI / 180);
|
|
7760
|
+
}
|
|
7761
|
+
//rotate the four vertices of the rectangle
|
|
7762
|
+
function getRotatedRectangleCoordinates(actualPoints, centerX, centerY, angle) {
|
|
7763
|
+
var coordinatesAfterRotation = [];
|
|
7764
|
+
for (var i = 0; i < 4; i++) {
|
|
7765
|
+
var point = actualPoints[i];
|
|
7766
|
+
var tempX = point.x - centerX;
|
|
7767
|
+
var tempY = point.y - centerY;
|
|
7768
|
+
var rotatedX = tempX * Math.cos(degreeToRadian(angle)) - tempY * Math.sin(degreeToRadian(angle));
|
|
7769
|
+
var rotatedY = tempX * Math.sin(degreeToRadian(angle)) + tempY * Math.cos(degreeToRadian(angle));
|
|
7770
|
+
point.x = rotatedX + centerX;
|
|
7771
|
+
point.y = rotatedY + centerY;
|
|
7772
|
+
coordinatesAfterRotation.push({ x: point.x, y: point.y });
|
|
7773
|
+
}
|
|
7774
|
+
return coordinatesAfterRotation;
|
|
7775
|
+
}
|
|
7776
|
+
//Calculate the angle between 2 points relative to the OX axis
|
|
7777
|
+
function calculateAngleWithOx(pStart, pEnd) {
|
|
7778
|
+
var deltaX = pEnd.x - pStart.x;
|
|
7779
|
+
var deltaY = pEnd.y - pStart.y;
|
|
7780
|
+
// Calculate the angle in radians
|
|
7781
|
+
var angleInRadians = Math.atan2(deltaY, deltaX);
|
|
7782
|
+
// Convert to degrees (optional)
|
|
7783
|
+
var angleInDegrees = angleInRadians * (180 / Math.PI);
|
|
7784
|
+
// Ensure the angle is positive (optional, depending on use case)
|
|
7785
|
+
if (angleInDegrees < 0) {
|
|
7786
|
+
angleInDegrees += 360;
|
|
7787
|
+
}
|
|
7788
|
+
return angleInDegrees;
|
|
7789
|
+
}
|
|
7790
|
+
|
|
7791
|
+
//Defined remove icon for element link, shown when element link is selected.
|
|
7792
|
+
function CloseIcon(_a) {
|
|
7793
|
+
var onClick = _a.onClick;
|
|
7794
|
+
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' },
|
|
7795
|
+
React.createElement("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0", transform: "translate(3.84,3.84), scale(0.68)" },
|
|
7796
|
+
React.createElement("rect", { x: "0", y: "0", width: "24.00", height: "24.00", rx: "12", fill: "#ffffff", strokeWidth: "0" })),
|
|
7797
|
+
React.createElement("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round", stroke: "#CCCCCC", "stroke-width": "0.048" }),
|
|
7798
|
+
React.createElement("g", { id: "SVGRepo_iconCarrier" },
|
|
7799
|
+
React.createElement("g", null,
|
|
7800
|
+
React.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
|
|
7801
|
+
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" })))));
|
|
7802
|
+
}
|
|
7803
|
+
|
|
7804
|
+
var makerStart = React.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
|
|
7805
|
+
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>
|
|
7806
|
+
var IElementLink = function (_a) {
|
|
7807
|
+
var _b, _c;
|
|
7808
|
+
var id = _a.id, path = _a.path, stroke = _a.stroke, _d = _a.strokeWidth, strokeWidth = _d === void 0 ? 4 : _d, pointsProp = _a.points, sourcePosition = _a.sourcePosition, targetPosition = _a.targetPosition, onPathChanged = _a.onPathChanged, onClickDelete = _a.onClickDelete, onSelected = _a.onSelected, onDeselected = _a.onDeselected, container = _a.container, _e = _a.markerStart, markerStart = _e === void 0 ? makerStart : _e, _f = _a.markerEnd, markerEnd = _f === void 0 ? makerEnd : _f, _g = _a.markerDistanceFromPort, markerDistanceFromPort = _g === void 0 ? LINK_MARKER_DISTANCE_FROM_PORT : _g, _h = _a.markerSize, markerSize = _h === void 0 ? LINK_MARKER_SIZE : _h, label = _a.label, sourceLabel = _a.sourceLabel, targetLabel = _a.targetLabel, onLabelMoved = _a.onLabelMoved, onLabelResized = _a.onLabelResized, onLabelContentChanged = _a.onLabelContentChanged;
|
|
7809
|
+
var _j = React.useState(path), pathStr = _j[0], setPathStr = _j[1];
|
|
7810
|
+
var _k = React.useState(pointsProp !== null && pointsProp !== void 0 ? pointsProp : []), points = _k[0], setPoints = _k[1];
|
|
7811
|
+
var _l = React.useState(false), isDragging = _l[0], setIsDragging = _l[1];
|
|
7812
|
+
var _m = React.useState(), draggingPointIndex = _m[0], setDraggingPointIndex = _m[1];
|
|
7813
|
+
var _o = React.useState({
|
|
7814
|
+
current: null,
|
|
7815
|
+
}), selectedLabelRef = _o[0], setSelectedLabelRef = _o[1];
|
|
7816
|
+
var _p = React.useState(false), isSelectedLink = _p[0], setIsSelectedLink = _p[1];
|
|
7817
|
+
var _q = React.useContext(paperEventEmitterContext), onPaperClicked = _q.onPaperClicked, onElementSelected = _q.onElementSelected;
|
|
7818
|
+
var pathRef = React.useRef(null);
|
|
7819
|
+
var labelRef = React.useRef(null);
|
|
7820
|
+
var sourceLabelRef = React.useRef(null);
|
|
7821
|
+
var targetLabelRef = React.useRef(null);
|
|
7822
|
+
var angleMarkerStart = '0';
|
|
7823
|
+
var angleMarkerEnd = '0';
|
|
7824
|
+
var markerStartPosition;
|
|
7825
|
+
var markerEndPosition;
|
|
7826
|
+
var centerPathPosition = undefined;
|
|
7827
|
+
React.useEffect(function () {
|
|
7828
|
+
var paperClickListener = onPaperClicked(function () {
|
|
7829
|
+
setSelectedLabelRef({
|
|
7830
|
+
current: null,
|
|
7831
|
+
});
|
|
7832
|
+
setIsSelectedLink(false);
|
|
7833
|
+
onDeselected === null || onDeselected === void 0 ? void 0 : onDeselected();
|
|
7834
|
+
});
|
|
7835
|
+
return function () {
|
|
7783
7836
|
paperClickListener.off();
|
|
7784
7837
|
};
|
|
7785
7838
|
}, []);
|
|
@@ -7887,16 +7940,22 @@ var IElementLink = function (_a) {
|
|
|
7887
7940
|
setDraggingPointIndex(_draggingPointIndex);
|
|
7888
7941
|
setPoints(pointsWithoutStartEndPoint);
|
|
7889
7942
|
};
|
|
7890
|
-
var handleLabelMoved = function (
|
|
7943
|
+
var handleLabelMoved = function (newX, newY) {
|
|
7944
|
+
if (!onLabelMoved)
|
|
7945
|
+
return;
|
|
7946
|
+
var newPosition;
|
|
7891
7947
|
switch (selectedLabelRef.current) {
|
|
7892
7948
|
case labelRef.current:
|
|
7893
|
-
|
|
7949
|
+
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY }, centerPathPosition);
|
|
7950
|
+
onLabelMoved(newPosition.x, newPosition.y, 'middle');
|
|
7894
7951
|
break;
|
|
7895
7952
|
case sourceLabelRef.current:
|
|
7896
|
-
|
|
7953
|
+
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY }, sourcePosition);
|
|
7954
|
+
onLabelMoved(newPosition.x, newPosition.y, 'source');
|
|
7897
7955
|
break;
|
|
7898
7956
|
case targetLabelRef.current:
|
|
7899
|
-
|
|
7957
|
+
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY }, targetPosition);
|
|
7958
|
+
onLabelMoved(newPosition.x, newPosition.y, 'target');
|
|
7900
7959
|
break;
|
|
7901
7960
|
}
|
|
7902
7961
|
};
|
|
@@ -7931,7 +7990,6 @@ var IElementLink = function (_a) {
|
|
|
7931
7990
|
onSelected === null || onSelected === void 0 ? void 0 : onSelected();
|
|
7932
7991
|
};
|
|
7933
7992
|
var renderLabel = function (label, labelType, relativePositionTo) {
|
|
7934
|
-
if (relativePositionTo === void 0) { relativePositionTo = { x: 0, y: 0 }; }
|
|
7935
7993
|
var content = label.content, size = label.size;
|
|
7936
7994
|
var relativePosition = label.position;
|
|
7937
7995
|
var curLabelRef;
|
|
@@ -7958,16 +8016,15 @@ var IElementLink = function (_a) {
|
|
|
7958
8016
|
throw new Error('This type of label does not exist.');
|
|
7959
8017
|
}
|
|
7960
8018
|
var position = {
|
|
7961
|
-
x: relativePosition.x
|
|
7962
|
-
y: relativePosition.y
|
|
8019
|
+
x: relativePosition.x,
|
|
8020
|
+
y: relativePosition.y,
|
|
7963
8021
|
};
|
|
8022
|
+
if (relativePositionTo) {
|
|
8023
|
+
position.x += relativePositionTo.x;
|
|
8024
|
+
position.y += relativePositionTo.y;
|
|
8025
|
+
}
|
|
7964
8026
|
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 }));
|
|
7965
8027
|
};
|
|
7966
|
-
var angleMarkerStart = '0';
|
|
7967
|
-
var angleMarkerEnd = '0';
|
|
7968
|
-
var markerStartPosition;
|
|
7969
|
-
var markerEndPosition;
|
|
7970
|
-
var centerPathPosition;
|
|
7971
8028
|
if ((_b = pathRef.current) === null || _b === void 0 ? void 0 : _b.getAttribute('d')) {
|
|
7972
8029
|
if (markerStart) {
|
|
7973
8030
|
markerStartPosition = pathRef.current.getPointAtLength(markerDistanceFromPort);
|
|
@@ -8072,7 +8129,7 @@ var getElementRotationInfo = function (element) {
|
|
|
8072
8129
|
|
|
8073
8130
|
var Element = function (props) {
|
|
8074
8131
|
var _a, _b;
|
|
8075
|
-
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;
|
|
8132
|
+
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;
|
|
8076
8133
|
var _c = React.useState(), selectedPort = _c[0], setSelectedPort = _c[1];
|
|
8077
8134
|
var _d = React.useState(), hoveredPort = _d[0], setHoveredPort = _d[1];
|
|
8078
8135
|
var _e = React.useState([]), ports = _e[0], setPorts = _e[1];
|
|
@@ -8082,22 +8139,24 @@ var Element = function (props) {
|
|
|
8082
8139
|
var elementRef = React.useRef(null);
|
|
8083
8140
|
var elementLinkStarted = React.useRef();
|
|
8084
8141
|
var portsRef = React.useRef(ports);
|
|
8085
|
-
React.
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
return function () {
|
|
8090
|
-
var _a;
|
|
8091
|
-
console.log('un mount', (_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content);
|
|
8142
|
+
var getElementAbsPosition = React.useCallback(function () {
|
|
8143
|
+
var position = {
|
|
8144
|
+
x: x,
|
|
8145
|
+
y: y,
|
|
8092
8146
|
};
|
|
8093
|
-
|
|
8147
|
+
if (parentAbsolutePosition) {
|
|
8148
|
+
position.x += parentAbsolutePosition.x;
|
|
8149
|
+
position.y += parentAbsolutePosition.y;
|
|
8150
|
+
}
|
|
8151
|
+
return position;
|
|
8152
|
+
}, [x, y, parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.x, parentAbsolutePosition === null || parentAbsolutePosition === void 0 ? void 0 : parentAbsolutePosition.y]);
|
|
8153
|
+
var elementAbsPosition = React.useMemo(function () { return getElementAbsPosition(); }, [getElementAbsPosition]);
|
|
8094
8154
|
//Listen to manually trigger render event
|
|
8095
8155
|
React.useEffect(function () {
|
|
8096
8156
|
var _a;
|
|
8097
8157
|
var off = (_a = props.onManuallyTriggerRenderPort) === null || _a === void 0 ? void 0 : _a.call(props, function (portId, elementId) {
|
|
8098
8158
|
if (elementId !== id)
|
|
8099
8159
|
return;
|
|
8100
|
-
console.log('onManuallyTriggerRenderPort', id);
|
|
8101
8160
|
setPorts(function (prev) { return __spreadArray([], prev, true); });
|
|
8102
8161
|
});
|
|
8103
8162
|
return function () {
|
|
@@ -8108,13 +8167,8 @@ var Element = function (props) {
|
|
|
8108
8167
|
React.useEffect(function () {
|
|
8109
8168
|
portsRef.current = ports;
|
|
8110
8169
|
}, [ports]);
|
|
8111
|
-
React.useEffect(function () {
|
|
8112
|
-
var _a;
|
|
8113
|
-
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);
|
|
8114
|
-
});
|
|
8115
8170
|
//Listen a new port is created, after add new port to ports state
|
|
8116
8171
|
React.useEffect(function () {
|
|
8117
|
-
console.info('Ports changed', props.ports);
|
|
8118
8172
|
setPorts(function (prev) {
|
|
8119
8173
|
var _a, _b;
|
|
8120
8174
|
return (_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p, index) {
|
|
@@ -8312,11 +8366,14 @@ var Element = function (props) {
|
|
|
8312
8366
|
}
|
|
8313
8367
|
return newPosition || tempNewPosition;
|
|
8314
8368
|
};
|
|
8315
|
-
var handlePortMove = function (
|
|
8369
|
+
var handlePortMove = function (newX, newY) {
|
|
8316
8370
|
if (!selectedPort)
|
|
8317
8371
|
return;
|
|
8318
8372
|
var oldPosition = __assign({}, selectedPort.position);
|
|
8319
|
-
var tempNewPosition = {
|
|
8373
|
+
var tempNewPosition = transformAbsPositionToRelativePositionInsideElement({
|
|
8374
|
+
x: newX,
|
|
8375
|
+
y: newY,
|
|
8376
|
+
}, elementAbsPosition);
|
|
8320
8377
|
//handle to keep the port always in the correct allowed position
|
|
8321
8378
|
var newPosition = normalizePortPosition(tempNewPosition);
|
|
8322
8379
|
if (newPosition) {
|
|
@@ -8349,15 +8406,17 @@ var Element = function (props) {
|
|
|
8349
8406
|
}
|
|
8350
8407
|
}, [_paperEventEmitterContext, potentialPortPosition]);
|
|
8351
8408
|
//Update state when label of port is moved
|
|
8352
|
-
var handlePortLabelMoved = React.useCallback(function (
|
|
8409
|
+
var handlePortLabelMoved = React.useCallback(function (newX, newY, portId) {
|
|
8353
8410
|
setPorts(function (prevPorts) {
|
|
8354
8411
|
return prevPorts.map(function (p) {
|
|
8355
8412
|
if (p.id === portId && p.label) {
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8413
|
+
var newLabel = Object.assign(Object.create(Object.getPrototypeOf(p.label)), p.label);
|
|
8414
|
+
var newPosition = {
|
|
8415
|
+
x: newX,
|
|
8416
|
+
y: newY
|
|
8417
|
+
};
|
|
8418
|
+
newLabel.position = newPosition;
|
|
8419
|
+
p.label = newLabel;
|
|
8361
8420
|
}
|
|
8362
8421
|
return p;
|
|
8363
8422
|
});
|
|
@@ -8516,9 +8575,11 @@ var Element = function (props) {
|
|
|
8516
8575
|
enabled: false,
|
|
8517
8576
|
keepRatio: false
|
|
8518
8577
|
},
|
|
8578
|
+
x: selectedPort ? elementAbsPosition.x + selectedPort.position.x : undefined,
|
|
8579
|
+
y: selectedPort ? elementAbsPosition.y + selectedPort.position.y : undefined,
|
|
8519
8580
|
// width: selectedPort?.size.width,
|
|
8520
8581
|
// height: selectedPort?.size.height,
|
|
8521
|
-
movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
|
|
8582
|
+
// movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
|
|
8522
8583
|
onMove: handlePortMove
|
|
8523
8584
|
});
|
|
8524
8585
|
useSelectionFrame({
|
|
@@ -8536,7 +8597,7 @@ var Element = function (props) {
|
|
|
8536
8597
|
: 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 :
|
|
8537
8598
|
ports.map(function (p, index) {
|
|
8538
8599
|
var _a, _b, _c, _d, _e, _f;
|
|
8539
|
-
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,
|
|
8600
|
+
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,
|
|
8540
8601
|
// rotation={rotatePort(p)}
|
|
8541
8602
|
calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: handlePortLabelMoved, onPortLabelResized: handlePortLabelResized, onPortLabelContentChanged: handlePortLabelContentChanged, onSelected: handleSelectedPort, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, onMouseMove: handlePortMouseMove,
|
|
8542
8603
|
// onMouseEnter={() => {
|
|
@@ -8548,7 +8609,7 @@ var Element = function (props) {
|
|
|
8548
8609
|
}), texts === null || texts === void 0 ? void 0 :
|
|
8549
8610
|
texts.map(function (t, index) {
|
|
8550
8611
|
var _a, _b;
|
|
8551
|
-
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); } });
|
|
8612
|
+
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); } });
|
|
8552
8613
|
}),
|
|
8553
8614
|
children));
|
|
8554
8615
|
};
|
|
@@ -8814,11 +8875,6 @@ function convertElementsToTree(elements) {
|
|
|
8814
8875
|
var foundChildElements = possibleChildElements.filter(function (ele) { var _a; return ((_a = ele.parentElement) === null || _a === void 0 ? void 0 : _a.id) === elementNodeInTree.id; });
|
|
8815
8876
|
var orphanedElements = possibleChildElements.filter(function (ele) { var _a; return ((_a = ele.parentElement) === null || _a === void 0 ? void 0 : _a.id) !== elementNodeInTree.id; });
|
|
8816
8877
|
var childElementsWithChild = foundChildElements.map(function (_elementNodeInTree) {
|
|
8817
|
-
// const relativePosition = {
|
|
8818
|
-
// x: _elementNodeInTree.position.x - elementNodeInTree.position.x,
|
|
8819
|
-
// y: _elementNodeInTree.position.y - elementNodeInTree.position.y,
|
|
8820
|
-
// }
|
|
8821
|
-
// _elementNodeInTree.relativePosition = relativePosition;
|
|
8822
8878
|
var newNode = findChildElementsOfNode(_elementNodeInTree, orphanedElements);
|
|
8823
8879
|
return newNode;
|
|
8824
8880
|
});
|
|
@@ -8828,7 +8884,6 @@ function convertElementsToTree(elements) {
|
|
|
8828
8884
|
var parentElms = elements.filter(function (e) { return !e.parentElement; });
|
|
8829
8885
|
var childElms = elements.filter(function (e) { return e.parentElement; });
|
|
8830
8886
|
var parsedElementsInTree = parentElms.map(function (ele) {
|
|
8831
|
-
// ele.relativePosition = ele.position;
|
|
8832
8887
|
var eleWithChild = findChildElementsOfNode(ele, childElms);
|
|
8833
8888
|
return eleWithChild;
|
|
8834
8889
|
});
|
|
@@ -8849,10 +8904,10 @@ var Paper = function (props) {
|
|
|
8849
8904
|
var paperContainerRef = React.useRef(null);
|
|
8850
8905
|
var tempLinkRef = React.useRef(tempLink); //Cache tempLink to avoid re-render when tempLink changed
|
|
8851
8906
|
var elementsRef = React.useRef(elements); //Cache elements to avoid re-render when elements changed
|
|
8907
|
+
var linksRef = React.useRef(links); //Cache links to avoid re-render when links changed
|
|
8908
|
+
var textsRef = React.useRef(texts); //Cache texts to avoid re-render when texts changed
|
|
8852
8909
|
var size = props.size;
|
|
8853
|
-
React.
|
|
8854
|
-
console.log('Render Paper');
|
|
8855
|
-
});
|
|
8910
|
+
var selectedElementAbsPosition = React.useMemo(function () { return selectedElement ? getAbsolutePosition(selectedElement) : null; }, [selectedElement]);
|
|
8856
8911
|
React.useEffect(function () {
|
|
8857
8912
|
setElements(props.elements);
|
|
8858
8913
|
}, [props.elements]);
|
|
@@ -8864,17 +8919,27 @@ var Paper = function (props) {
|
|
|
8864
8919
|
}, [props.texts]);
|
|
8865
8920
|
React.useEffect(function () {
|
|
8866
8921
|
var off = props.onManuallyTriggerRenderElement(function (elementId) {
|
|
8867
|
-
|
|
8868
|
-
|
|
8922
|
+
setElements(__spreadArray([], elements, true));
|
|
8923
|
+
if (props.onElementsChanged) {
|
|
8924
|
+
props.onElementsChanged(__spreadArray([], elements, true));
|
|
8925
|
+
}
|
|
8869
8926
|
});
|
|
8870
8927
|
return function () {
|
|
8871
8928
|
off();
|
|
8872
8929
|
};
|
|
8873
|
-
}, [props.onManuallyTriggerRenderElement]);
|
|
8930
|
+
}, [props.onManuallyTriggerRenderElement, props.onElementsChanged, elements]);
|
|
8874
8931
|
//Cache elements to avoid re-render when elements changed
|
|
8875
8932
|
React.useEffect(function () {
|
|
8876
8933
|
elementsRef.current = elements;
|
|
8877
8934
|
}, [elements]);
|
|
8935
|
+
//Cache links to avoid re-render when links changed
|
|
8936
|
+
React.useEffect(function () {
|
|
8937
|
+
linksRef.current = links;
|
|
8938
|
+
}, [links]);
|
|
8939
|
+
//Cache texts to avoid re-render when texts changed
|
|
8940
|
+
React.useEffect(function () {
|
|
8941
|
+
textsRef.current = texts;
|
|
8942
|
+
}, [texts]);
|
|
8878
8943
|
useKeyboardCommands({
|
|
8879
8944
|
element: paperContainerRef.current
|
|
8880
8945
|
});
|
|
@@ -8922,7 +8987,6 @@ var Paper = function (props) {
|
|
|
8922
8987
|
var parentChangedCancelers = elementsRef.current.map(function (element) {
|
|
8923
8988
|
var _a;
|
|
8924
8989
|
return (_a = element.onParentChanged) === null || _a === void 0 ? void 0 : _a.call(element, function (newPa, oldPa) {
|
|
8925
|
-
console.log('onParentChanged');
|
|
8926
8990
|
updateElementsTree();
|
|
8927
8991
|
});
|
|
8928
8992
|
});
|
|
@@ -8931,13 +8995,18 @@ var Paper = function (props) {
|
|
|
8931
8995
|
var _a;
|
|
8932
8996
|
return (_a = element.onAddedPort) === null || _a === void 0 ? void 0 : _a.call(element, function (newPort) {
|
|
8933
8997
|
console.log("A new port has been added to element ".concat(element.id));
|
|
8934
|
-
|
|
8935
|
-
|
|
8998
|
+
var prevElements = elementsRef.current;
|
|
8999
|
+
var newElements = prevElements.map(function (ele) {
|
|
8936
9000
|
if (ele.id === element.id) {
|
|
8937
9001
|
ele.ports = __spreadArray([], (ele.ports || []), true);
|
|
8938
9002
|
}
|
|
8939
9003
|
return ele;
|
|
8940
|
-
});
|
|
9004
|
+
});
|
|
9005
|
+
//Set state to re-render component
|
|
9006
|
+
setElements(newElements);
|
|
9007
|
+
if (props.onElementsChanged) {
|
|
9008
|
+
props.onElementsChanged(newElements);
|
|
9009
|
+
}
|
|
8941
9010
|
});
|
|
8942
9011
|
});
|
|
8943
9012
|
return function () {
|
|
@@ -8966,8 +9035,20 @@ var Paper = function (props) {
|
|
|
8966
9035
|
if (selectedElement) {
|
|
8967
9036
|
var deletedChildElements = getDeletedChildElements(selectedElement);
|
|
8968
9037
|
var deletedElementIds_1 = __spreadArray(__spreadArray([], deletedChildElements, true), [selectedElement], false).map(function (e) { return e.id; });
|
|
8969
|
-
|
|
8970
|
-
|
|
9038
|
+
var prevElements = elementsRef.current;
|
|
9039
|
+
var newElements = prevElements.filter(function (e) { return !deletedElementIds_1.includes(e.id); });
|
|
9040
|
+
//Set state to re-render component
|
|
9041
|
+
setElements(newElements);
|
|
9042
|
+
if (props.onElementsChanged) {
|
|
9043
|
+
props.onElementsChanged(newElements);
|
|
9044
|
+
}
|
|
9045
|
+
//Update links
|
|
9046
|
+
var prevLinks = linksRef.current;
|
|
9047
|
+
var newLinks = prevLinks.filter(function (l) { return !deletedElementIds_1.includes(l.sourceElement.id) && !deletedElementIds_1.includes(l.targetElement.id); });
|
|
9048
|
+
setLinks(newLinks);
|
|
9049
|
+
if (props.onLinksChanged) {
|
|
9050
|
+
props.onLinksChanged(newLinks);
|
|
9051
|
+
}
|
|
8971
9052
|
setSelectedElement(undefined);
|
|
8972
9053
|
setSelectedElementSVG(null);
|
|
8973
9054
|
}
|
|
@@ -8979,14 +9060,19 @@ var Paper = function (props) {
|
|
|
8979
9060
|
return function () {
|
|
8980
9061
|
listener.off();
|
|
8981
9062
|
};
|
|
8982
|
-
}, [selectedElement]);
|
|
9063
|
+
}, [selectedElement, props.onElementsChanged]);
|
|
8983
9064
|
//Listen command delete selected for link
|
|
8984
9065
|
React.useEffect(function () {
|
|
8985
9066
|
var _a;
|
|
8986
9067
|
var listener = paperEventEmitter.onCommandDeleteSelectedLink(function () {
|
|
8987
9068
|
if (selectedLink) {
|
|
8988
|
-
|
|
9069
|
+
var prevLinks = linksRef.current;
|
|
9070
|
+
var newLinks = prevLinks.filter(function (l) { return l.id !== selectedLink.id; });
|
|
9071
|
+
setLinks(links);
|
|
8989
9072
|
setSelectedLink(undefined);
|
|
9073
|
+
if (props.onLinksChanged) {
|
|
9074
|
+
props.onLinksChanged(newLinks);
|
|
9075
|
+
}
|
|
8990
9076
|
}
|
|
8991
9077
|
});
|
|
8992
9078
|
//broadcast selected link to parent component
|
|
@@ -8996,13 +9082,18 @@ var Paper = function (props) {
|
|
|
8996
9082
|
return function () {
|
|
8997
9083
|
listener.off();
|
|
8998
9084
|
};
|
|
8999
|
-
}, [selectedLink]);
|
|
9085
|
+
}, [selectedLink, props.onLinksChanged]);
|
|
9000
9086
|
//Listen command delete selected for Text
|
|
9001
9087
|
React.useEffect(function () {
|
|
9002
9088
|
var _a;
|
|
9003
9089
|
var listener = paperEventEmitter.onCommandDeleteSelectedText(function () {
|
|
9004
9090
|
if (selectedText) {
|
|
9005
|
-
|
|
9091
|
+
var prevTexts = textsRef.current;
|
|
9092
|
+
var newTexts = prevTexts.filter(function (t) { return t.id !== selectedText.id; });
|
|
9093
|
+
setTexts(newTexts);
|
|
9094
|
+
if (props.onTextsChanged) {
|
|
9095
|
+
props.onTextsChanged(newTexts);
|
|
9096
|
+
}
|
|
9006
9097
|
setSelectedText(undefined);
|
|
9007
9098
|
}
|
|
9008
9099
|
});
|
|
@@ -9013,7 +9104,7 @@ var Paper = function (props) {
|
|
|
9013
9104
|
return function () {
|
|
9014
9105
|
listener.off();
|
|
9015
9106
|
};
|
|
9016
|
-
}, [selectedText]);
|
|
9107
|
+
}, [selectedText, props.onTextsChanged]);
|
|
9017
9108
|
var handlePaperMouseMove = function (ev) {
|
|
9018
9109
|
var _a;
|
|
9019
9110
|
//if there is a temp link, update the temp target point
|
|
@@ -9078,17 +9169,22 @@ var Paper = function (props) {
|
|
|
9078
9169
|
};
|
|
9079
9170
|
var handlePathChange = React.useCallback(function (path, id) {
|
|
9080
9171
|
//Update path of element link, that changed
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9172
|
+
// const prevLinks = linksRef.current;
|
|
9173
|
+
var updatedLinkIndex = links.findIndex(function (l) { return l.id === id; });
|
|
9174
|
+
links[updatedLinkIndex].path = path;
|
|
9175
|
+
var newLinks = __spreadArray([], links, true);
|
|
9176
|
+
setLinks(newLinks);
|
|
9177
|
+
if (props.onLinksChanged) {
|
|
9178
|
+
props.onLinksChanged(newLinks);
|
|
9179
|
+
}
|
|
9180
|
+
}, [props.onLinksChanged, links]);
|
|
9087
9181
|
var handlePortMoved = React.useCallback(function (port, elementId, oldPosition, newPosition) {
|
|
9182
|
+
var _a;
|
|
9088
9183
|
var element = elementsRef.current.find(function (e) { return e.id === elementId; });
|
|
9089
9184
|
if (element) {
|
|
9090
9185
|
//set links equals a clone links to re-render links with new position
|
|
9091
|
-
|
|
9186
|
+
var prevLinks = linksRef.current;
|
|
9187
|
+
var newLinks = prevLinks.map(function (link) {
|
|
9092
9188
|
var _a, _b;
|
|
9093
9189
|
if (link.sourceElement.id === elementId && link.sourcePort.id === port.id) {
|
|
9094
9190
|
link.sourcePort.position = newPosition;
|
|
@@ -9097,24 +9193,30 @@ var Paper = function (props) {
|
|
|
9097
9193
|
link.targetPort.position = newPosition;
|
|
9098
9194
|
}
|
|
9099
9195
|
return link;
|
|
9100
|
-
}); });
|
|
9101
|
-
//Update port position in element, not re-render
|
|
9102
|
-
setElements(function (prevElements) {
|
|
9103
|
-
var _a;
|
|
9104
|
-
var updatedElementIndex = prevElements.findIndex(function (e) { return e.id === elementId; });
|
|
9105
|
-
prevElements[updatedElementIndex].ports = (_a = prevElements[updatedElementIndex].ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
|
|
9106
|
-
if (p.id === port.id) {
|
|
9107
|
-
p.position = newPosition;
|
|
9108
|
-
}
|
|
9109
|
-
return p;
|
|
9110
|
-
});
|
|
9111
|
-
return prevElements;
|
|
9112
9196
|
});
|
|
9197
|
+
setLinks(newLinks);
|
|
9198
|
+
if (props.onLinksChanged) {
|
|
9199
|
+
props.onLinksChanged(newLinks);
|
|
9200
|
+
}
|
|
9201
|
+
var newElements = elementsRef.current;
|
|
9202
|
+
var updatedElementIndex = newElements.findIndex(function (e) { return e.id === elementId; });
|
|
9203
|
+
newElements[updatedElementIndex].ports = (_a = newElements[updatedElementIndex].ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
|
|
9204
|
+
if (p.id === port.id) {
|
|
9205
|
+
p.position = newPosition;
|
|
9206
|
+
}
|
|
9207
|
+
return p;
|
|
9208
|
+
});
|
|
9209
|
+
//Update port position in element, not re-render
|
|
9210
|
+
//To avoid re-render
|
|
9211
|
+
setElements(newElements);
|
|
9212
|
+
if (props.onElementsChanged) {
|
|
9213
|
+
props.onElementsChanged(newElements);
|
|
9214
|
+
}
|
|
9113
9215
|
if (props.onPortMoved) {
|
|
9114
9216
|
props.onPortMoved(newPosition, port, element);
|
|
9115
9217
|
}
|
|
9116
9218
|
}
|
|
9117
|
-
}, [props.onPortMoved]);
|
|
9219
|
+
}, [props.onPortMoved, props.onElementsChanged, props.onLinksChanged]);
|
|
9118
9220
|
//Handle creating a new element link
|
|
9119
9221
|
var handlePortMouseDown = React.useCallback(function (ev, port, elementId) {
|
|
9120
9222
|
var _a;
|
|
@@ -9163,112 +9265,112 @@ var Paper = function (props) {
|
|
|
9163
9265
|
if (tempLinkRef.current) {
|
|
9164
9266
|
//Check if mouse up point is mouse down point or not
|
|
9165
9267
|
var isMouseUpOnNotSelf = tempLinkRef.current.sourcePort.id !== port.id || tempLinkRef.current.sourceElement.id !== elementId;
|
|
9166
|
-
var
|
|
9268
|
+
var newElementLink = null;
|
|
9167
9269
|
if (isMouseUpOnNotSelf) {
|
|
9168
9270
|
var _b = tempLinkRef.current, sourcePort = _b.sourcePort, sourceElement = _b.sourceElement;
|
|
9169
9271
|
var targetElement = elementsRef.current.find(function (e) { return e.id === elementId; });
|
|
9170
|
-
|
|
9272
|
+
newElementLink = createElementLink(sourcePort, sourceElement, port, targetElement);
|
|
9171
9273
|
}
|
|
9172
|
-
if (
|
|
9173
|
-
|
|
9174
|
-
|
|
9274
|
+
if (newElementLink) {
|
|
9275
|
+
var prevLinks = linksRef.current;
|
|
9276
|
+
var newLinks = __spreadArray(__spreadArray([], prevLinks, true), [newElementLink], false);
|
|
9277
|
+
setLinks(newLinks);
|
|
9278
|
+
if (props.onLinksChanged) {
|
|
9279
|
+
props.onLinksChanged(newLinks);
|
|
9280
|
+
}
|
|
9281
|
+
paperEventEmitter.emitElementLinkEnded(newElementLink);
|
|
9175
9282
|
}
|
|
9176
9283
|
else {
|
|
9177
9284
|
paperEventEmitter.emitElementLinkEnded();
|
|
9178
9285
|
}
|
|
9179
9286
|
setTempLink(null);
|
|
9180
9287
|
}
|
|
9181
|
-
}, [paperEventEmitter, createElementLink, props.onPortMouseUp]);
|
|
9182
|
-
var handleLinkLabelMoved = React.useCallback(function (
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
break;
|
|
9195
|
-
}
|
|
9196
|
-
case 'source': {
|
|
9197
|
-
var oldPosition = currentLink.sourceLabel.position || LINK_SOURCE_LABEL_POSITION_FROM_SOURCE_PORT;
|
|
9198
|
-
var newPosition = {
|
|
9199
|
-
x: oldPosition.x + offsetX,
|
|
9200
|
-
y: oldPosition.y + offsetY,
|
|
9201
|
-
};
|
|
9202
|
-
currentLink.sourceLabel.position = newPosition;
|
|
9203
|
-
break;
|
|
9204
|
-
}
|
|
9205
|
-
case 'target': {
|
|
9206
|
-
var oldPosition = currentLink.targetLabel.position || LINK_TARGET_LABEL_POSITION_FROM_TARGET_PORT;
|
|
9207
|
-
var newPosition = {
|
|
9208
|
-
x: oldPosition.x + offsetX,
|
|
9209
|
-
y: oldPosition.y + offsetY,
|
|
9210
|
-
};
|
|
9211
|
-
currentLink.targetLabel.position = newPosition;
|
|
9212
|
-
break;
|
|
9213
|
-
}
|
|
9288
|
+
}, [paperEventEmitter, createElementLink, props.onPortMouseUp, props.onLinksChanged]);
|
|
9289
|
+
var handleLinkLabelMoved = React.useCallback(function (newX, newY, index, labelType) {
|
|
9290
|
+
var prevLinks = linksRef.current;
|
|
9291
|
+
var newLinks = __spreadArray([], prevLinks, true);
|
|
9292
|
+
var currentLink = newLinks[index];
|
|
9293
|
+
var newPosition = {
|
|
9294
|
+
x: newX,
|
|
9295
|
+
y: newY,
|
|
9296
|
+
};
|
|
9297
|
+
switch (labelType) {
|
|
9298
|
+
case 'middle': {
|
|
9299
|
+
currentLink.label.position = newPosition;
|
|
9300
|
+
break;
|
|
9214
9301
|
}
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9302
|
+
case 'source': {
|
|
9303
|
+
currentLink.sourceLabel.position = newPosition;
|
|
9304
|
+
break;
|
|
9305
|
+
}
|
|
9306
|
+
case 'target': {
|
|
9307
|
+
currentLink.targetLabel.position = newPosition;
|
|
9308
|
+
break;
|
|
9309
|
+
}
|
|
9310
|
+
}
|
|
9311
|
+
setLinks(newLinks);
|
|
9312
|
+
if (props.onLinksChanged) {
|
|
9313
|
+
props.onLinksChanged(newLinks);
|
|
9314
|
+
}
|
|
9315
|
+
}, [props.onLinksChanged]);
|
|
9218
9316
|
var handleLinkLabelResized = React.useCallback(function (width, height, index, labelType) {
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
}
|
|
9231
|
-
case 'source': {
|
|
9232
|
-
var newSize = {
|
|
9233
|
-
width: width,
|
|
9234
|
-
height: height,
|
|
9235
|
-
};
|
|
9236
|
-
currentLink.sourceLabel.size = newSize;
|
|
9237
|
-
break;
|
|
9238
|
-
}
|
|
9239
|
-
case 'target': {
|
|
9240
|
-
var newSize = {
|
|
9241
|
-
width: width,
|
|
9242
|
-
height: height,
|
|
9243
|
-
};
|
|
9244
|
-
currentLink.targetLabel.size = newSize;
|
|
9245
|
-
break;
|
|
9246
|
-
}
|
|
9317
|
+
var prevLinks = linksRef.current;
|
|
9318
|
+
var newLinks = __spreadArray([], prevLinks, true);
|
|
9319
|
+
var currentLink = newLinks[index];
|
|
9320
|
+
switch (labelType) {
|
|
9321
|
+
case 'middle': {
|
|
9322
|
+
var newSize = {
|
|
9323
|
+
width: width,
|
|
9324
|
+
height: height,
|
|
9325
|
+
};
|
|
9326
|
+
currentLink.label.size = newSize;
|
|
9327
|
+
break;
|
|
9247
9328
|
}
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9329
|
+
case 'source': {
|
|
9330
|
+
var newSize = {
|
|
9331
|
+
width: width,
|
|
9332
|
+
height: height,
|
|
9333
|
+
};
|
|
9334
|
+
currentLink.sourceLabel.size = newSize;
|
|
9335
|
+
break;
|
|
9336
|
+
}
|
|
9337
|
+
case 'target': {
|
|
9338
|
+
var newSize = {
|
|
9339
|
+
width: width,
|
|
9340
|
+
height: height,
|
|
9341
|
+
};
|
|
9342
|
+
currentLink.targetLabel.size = newSize;
|
|
9343
|
+
break;
|
|
9344
|
+
}
|
|
9345
|
+
}
|
|
9346
|
+
setLinks(newLinks);
|
|
9347
|
+
if (props.onLinksChanged) {
|
|
9348
|
+
props.onLinksChanged(newLinks);
|
|
9349
|
+
}
|
|
9350
|
+
}, [props.onLinksChanged]);
|
|
9251
9351
|
var handleLinkLabelContentChanged = React.useCallback(function (newValue, index, labelType) {
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
}
|
|
9260
|
-
case 'source': {
|
|
9261
|
-
currentLink.sourceLabel.content = newValue;
|
|
9262
|
-
break;
|
|
9263
|
-
}
|
|
9264
|
-
case 'target': {
|
|
9265
|
-
currentLink.targetLabel.content = newValue;
|
|
9266
|
-
break;
|
|
9267
|
-
}
|
|
9352
|
+
var prevLinks = linksRef.current;
|
|
9353
|
+
var newLinks = __spreadArray([], prevLinks, true);
|
|
9354
|
+
var currentLink = newLinks[index];
|
|
9355
|
+
switch (labelType) {
|
|
9356
|
+
case 'middle': {
|
|
9357
|
+
currentLink.label.content = newValue;
|
|
9358
|
+
break;
|
|
9268
9359
|
}
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9360
|
+
case 'source': {
|
|
9361
|
+
currentLink.sourceLabel.content = newValue;
|
|
9362
|
+
break;
|
|
9363
|
+
}
|
|
9364
|
+
case 'target': {
|
|
9365
|
+
currentLink.targetLabel.content = newValue;
|
|
9366
|
+
break;
|
|
9367
|
+
}
|
|
9368
|
+
}
|
|
9369
|
+
setLinks(newLinks);
|
|
9370
|
+
if (props.onLinksChanged) {
|
|
9371
|
+
props.onLinksChanged(newLinks);
|
|
9372
|
+
}
|
|
9373
|
+
}, [props.onLinksChanged]);
|
|
9272
9374
|
var handleSelectLink = function (link, index) {
|
|
9273
9375
|
setSelectedLink(link);
|
|
9274
9376
|
};
|
|
@@ -9276,12 +9378,10 @@ var Paper = function (props) {
|
|
|
9276
9378
|
setSelectedLink(undefined);
|
|
9277
9379
|
};
|
|
9278
9380
|
//update absolute position of element and absolute position of children elements
|
|
9279
|
-
var updateElementPosition = function (element,
|
|
9280
|
-
|
|
9281
|
-
element.position.
|
|
9282
|
-
|
|
9283
|
-
// element.childrenElementsInTree = element.childrenElementsInTree.map(child => updateElementPosition(child, movementX, movementY));
|
|
9284
|
-
// }
|
|
9381
|
+
var updateElementPosition = function (element, x, y) {
|
|
9382
|
+
var relativePosition = transformAbsPositionToElementRelativePosition({ x: x, y: y }, element);
|
|
9383
|
+
element.position.x = relativePosition.x;
|
|
9384
|
+
element.position.y = relativePosition.y;
|
|
9285
9385
|
return element;
|
|
9286
9386
|
};
|
|
9287
9387
|
//use selection frame
|
|
@@ -9292,18 +9392,16 @@ var Paper = function (props) {
|
|
|
9292
9392
|
enabled: true,
|
|
9293
9393
|
keepRatio: true
|
|
9294
9394
|
},
|
|
9395
|
+
x: selectedElementAbsPosition === null || selectedElementAbsPosition === void 0 ? void 0 : selectedElementAbsPosition.x,
|
|
9396
|
+
y: selectedElementAbsPosition === null || selectedElementAbsPosition === void 0 ? void 0 : selectedElementAbsPosition.y,
|
|
9295
9397
|
width: selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.size.width,
|
|
9296
9398
|
height: selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.size.height,
|
|
9297
9399
|
//movingOffsetThreshold: ELEMENT_MOVING_OFFSET_THRESHOLD,
|
|
9298
|
-
onMove: function (
|
|
9400
|
+
onMove: function (newX, newY) {
|
|
9299
9401
|
if (!selectedElement)
|
|
9300
9402
|
return;
|
|
9301
9403
|
var oldPosition = __assign({}, selectedElement.position);
|
|
9302
|
-
var newElementPosition = updateElementPosition(selectedElement,
|
|
9303
|
-
// newElementPosition.relativePosition = {
|
|
9304
|
-
// x: newElementPosition.relativePosition!.x + offsetX,
|
|
9305
|
-
// y: newElementPosition.relativePosition!.y + offsetY
|
|
9306
|
-
// }
|
|
9404
|
+
var newElementPosition = updateElementPosition(selectedElement, newX, newY);
|
|
9307
9405
|
var indexSelectedElement = elements.findIndex(function (e) { return e.id === selectedElement.id; });
|
|
9308
9406
|
//Set state to re-render UI with new position
|
|
9309
9407
|
setElementsInTree(function (prev) { return __spreadArray([], prev, true); });
|
|
@@ -9320,7 +9418,11 @@ var Paper = function (props) {
|
|
|
9320
9418
|
var oldSize = selectedElement.size;
|
|
9321
9419
|
var newSize = { width: width, height: height };
|
|
9322
9420
|
elements[indexSelectedElement].size = newSize;
|
|
9323
|
-
|
|
9421
|
+
var newElements = __spreadArray([], elements, true);
|
|
9422
|
+
setElements(newElements);
|
|
9423
|
+
if (props.onElementsChanged) {
|
|
9424
|
+
props.onElementsChanged(newElements);
|
|
9425
|
+
}
|
|
9324
9426
|
if (props.onElementResized) {
|
|
9325
9427
|
props.onElementResized(newSize, selectedElement, indexSelectedElement);
|
|
9326
9428
|
}
|
|
@@ -9333,8 +9435,8 @@ var Paper = function (props) {
|
|
|
9333
9435
|
avoid causing the components using it to re-render unnecessarily
|
|
9334
9436
|
*/
|
|
9335
9437
|
var onLabelMoved = React.useCallback(function (index) {
|
|
9336
|
-
return function (
|
|
9337
|
-
handleLinkLabelMoved(
|
|
9438
|
+
return function (newX, newY, labelType) {
|
|
9439
|
+
handleLinkLabelMoved(newX, newY, index, labelType);
|
|
9338
9440
|
};
|
|
9339
9441
|
}, [handleLinkLabelMoved]);
|
|
9340
9442
|
/*
|
|
@@ -9357,18 +9459,20 @@ var Paper = function (props) {
|
|
|
9357
9459
|
}, [handleLinkLabelContentChanged]);
|
|
9358
9460
|
var handleClickLinkDelete = React.useCallback(function (link, index) {
|
|
9359
9461
|
return function () {
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9462
|
+
var prevLinks = linksRef.current;
|
|
9463
|
+
var newLinks = __spreadArray([], prevLinks, true);
|
|
9464
|
+
newLinks.splice(index, 1);
|
|
9465
|
+
setLinks(newLinks);
|
|
9466
|
+
if (props.onLinksChanged) {
|
|
9467
|
+
props.onLinksChanged(newLinks);
|
|
9468
|
+
}
|
|
9365
9469
|
};
|
|
9366
|
-
}, []);
|
|
9470
|
+
}, [props.onLinksChanged]);
|
|
9367
9471
|
var handleMouseUpAtLinkedPortPlaceholder = React.useCallback(function (link, position, targetElementId) {
|
|
9368
9472
|
var targetElement = elementsRef.current.find(function (e) { return e.id === targetElementId; });
|
|
9369
9473
|
if (!targetElement)
|
|
9370
9474
|
return;
|
|
9371
|
-
console.
|
|
9475
|
+
console.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));
|
|
9372
9476
|
if (props.onCreatingPortByLinking) {
|
|
9373
9477
|
var sourcePort = link.sourcePort, sourceElement = link.sourceElement;
|
|
9374
9478
|
//Handle create port via onCreatingPortByLinking prop
|
|
@@ -9377,11 +9481,16 @@ var Paper = function (props) {
|
|
|
9377
9481
|
//Add new port to target element
|
|
9378
9482
|
targetElement.addPort(targetPort);
|
|
9379
9483
|
//Create new link with created port, that is returned.
|
|
9380
|
-
var
|
|
9484
|
+
var newElementLink = createElementLink(sourcePort, sourceElement, targetPort, targetElement);
|
|
9381
9485
|
//Create link and clear some thing, then return
|
|
9382
|
-
if (
|
|
9383
|
-
|
|
9384
|
-
|
|
9486
|
+
if (newElementLink) {
|
|
9487
|
+
var prevLinks = linksRef.current;
|
|
9488
|
+
var newLinks = __spreadArray(__spreadArray([], prevLinks, true), [newElementLink], false);
|
|
9489
|
+
setLinks(newLinks);
|
|
9490
|
+
if (props.onLinksChanged) {
|
|
9491
|
+
props.onLinksChanged(newLinks);
|
|
9492
|
+
}
|
|
9493
|
+
paperEventEmitter.emitElementLinkEnded(newElementLink);
|
|
9385
9494
|
setTempLink(null);
|
|
9386
9495
|
return;
|
|
9387
9496
|
}
|
|
@@ -9390,21 +9499,24 @@ var Paper = function (props) {
|
|
|
9390
9499
|
//Clear tempLink
|
|
9391
9500
|
setTempLink(null);
|
|
9392
9501
|
paperEventEmitter.emitElementLinkEnded();
|
|
9393
|
-
}, [props.onCreatingPortByLinking, createElementLink, paperEventEmitter]);
|
|
9502
|
+
}, [props.onCreatingPortByLinking, createElementLink, paperEventEmitter, props.onLinksChanged]);
|
|
9394
9503
|
var handleElementTextChange = React.useCallback(function (elementId, textId, newContent) {
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
}
|
|
9504
|
+
var prevElms = elementsRef.current;
|
|
9505
|
+
var newElements = prevElms.map(function (curEle) {
|
|
9506
|
+
//Find changed text of element to update the content for it.
|
|
9507
|
+
if (curEle.id === elementId && curEle.texts) {
|
|
9508
|
+
var updatedTextId = curEle.texts.findIndex(function (t) { return t.id === textId; });
|
|
9509
|
+
if (updatedTextId !== undefined) {
|
|
9510
|
+
curEle.texts[updatedTextId].content = newContent;
|
|
9403
9511
|
}
|
|
9404
|
-
|
|
9405
|
-
|
|
9512
|
+
}
|
|
9513
|
+
return curEle;
|
|
9406
9514
|
});
|
|
9407
|
-
|
|
9515
|
+
setElements(newElements);
|
|
9516
|
+
if (props.onElementsChanged) {
|
|
9517
|
+
props.onElementsChanged(newElements);
|
|
9518
|
+
}
|
|
9519
|
+
}, [props.onElementsChanged]);
|
|
9408
9520
|
var handleElementClicked = React.useCallback(function (elementId, e, ref) {
|
|
9409
9521
|
e.stopPropagation();
|
|
9410
9522
|
var tempLink = tempLinkRef.current;
|
|
@@ -9459,14 +9571,8 @@ var Paper = function (props) {
|
|
|
9459
9571
|
return (React.createElement("g", { id: "group-of-element-".concat(element.id), key: element.id },
|
|
9460
9572
|
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,
|
|
9461
9573
|
// portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
|
|
9462
|
-
onMouseUpAtLinkedPortPlaceholder: handleMouseUpAtLinkedPortPlaceholder, onTextUpdated: handleElementTextChange, onManuallyTriggerRenderPort: props.onManuallyTriggerRenderPort, textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition }, element.childrenElementsInTree && element.childrenElementsInTree.map(renderElementInTree))));
|
|
9574
|
+
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))));
|
|
9463
9575
|
}, [handleElementClicked, handleContextMenu, handlePortMoved, handlePortMouseDown, handlePortMouseUp, handleMouseUpAtLinkedPortPlaceholder, handleElementTextChange, handleMouseUp, handleMouseMove, handleMouseLeave]);
|
|
9464
|
-
React.useEffect(function () {
|
|
9465
|
-
console.log('elementsInTree');
|
|
9466
|
-
}, [elementsInTree]);
|
|
9467
|
-
React.useEffect(function () {
|
|
9468
|
-
console.log('renderElementInTree');
|
|
9469
|
-
}, [renderElementInTree]);
|
|
9470
9576
|
var ElementsInTree = React.useMemo(function () {
|
|
9471
9577
|
return elementsInTree.map(function (element, index) {
|
|
9472
9578
|
return renderElementInTree(element);
|
|
@@ -9524,7 +9630,6 @@ var Editor = function (_a) {
|
|
|
9524
9630
|
var offs = [];
|
|
9525
9631
|
if (editorContext) {
|
|
9526
9632
|
offs.push(editorContext.onEditorContextUpdated(function () {
|
|
9527
|
-
console.log("onEditorContextUpdated");
|
|
9528
9633
|
setEditorStates(editorContext);
|
|
9529
9634
|
}));
|
|
9530
9635
|
}
|
|
@@ -9568,12 +9673,21 @@ var Editor = function (_a) {
|
|
|
9568
9673
|
var handleElementMouseUp = React.useCallback(function (ev, element) {
|
|
9569
9674
|
editorContext.onElementMouseUpHandler(ev, element);
|
|
9570
9675
|
}, [editorContext]);
|
|
9676
|
+
var handleElementsChanged = React.useCallback(function (elements) {
|
|
9677
|
+
editorContext.elements = elements;
|
|
9678
|
+
}, [editorContext]);
|
|
9571
9679
|
var handleLinkSelected = React.useCallback(function (link) {
|
|
9572
9680
|
editorContext.onLinkSelectedHandler(link);
|
|
9573
9681
|
}, [editorContext]);
|
|
9682
|
+
var handleLinksChanged = React.useCallback(function (links) {
|
|
9683
|
+
editorContext.links = links;
|
|
9684
|
+
}, [editorContext]);
|
|
9574
9685
|
var handleTextSelected = React.useCallback(function (text) {
|
|
9575
9686
|
editorContext.onTextSelectedHandler(text);
|
|
9576
9687
|
}, [editorContext]);
|
|
9688
|
+
var handleTextsChanged = React.useCallback(function (texts) {
|
|
9689
|
+
editorContext.texts = texts;
|
|
9690
|
+
}, [editorContext]);
|
|
9577
9691
|
var handleOnCreatingLink = React.useCallback(function (sourcePort, sourceElement, targetPort, targetElement) {
|
|
9578
9692
|
if (editorContext.onCreatingLinkHandler) {
|
|
9579
9693
|
return editorContext.onCreatingLinkHandler(sourcePort, sourceElement, targetPort, targetElement);
|
|
@@ -9595,7 +9709,7 @@ var Editor = function (_a) {
|
|
|
9595
9709
|
var handlePaperMouseUp = React.useCallback(function (position) {
|
|
9596
9710
|
editorContext.onPaperMouseUpHandler(position);
|
|
9597
9711
|
}, [editorContext]);
|
|
9598
|
-
return (React.createElement(Paper$1, { key: "paper", size: { width: width, height: height }, elements: elements, links: links, texts: texts, onPaperClicked: handlePaperClicked, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onElementMouseLeave: handleElementMouseLeave, onElementMouseMove: handleElementMouseMove, onElementMouseUp: handleElementMouseUp, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onTextSelected: handleTextSelected, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseUp, onPaperMouseDown: handlePaperMouseDown, onManuallyTriggerRenderElement: editorContext.onManuallyTriggerRenderElement.bind(editorContext), onManuallyTriggerRenderPort: editorContext.onManuallyTriggerRenderPort.bind(editorContext) }));
|
|
9712
|
+
return (React.createElement(Paper$1, { key: "paper", size: { width: width, height: height }, elements: elements, links: links, texts: texts, onPaperClicked: handlePaperClicked, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onElementMouseLeave: handleElementMouseLeave, onElementMouseMove: handleElementMouseMove, onElementMouseUp: handleElementMouseUp, onElementsChanged: handleElementsChanged, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onLinksChanged: handleLinksChanged, onTextSelected: handleTextSelected, onTextsChanged: handleTextsChanged, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseUp, onPaperMouseDown: handlePaperMouseDown, onManuallyTriggerRenderElement: editorContext.onManuallyTriggerRenderElement.bind(editorContext), onManuallyTriggerRenderPort: editorContext.onManuallyTriggerRenderPort.bind(editorContext) }));
|
|
9599
9713
|
};
|
|
9600
9714
|
|
|
9601
9715
|
exports.CircleRC = Circle;
|