orcasvn-react-diagrams 0.1.67 → 0.1.71
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 +615 -450
- package/dist/cjs/types/components/paper.d.ts +6 -3
- package/dist/cjs/types/mocks/diamondElement.d.ts +1 -1
- package/dist/cjs/types/mocks/rectangularFrameElement.d.ts +1 -1
- package/dist/cjs/types/models/IEditorContext.d.ts +4 -1
- package/dist/cjs/types/models/IElement.d.ts +5 -0
- package/dist/cjs/types/models/IElementLink.d.ts +1 -0
- package/dist/cjs/types/models/IElementLinkProps.d.ts +5 -2
- package/dist/cjs/types/models/IElementProps.d.ts +10 -22
- package/dist/cjs/types/models/IPort.d.ts +1 -0
- package/dist/cjs/types/models/IText.d.ts +1 -0
- package/dist/cjs/types/models/implementations/EditorContext.d.ts +4 -1
- package/dist/cjs/types/models/implementations/Element.d.ts +6 -1
- package/dist/cjs/types/models/implementations/ElementLink.d.ts +2 -1
- package/dist/cjs/types/models/implementations/Port.d.ts +2 -1
- package/dist/cjs/types/models/implementations/Text.d.ts +2 -1
- package/dist/esm/index.js +615 -450
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/paper.d.ts +6 -3
- package/dist/esm/types/mocks/diamondElement.d.ts +1 -1
- package/dist/esm/types/mocks/rectangularFrameElement.d.ts +1 -1
- package/dist/esm/types/models/IEditorContext.d.ts +4 -1
- package/dist/esm/types/models/IElement.d.ts +5 -0
- package/dist/esm/types/models/IElementLink.d.ts +1 -0
- package/dist/esm/types/models/IElementLinkProps.d.ts +5 -2
- package/dist/esm/types/models/IElementProps.d.ts +10 -22
- package/dist/esm/types/models/IPort.d.ts +1 -0
- package/dist/esm/types/models/IText.d.ts +1 -0
- package/dist/esm/types/models/implementations/EditorContext.d.ts +4 -1
- package/dist/esm/types/models/implementations/Element.d.ts +6 -1
- package/dist/esm/types/models/implementations/ElementLink.d.ts +2 -1
- package/dist/esm/types/models/implementations/Port.d.ts +2 -1
- package/dist/esm/types/models/implementations/Text.d.ts +2 -1
- package/dist/index.d.ts +42 -27
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -484,7 +484,8 @@ function generateUniqueId() {
|
|
|
484
484
|
}
|
|
485
485
|
|
|
486
486
|
var Element$2 = /** @class */ (function () {
|
|
487
|
-
function Element(id, x, y, width, height, selectable, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection, parentElement, textsPlaceHolderClassName, textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition) {
|
|
487
|
+
function Element(id, x, y, width, height, selectable, removable, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection, parentElement, textsPlaceHolderClassName, textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition) {
|
|
488
|
+
if (removable === void 0) { removable = true; }
|
|
488
489
|
if (portMovealeAreas === void 0) { portMovealeAreas = []; }
|
|
489
490
|
this.positionAnchor = exports.PositioningAnchor.TopLeft;
|
|
490
491
|
this._childrenElements = [];
|
|
@@ -498,6 +499,7 @@ var Element$2 = /** @class */ (function () {
|
|
|
498
499
|
this._position = { x: x, y: y };
|
|
499
500
|
this._size = { width: width, height: height };
|
|
500
501
|
this.selectable = selectable === undefined ? true : selectable;
|
|
502
|
+
this.removable = removable;
|
|
501
503
|
this.cssClass = cssClass;
|
|
502
504
|
this.renderShape = renderShape;
|
|
503
505
|
this.texts = texts;
|
|
@@ -607,7 +609,7 @@ var Element$2 = /** @class */ (function () {
|
|
|
607
609
|
};
|
|
608
610
|
Element.prototype.addPort = function (newPort) {
|
|
609
611
|
if (this.ports) {
|
|
610
|
-
this.ports.
|
|
612
|
+
this.ports = __spreadArray(__spreadArray([], this.ports, true), [newPort], false);
|
|
611
613
|
}
|
|
612
614
|
else {
|
|
613
615
|
this.ports = [newPort];
|
|
@@ -629,7 +631,7 @@ var Element$2 = /** @class */ (function () {
|
|
|
629
631
|
if (index === -1) {
|
|
630
632
|
throw new Error("Port with id ".concat(id, " is not found"));
|
|
631
633
|
}
|
|
632
|
-
this.ports.
|
|
634
|
+
this.ports = this.ports.filter(function (p) { return p.id !== id; });
|
|
633
635
|
this._eventEmitter.emit('deletedPort', id);
|
|
634
636
|
};
|
|
635
637
|
Element.prototype.onDeletedPort = function (callback) {
|
|
@@ -645,6 +647,41 @@ var Element$2 = /** @class */ (function () {
|
|
|
645
647
|
return undefined;
|
|
646
648
|
return this.ports.find(function (p) { return p.id === id; });
|
|
647
649
|
};
|
|
650
|
+
Element.prototype.addText = function (newText) {
|
|
651
|
+
if (this.texts) {
|
|
652
|
+
this.texts.push(newText);
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
this.texts = [newText];
|
|
656
|
+
}
|
|
657
|
+
this._eventEmitter.emit('addedText', newText);
|
|
658
|
+
};
|
|
659
|
+
Element.prototype.onAddedText = function (callback) {
|
|
660
|
+
var _this = this;
|
|
661
|
+
this._eventEmitter.on('addedText', callback);
|
|
662
|
+
var canceller = function () {
|
|
663
|
+
_this._eventEmitter.off('addedText', callback);
|
|
664
|
+
};
|
|
665
|
+
return canceller;
|
|
666
|
+
};
|
|
667
|
+
Element.prototype.deleteText = function (id) {
|
|
668
|
+
if (!this.texts)
|
|
669
|
+
return;
|
|
670
|
+
var index = this.texts.findIndex(function (t) { return t.id === id; });
|
|
671
|
+
if (index === -1) {
|
|
672
|
+
throw new Error("Text with id ".concat(id, " is not found"));
|
|
673
|
+
}
|
|
674
|
+
this.texts.splice(index, 1);
|
|
675
|
+
this._eventEmitter.emit('deletedText', id);
|
|
676
|
+
};
|
|
677
|
+
Element.prototype.onDeletedText = function (callback) {
|
|
678
|
+
var _this = this;
|
|
679
|
+
this._eventEmitter.on('deletedText', callback);
|
|
680
|
+
var canceller = function () {
|
|
681
|
+
_this._eventEmitter.off('deletedText', callback);
|
|
682
|
+
};
|
|
683
|
+
return canceller;
|
|
684
|
+
};
|
|
648
685
|
return Element;
|
|
649
686
|
}());
|
|
650
687
|
|
|
@@ -697,7 +734,8 @@ var CustomShape = React.forwardRef(function (props, ref) {
|
|
|
697
734
|
});
|
|
698
735
|
|
|
699
736
|
var Port$1 = /** @class */ (function () {
|
|
700
|
-
function Port(id, x, y, label, shapeRenderer, width, height) {
|
|
737
|
+
function Port(id, x, y, label, shapeRenderer, width, height, removable) {
|
|
738
|
+
if (removable === void 0) { removable = true; }
|
|
701
739
|
var _this = this;
|
|
702
740
|
//internal properties
|
|
703
741
|
this._eventEmitter = new EventEmitter();
|
|
@@ -720,6 +758,7 @@ var Port$1 = /** @class */ (function () {
|
|
|
720
758
|
props.children));
|
|
721
759
|
});
|
|
722
760
|
}
|
|
761
|
+
this.removable = removable;
|
|
723
762
|
}
|
|
724
763
|
Object.defineProperty(Port.prototype, "id", {
|
|
725
764
|
get: function () {
|
|
@@ -733,7 +772,8 @@ var Port$1 = /** @class */ (function () {
|
|
|
733
772
|
|
|
734
773
|
var ElementLink$1 = /** @class */ (function () {
|
|
735
774
|
// constructor(id: string | null, sourceElement: IElement, sourcePort: IPort, targetElement: IElement, targetPort: IPort, tempTargetPosition: IPosition, points?: IPosition[]);
|
|
736
|
-
function ElementLink(id, sourceElement, sourcePort, targetElement, targetPort, tempTargetPosition, points, path, markerStart, markerEnd, markerDistanceFromPort, markerSize, label, sourceLabel, targetLabel) {
|
|
775
|
+
function ElementLink(id, sourceElement, sourcePort, targetElement, targetPort, tempTargetPosition, points, path, markerStart, markerEnd, markerDistanceFromPort, markerSize, label, sourceLabel, targetLabel, removable) {
|
|
776
|
+
if (removable === void 0) { removable = true; }
|
|
737
777
|
this.id = id || generateUniqueId();
|
|
738
778
|
this.sourceElement = sourceElement;
|
|
739
779
|
this.sourcePort = sourcePort;
|
|
@@ -766,12 +806,14 @@ var ElementLink$1 = /** @class */ (function () {
|
|
|
766
806
|
this.sourceLabel = sourceLabel;
|
|
767
807
|
if (targetLabel)
|
|
768
808
|
this.targetLabel = targetLabel;
|
|
809
|
+
this.removable = removable;
|
|
769
810
|
}
|
|
770
811
|
return ElementLink;
|
|
771
812
|
}());
|
|
772
813
|
|
|
773
814
|
var Text$2 = /** @class */ (function () {
|
|
774
|
-
function Text(id, content, width, height, editable, selectable, x, y, align, fontSize, border, style) {
|
|
815
|
+
function Text(id, content, width, height, editable, selectable, removable, x, y, align, fontSize, border, style) {
|
|
816
|
+
if (removable === void 0) { removable = true; }
|
|
775
817
|
this._id = id || generateUniqueId();
|
|
776
818
|
this.content = content;
|
|
777
819
|
this.align = align;
|
|
@@ -781,6 +823,7 @@ var Text$2 = /** @class */ (function () {
|
|
|
781
823
|
this.style = style;
|
|
782
824
|
this.editable = editable;
|
|
783
825
|
this.selectable = selectable;
|
|
826
|
+
this.removable = removable;
|
|
784
827
|
if (selectable === undefined) {
|
|
785
828
|
this.selectable = true; // Default to true if not specified
|
|
786
829
|
}
|
|
@@ -7446,10 +7489,10 @@ var getAbsolutePosition = function (element) {
|
|
|
7446
7489
|
x: element.position.x,
|
|
7447
7490
|
y: element.position.y,
|
|
7448
7491
|
};
|
|
7449
|
-
if (element.positionAnchor ===
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
}
|
|
7492
|
+
// if (element.positionAnchor === PositioningAnchor.Center) {
|
|
7493
|
+
// elemenetPositionWithTopLeftAnchor.x -= element.size.width / 2;
|
|
7494
|
+
// elemenetPositionWithTopLeftAnchor.y -= element.size.height / 2;
|
|
7495
|
+
// }
|
|
7453
7496
|
if (!parentElement) {
|
|
7454
7497
|
return __assign({}, elemenetPositionWithTopLeftAnchor);
|
|
7455
7498
|
}
|
|
@@ -7479,10 +7522,10 @@ var transformAbsPositionToElementRelativePosition = function (position, element)
|
|
|
7479
7522
|
x: position.x - absoluteParentElement.x,
|
|
7480
7523
|
y: position.y - absoluteParentElement.y,
|
|
7481
7524
|
};
|
|
7482
|
-
if (element.positionAnchor ===
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
}
|
|
7525
|
+
// if (element.positionAnchor === PositioningAnchor.Center) {
|
|
7526
|
+
// result.x += element.size.width / 2;
|
|
7527
|
+
// result.y += element.size.height / 2;
|
|
7528
|
+
// }
|
|
7486
7529
|
return result;
|
|
7487
7530
|
};
|
|
7488
7531
|
var transformAbsPositionToRelativePositionInsideElement = function (absolutePosition, parentAbsolutePosition) {
|
|
@@ -7891,7 +7934,10 @@ var SelectionFrame = function (props) {
|
|
|
7891
7934
|
}
|
|
7892
7935
|
return (React.createElement(React.Fragment, null,
|
|
7893
7936
|
PropDragDropHandlerElement && React.createElement(PropDragDropHandlerElement, { dragging: draggingRect, onMouseDown: addRectHandleMouseDown }),
|
|
7894
|
-
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, onMouseUp:
|
|
7937
|
+
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, onMouseUp: function (ev) {
|
|
7938
|
+
propOnMouseUp === null || propOnMouseUp === void 0 ? void 0 : propOnMouseUp(ev);
|
|
7939
|
+
setDraggingRect(false);
|
|
7940
|
+
} }),
|
|
7895
7941
|
propResizability.enabled ?
|
|
7896
7942
|
(React.createElement("circle", { cursor: 'se-resize', cx: leftX + width, cy: topY + height, r: r, fill: 'blue', stroke: 'blue', onMouseDown: circleHandleMouseDown })) : null));
|
|
7897
7943
|
};
|
|
@@ -7899,10 +7945,7 @@ var SelectionFrame = function (props) {
|
|
|
7899
7945
|
var useSelectionFrame = function (props) {
|
|
7900
7946
|
React.useEffect(function () {
|
|
7901
7947
|
//log selection frame rendering
|
|
7902
|
-
if (props.targetSVGElement) {
|
|
7903
|
-
console.debug('Rendering SelectionFrame for targetSVGElement:', props.targetSVGElement);
|
|
7904
|
-
}
|
|
7905
|
-
else {
|
|
7948
|
+
if (!props.targetSVGElement) {
|
|
7906
7949
|
console.warn('No targetSVGElement provided for SelectionFrame.');
|
|
7907
7950
|
}
|
|
7908
7951
|
if (props.targetSVGElement && props.container) {
|
|
@@ -8464,7 +8507,9 @@ function CloseIcon(_a) {
|
|
|
8464
8507
|
// const makerEnd = <path d="M0 0 L 20 10 L0 20 Z" fill="blue"></path>//<path d="M0 0 L 10 5 L0 10 Z"></path>
|
|
8465
8508
|
var IElementLink = function (_a) {
|
|
8466
8509
|
var _b, _c;
|
|
8467
|
-
var id = _a.id, path = _a.path, stroke = _a.stroke, _d = _a.strokeWidth, strokeWidth = _d === void 0 ? 4 : _d, pointsProp = _a.points,
|
|
8510
|
+
var id = _a.id, path = _a.path, stroke = _a.stroke, _d = _a.strokeWidth, strokeWidth = _d === void 0 ? 4 : _d, pointsProp = _a.points, sourcePositionX = _a.sourcePositionX, sourcePositionY = _a.sourcePositionY, targetPositionX = _a.targetPositionX, targetPositionY = _a.targetPositionY, removable = _a.removable,
|
|
8511
|
+
//TODO: get rid of this
|
|
8512
|
+
onPathChanged = _a.onPathChanged, onClickDelete = _a.onClickDelete, onSelected = _a.onSelected, onDeselected = _a.onDeselected, onPointsChanged = _a.onPointsChanged, container = _a.container, markerStart = _a.markerStart, markerEnd = _a.markerEnd, _e = _a.markerDistanceFromPort, markerDistanceFromPort = _e === void 0 ? LINK_MARKER_DISTANCE_FROM_PORT : _e, _f = _a.markerSize, markerSize = _f === void 0 ? LINK_MARKER_SIZE : _f, label = _a.label, sourceLabel = _a.sourceLabel, targetLabel = _a.targetLabel, onLabelMoved = _a.onLabelMoved, onLabelResized = _a.onLabelResized, onLabelContentChanged = _a.onLabelContentChanged;
|
|
8468
8513
|
var _g = React.useState(path), pathStr = _g[0], setPathStr = _g[1];
|
|
8469
8514
|
var _h = React.useState(pointsProp !== null && pointsProp !== void 0 ? pointsProp : []), points = _h[0], setPoints = _h[1];
|
|
8470
8515
|
var _j = React.useState(false), isDragging = _j[0], setIsDragging = _j[1];
|
|
@@ -8481,6 +8526,7 @@ var IElementLink = function (_a) {
|
|
|
8481
8526
|
var isFirstRender = React.useRef(true);
|
|
8482
8527
|
var onPointsChangedRef = React.useRef();
|
|
8483
8528
|
var draggingPointIndexRef = React.useRef(); // Ref to store the index of the point being dragged. No need to store it in state, as it is only used during the drag operation.
|
|
8529
|
+
var timeFromMouseDownToUpRef = React.useRef(0);
|
|
8484
8530
|
var angleMarkerStart = '0';
|
|
8485
8531
|
var angleMarkerEnd = '0';
|
|
8486
8532
|
var markerStartPosition;
|
|
@@ -8503,7 +8549,7 @@ var IElementLink = function (_a) {
|
|
|
8503
8549
|
return function () {
|
|
8504
8550
|
paperClickListener.off();
|
|
8505
8551
|
};
|
|
8506
|
-
}, []);
|
|
8552
|
+
}, [onPaperClicked, onDeselected]);
|
|
8507
8553
|
// Reset selected label when an element is selected
|
|
8508
8554
|
React.useEffect(function () {
|
|
8509
8555
|
var elementSelectedListener = onElementSelected(function () {
|
|
@@ -8516,34 +8562,32 @@ var IElementLink = function (_a) {
|
|
|
8516
8562
|
return function () {
|
|
8517
8563
|
elementSelectedListener.off();
|
|
8518
8564
|
};
|
|
8519
|
-
}, []);
|
|
8565
|
+
}, [onElementSelected, onDeselected]);
|
|
8520
8566
|
// Store onPointsChanged in a ref to avoid unnecessary re-renders
|
|
8521
8567
|
React.useEffect(function () {
|
|
8522
8568
|
onPointsChangedRef.current = onPointsChanged;
|
|
8523
8569
|
}, [onPointsChanged]);
|
|
8524
8570
|
// Notify parent component when points change
|
|
8525
8571
|
React.useEffect(function () {
|
|
8526
|
-
var _a;
|
|
8527
8572
|
if (isFirstRender.current) {
|
|
8528
8573
|
isFirstRender.current = false;
|
|
8529
8574
|
return;
|
|
8530
8575
|
}
|
|
8531
|
-
|
|
8532
|
-
}, [JSON.stringify(points)]);
|
|
8576
|
+
}, []);
|
|
8533
8577
|
React.useLayoutEffect(function () {
|
|
8534
|
-
var pointsList = __spreadArray(__spreadArray([
|
|
8578
|
+
var pointsList = __spreadArray(__spreadArray([{ x: sourcePositionX, y: sourcePositionY }], points, true), [{ x: targetPositionX, y: targetPositionY }], false);
|
|
8535
8579
|
var _pathStr = createSmoothPathString(pointsList, undefined, false);
|
|
8536
8580
|
setPathStr(_pathStr);
|
|
8537
|
-
}, [
|
|
8581
|
+
}, [sourcePositionX, sourcePositionY, points, targetPositionX, targetPositionY]);
|
|
8538
8582
|
React.useEffect(function () {
|
|
8539
8583
|
if (!pathStr)
|
|
8540
8584
|
return;
|
|
8541
8585
|
onPathChanged === null || onPathChanged === void 0 ? void 0 : onPathChanged(pathStr, id);
|
|
8542
|
-
}, [pathStr, id]);
|
|
8543
|
-
var addMovingPoint = function (mouseDownedOnPaperPos, points) {
|
|
8586
|
+
}, [pathStr, id, onPathChanged]);
|
|
8587
|
+
var addMovingPoint = React.useCallback(function (mouseDownedOnPaperPos, points) {
|
|
8544
8588
|
//Position of the new point on the path
|
|
8545
8589
|
var paperPosition = mouseDownedOnPaperPos;
|
|
8546
|
-
var newPoints = addPointToList(paperPosition, __spreadArray(__spreadArray([
|
|
8590
|
+
var newPoints = addPointToList(paperPosition, __spreadArray(__spreadArray([{ x: sourcePositionX, y: sourcePositionY }], points, true), [{ x: targetPositionX, y: targetPositionY }], false), pathRef.current);
|
|
8547
8591
|
var pointsWithoutStartEndPoint = newPoints.slice(1, newPoints.length - 1);
|
|
8548
8592
|
var addedIndex = pointsWithoutStartEndPoint.findIndex(function (p) { return p.x === paperPosition.x && p.y === paperPosition.y; });
|
|
8549
8593
|
var leftPointIndex = addedIndex - 1;
|
|
@@ -8589,12 +8633,13 @@ var IElementLink = function (_a) {
|
|
|
8589
8633
|
draggingPointIndex: _draggingPointIndex,
|
|
8590
8634
|
points: pointsWithoutStartEndPoint,
|
|
8591
8635
|
};
|
|
8592
|
-
};
|
|
8636
|
+
}, [sourcePositionX, sourcePositionY, targetPositionX, targetPositionY]);
|
|
8593
8637
|
React.useEffect(function () {
|
|
8594
8638
|
//handle when creating and moving point
|
|
8595
8639
|
var handleMouseMove = function (ev) {
|
|
8596
8640
|
var mouseEvent = ev;
|
|
8597
8641
|
if (isDragging && container) {
|
|
8642
|
+
console.info('Mouse move on link');
|
|
8598
8643
|
var paperPosition_1 = windowsPositionToPaperPosition({
|
|
8599
8644
|
x: mouseEvent.clientX,
|
|
8600
8645
|
y: mouseEvent.clientY
|
|
@@ -8614,8 +8659,13 @@ var IElementLink = function (_a) {
|
|
|
8614
8659
|
}
|
|
8615
8660
|
};
|
|
8616
8661
|
var mouseUp = function () {
|
|
8662
|
+
console.info('Mouse up on link');
|
|
8617
8663
|
draggingPointIndexRef.current = undefined;
|
|
8618
8664
|
setIsDragging(false);
|
|
8665
|
+
//trigger onPointsChanged
|
|
8666
|
+
if (onPointsChangedRef.current) {
|
|
8667
|
+
onPointsChangedRef.current(points, id);
|
|
8668
|
+
}
|
|
8619
8669
|
};
|
|
8620
8670
|
container === null || container === void 0 ? void 0 : container.addEventListener('mousemove', handleMouseMove);
|
|
8621
8671
|
container === null || container === void 0 ? void 0 : container.addEventListener('mouseup', mouseUp);
|
|
@@ -8623,9 +8673,14 @@ var IElementLink = function (_a) {
|
|
|
8623
8673
|
container === null || container === void 0 ? void 0 : container.removeEventListener('mousemove', handleMouseMove);
|
|
8624
8674
|
container === null || container === void 0 ? void 0 : container.removeEventListener('mouseup', mouseUp);
|
|
8625
8675
|
};
|
|
8626
|
-
}, [container, isDragging, zoom, points]);
|
|
8676
|
+
}, [container, isDragging, zoom, points, id, addMovingPoint]);
|
|
8677
|
+
React.useEffect(function () {
|
|
8678
|
+
console.info("Container changed in link", id);
|
|
8679
|
+
}, [addMovingPoint]);
|
|
8627
8680
|
var handleMouseDownOnPath = function (ev) {
|
|
8628
8681
|
ev.preventDefault();
|
|
8682
|
+
console.info('Mouse down on link');
|
|
8683
|
+
timeFromMouseDownToUpRef.current = Date.now();
|
|
8629
8684
|
//add point if click on path
|
|
8630
8685
|
setIsDragging(true);
|
|
8631
8686
|
};
|
|
@@ -8639,11 +8694,11 @@ var IElementLink = function (_a) {
|
|
|
8639
8694
|
onLabelMoved(newPosition.x, newPosition.y, 'middle');
|
|
8640
8695
|
break;
|
|
8641
8696
|
case sourceLabelRef.current:
|
|
8642
|
-
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY },
|
|
8697
|
+
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY }, { x: sourcePositionX, y: sourcePositionY });
|
|
8643
8698
|
onLabelMoved(newPosition.x, newPosition.y, 'source');
|
|
8644
8699
|
break;
|
|
8645
8700
|
case targetLabelRef.current:
|
|
8646
|
-
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY },
|
|
8701
|
+
newPosition = transformAbsPositionToRelativePositionInsideElement({ x: newX, y: newY }, { x: targetPositionX, y: targetPositionY });
|
|
8647
8702
|
onLabelMoved(newPosition.x, newPosition.y, 'target');
|
|
8648
8703
|
break;
|
|
8649
8704
|
}
|
|
@@ -8675,6 +8730,11 @@ var IElementLink = function (_a) {
|
|
|
8675
8730
|
}
|
|
8676
8731
|
};
|
|
8677
8732
|
var handleClickPath = function () {
|
|
8733
|
+
if (Date.now() - timeFromMouseDownToUpRef.current > 400) {
|
|
8734
|
+
//Prevent click event when dragging
|
|
8735
|
+
return;
|
|
8736
|
+
}
|
|
8737
|
+
console.info('Click link', id);
|
|
8678
8738
|
setIsSelectedLink(true);
|
|
8679
8739
|
onSelected === null || onSelected === void 0 ? void 0 : onSelected();
|
|
8680
8740
|
};
|
|
@@ -8717,22 +8777,22 @@ var IElementLink = function (_a) {
|
|
|
8717
8777
|
if ((_b = pathRef.current) === null || _b === void 0 ? void 0 : _b.getAttribute('d')) {
|
|
8718
8778
|
if (markerStart) {
|
|
8719
8779
|
markerStartPosition = pathRef.current.getPointAtLength(markerDistanceFromPort);
|
|
8720
|
-
angleMarkerStart = calculateAngleWithOx(
|
|
8780
|
+
angleMarkerStart = calculateAngleWithOx({ x: sourcePositionX, y: sourcePositionY }, markerStartPosition);
|
|
8721
8781
|
}
|
|
8722
8782
|
if (markerEnd) {
|
|
8723
8783
|
markerEndPosition = pathRef.current.getPointAtLength(pathRef.current.getTotalLength() - markerDistanceFromPort);
|
|
8724
|
-
angleMarkerEnd = calculateAngleWithOx(markerEndPosition,
|
|
8784
|
+
angleMarkerEnd = calculateAngleWithOx(markerEndPosition, { x: targetPositionX, y: targetPositionY });
|
|
8725
8785
|
}
|
|
8726
8786
|
centerPathPosition = (_c = pathRef.current) === null || _c === void 0 ? void 0 : _c.getPointAtLength(pathRef.current.getTotalLength() / 2);
|
|
8727
8787
|
}
|
|
8728
8788
|
return (React.createElement("g", null,
|
|
8729
8789
|
React.createElement("path", { ref: pathRef, d: pathStr, className: isSelectedLink ? CSS_CLASS_LINK_SELECTED : '', fill: "none", stroke: stroke || LINK_DEFAULT_COLOR, strokeWidth: strokeWidth }),
|
|
8730
8790
|
React.createElement("path", { d: pathStr, fill: "none", stroke: 'transparent', strokeWidth: LINK_CLICKABLE_STROKE_WIDTH, onClick: handleClickPath, onMouseDown: handleMouseDownOnPath }),
|
|
8731
|
-
isSelectedLink && centerPathPosition && React.createElement("svg", { x: centerPathPosition.x - 10, y: centerPathPosition.y - 10 },
|
|
8791
|
+
removable !== false && isSelectedLink && centerPathPosition && React.createElement("svg", { x: centerPathPosition.x - 10, y: centerPathPosition.y - 10 },
|
|
8732
8792
|
React.createElement(CloseIcon, { onClick: onClickDelete })),
|
|
8733
8793
|
label && renderLabel(label, 'middle', centerPathPosition),
|
|
8734
|
-
sourceLabel && renderLabel(sourceLabel, 'source',
|
|
8735
|
-
targetLabel && renderLabel(targetLabel, 'target',
|
|
8794
|
+
sourceLabel && renderLabel(sourceLabel, 'source', { x: sourcePositionX, y: sourcePositionY }),
|
|
8795
|
+
targetLabel && renderLabel(targetLabel, 'target', { x: targetPositionX, y: targetPositionY }),
|
|
8736
8796
|
markerStartPosition && React.createElement("g", { transform: "rotate(".concat(angleMarkerStart, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
|
|
8737
8797
|
React.createElement("svg", { x: markerStartPosition.x - markerSize / 2, y: markerStartPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerStart)),
|
|
8738
8798
|
markerEndPosition && React.createElement("g", { transform: "rotate(".concat(angleMarkerEnd, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
|
|
@@ -8789,58 +8849,41 @@ var ElementWrapper = React.forwardRef(function (_a, ref) {
|
|
|
8789
8849
|
});
|
|
8790
8850
|
|
|
8791
8851
|
var Element = React.forwardRef(function (props, forwardedRef) {
|
|
8792
|
-
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, textsPlaceHolderFlexStyle = props.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition = props.textsPlaceHolderFlexboxPosition, textsPlaceHolderClassName = props.textsPlaceHolderClassName, texts = props.texts, portSlideRailSVGClassName = props.portSlideRailSVGClassName, portMoveableAreas = props.portMoveableAreas, portDirection = props.portDirection, defaultPortSize = props.defaultPortSize, onClick = props.onClick, onContextMenu = props.onContextMenu, renderShape = props.renderShape; props.onMoved; var onPortMoved = props.onPortMoved; props.onResized; var onPortMouseDown = props.onPortMouseDown, onPortMouseUp = props.onPortMouseUp, onMouseMove = props.onMouseMove, onMouseLeave = props.onMouseLeave, onMouseUp = props.onMouseUp, onMouseDown = props.onMouseDown, onMouseUpAtLinkedPortPlaceholder = props.onMouseUpAtLinkedPortPlaceholder, onTextUpdated = props.onTextUpdated, onPortContextMenu = props.onPortContextMenu, onPortsChanged = props.onPortsChanged, onManuallyTriggerRenderPort = props.onManuallyTriggerRenderPort;
|
|
8793
|
-
var propPorts = props.ports;
|
|
8794
|
-
var _a = React.useState(), selectedPort = _a[0], setSelectedPort = _a[1];
|
|
8795
|
-
var _b = React.useState(), hoveredPort = _b[0], setHoveredPort = _b[1];
|
|
8796
|
-
var _c = React.useState((propPorts === null || propPorts === void 0 ? void 0 : propPorts.map(function (p) {
|
|
8797
|
-
var portState = __assign(__assign({}, p), { ref: React.createRef() });
|
|
8798
|
-
return portState;
|
|
8799
|
-
})) || []), ports = _c[0], setPorts = _c[1];
|
|
8800
|
-
var _d = React.useState(false), someElementLinkStarted = _d[0], setSomeElementLinkStarted = _d[1];
|
|
8801
|
-
var _e = React.useState(), potentialPortPosition = _e[0], setPotentialPortPosition = _e[1];
|
|
8802
8852
|
var _paperEventEmitterContext = React.useContext(paperEventEmitterContext);
|
|
8853
|
+
// const elementObj = props.element;
|
|
8854
|
+
var beingSelected = props.beingSelected, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container, onMouseUp = props.onMouseUp, onMouseDown = props.onMouseDown, onMouseLeave = props.onMouseLeave, onMouseMove = props.onMouseMove, onMoving = props.onMoving, onMoved = props.onMoved, onResized = props.onResized, onPortMoved = props.onPortMoved, onPortMouseDown = props.onPortMouseDown, onPortMouseUp = props.onPortMouseUp, onClick = props.onClick, onContextMenu = props.onContextMenu, onPortContextMenu = props.onPortContextMenu, onMouseUpAtLinkedPortPlaceholder = props.onMouseUpAtLinkedPortPlaceholder, onManuallyTriggerRenderPort = props.onManuallyTriggerRenderPort, draggingByDefault = props.draggingByDefault, parentDOM = props.parentDOM;
|
|
8855
|
+
var _a = props.element, id = _a.id, cssClass = _a.cssClass, textsPlaceHolderClassName = _a.textsPlaceHolderClassName, portSlideRailSVGClassName = _a.portSlideRailSVGClassName, portMoveableAreas = _a.portMoveableAreas, portDirection = _a.portDirection, defaultPortSize = _a.defaultPortSize, textsPlaceHolderFlexStyle = _a.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition = _a.textsPlaceHolderFlexboxPosition, resizability = _a.resizability, renderShape = _a.renderShape;
|
|
8856
|
+
var propPorts = props.element.ports;
|
|
8857
|
+
//state for position
|
|
8858
|
+
var _b = React.useState(__assign({}, props.element.position)), position = _b[0], setPosition = _b[1];
|
|
8859
|
+
//state for size
|
|
8860
|
+
var _c = React.useState(__assign({}, props.element.size)), size = _c[0], setSize = _c[1];
|
|
8861
|
+
var _d = React.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
|
|
8862
|
+
var _e = React.useState(), hoveredPort = _e[0], setHoveredPort = _e[1];
|
|
8863
|
+
var _f = React.useState([]), ports = _f[0], setPorts = _f[1];
|
|
8864
|
+
var _g = React.useState(props.element.texts || []), texts = _g[0], setTexts = _g[1];
|
|
8865
|
+
var _h = React.useState(false), someElementLinkStarted = _h[0], setSomeElementLinkStarted = _h[1];
|
|
8866
|
+
var _j = React.useState(), potentialPortPosition = _j[0], setPotentialPortPosition = _j[1];
|
|
8867
|
+
//Zoom
|
|
8803
8868
|
var zoom = useZoomContext().zoom;
|
|
8869
|
+
var zoomRef = React.useRef(zoom);
|
|
8804
8870
|
var elementRef = React.useRef(null);
|
|
8805
8871
|
React.useImperativeHandle(forwardedRef, function () { return elementRef.current; });
|
|
8806
8872
|
var elementLinkStarted = React.useRef();
|
|
8807
|
-
var portsRef = React.useRef(
|
|
8808
|
-
var getElementAbsPosition = React.useCallback(function () {
|
|
8809
|
-
var position = {
|
|
8810
|
-
x: x,
|
|
8811
|
-
y: y,
|
|
8812
|
-
};
|
|
8813
|
-
if (parentAbsolutePosition) {
|
|
8814
|
-
position.x += parentAbsolutePosition.x;
|
|
8815
|
-
position.y += parentAbsolutePosition.y;
|
|
8816
|
-
}
|
|
8817
|
-
return position;
|
|
8818
|
-
}, [x, y, parentAbsolutePosition]);
|
|
8819
|
-
var elementAbsPosition = React.useMemo(function () { return getElementAbsPosition(); }, [getElementAbsPosition]);
|
|
8820
|
-
//Listen to manually trigger render event
|
|
8821
|
-
React.useEffect(function () {
|
|
8822
|
-
var off = onManuallyTriggerRenderPort === null || onManuallyTriggerRenderPort === void 0 ? void 0 : onManuallyTriggerRenderPort(function (portId, elementId) {
|
|
8823
|
-
if (elementId !== id)
|
|
8824
|
-
return;
|
|
8825
|
-
logger.info('onManuallyTriggerRenderPort', id);
|
|
8826
|
-
setPorts(function (prev) { return __spreadArray([], prev, true); });
|
|
8827
|
-
});
|
|
8828
|
-
return function () {
|
|
8829
|
-
off === null || off === void 0 ? void 0 : off();
|
|
8830
|
-
};
|
|
8831
|
-
}, [id, onManuallyTriggerRenderPort]);
|
|
8873
|
+
var portsRef = React.useRef([]);
|
|
8832
8874
|
//Normalize port position
|
|
8833
8875
|
var normalizePortPosition = React.useCallback(function (tempNewPosition) {
|
|
8834
|
-
var newPosition = correctPortPositionInElement(tempNewPosition, width, height, portMoveableAreas, portSlideRailSVGClassName, elementRef.current || undefined);
|
|
8876
|
+
var newPosition = correctPortPositionInElement(tempNewPosition, size.width, size.height, portMoveableAreas, portSlideRailSVGClassName, elementRef.current || undefined);
|
|
8835
8877
|
return newPosition || tempNewPosition;
|
|
8836
|
-
}, [width, height, portMoveableAreas, portSlideRailSVGClassName]);
|
|
8837
|
-
//
|
|
8838
|
-
React.
|
|
8878
|
+
}, [size.width, size.height, portMoveableAreas, portSlideRailSVGClassName]);
|
|
8879
|
+
//set port ref when ports state is changed
|
|
8880
|
+
React.useLayoutEffect(function () {
|
|
8881
|
+
portsRef.current = ports;
|
|
8882
|
+
}, [ports]);
|
|
8883
|
+
//Handle ports state when propPorts is changed
|
|
8884
|
+
var handlePortsState = React.useCallback(function (newPorts) {
|
|
8839
8885
|
setPorts(function (prev) {
|
|
8840
|
-
var
|
|
8841
|
-
if (propPorts === undefined)
|
|
8842
|
-
return [];
|
|
8843
|
-
var newState = (_a = propPorts.map(function (p, index) {
|
|
8886
|
+
var newState = newPorts === null || newPorts === void 0 ? void 0 : newPorts.map(function (p, index) {
|
|
8844
8887
|
var prevPortState = prev.find(function (_p) { return _p.id === p.id; });
|
|
8845
8888
|
var newPortState;
|
|
8846
8889
|
//If port is existed, keep the ref of the port
|
|
@@ -8853,45 +8896,85 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
8853
8896
|
//Handle the case new port is created and the ref of the port is not defined
|
|
8854
8897
|
if (!newPortState.ref) {
|
|
8855
8898
|
var newPosition = normalizePortPosition(newPortState.position);
|
|
8856
|
-
|
|
8857
|
-
_paperEventEmitterContext.emitPortMoved(p, id, newPortState.position, newPosition)
|
|
8899
|
+
// onPortMoved?.(p, id, newPortState.position, newPosition)
|
|
8900
|
+
// _paperEventEmitterContext.emitPortMoved(p, id, newPortState.position, newPosition)
|
|
8858
8901
|
newPortState.position = newPosition;
|
|
8859
8902
|
newPortState.ref = React.createRef();
|
|
8860
8903
|
}
|
|
8861
8904
|
return newPortState;
|
|
8862
|
-
})
|
|
8905
|
+
});
|
|
8863
8906
|
return newState;
|
|
8864
8907
|
});
|
|
8865
|
-
}, [
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8908
|
+
}, [normalizePortPosition]);
|
|
8909
|
+
var getParentAbsolutePosition = React.useCallback(function () {
|
|
8910
|
+
return props.element.parentElement ? getAbsolutePosition(props.element.parentElement) : undefined;
|
|
8911
|
+
}, [props.element.parentElement]);
|
|
8912
|
+
var getElementAbsPosition = React.useCallback(function () {
|
|
8913
|
+
var newPosition = {
|
|
8914
|
+
x: position.x,
|
|
8915
|
+
y: position.y,
|
|
8916
|
+
};
|
|
8917
|
+
var parentAbsolutePosition = getParentAbsolutePosition();
|
|
8918
|
+
if (parentAbsolutePosition) {
|
|
8919
|
+
newPosition.x += parentAbsolutePosition.x;
|
|
8920
|
+
newPosition.y += parentAbsolutePosition.y;
|
|
8921
|
+
}
|
|
8922
|
+
return newPosition;
|
|
8923
|
+
}, [position, getParentAbsolutePosition]);
|
|
8924
|
+
var elementAbsPosition = React.useMemo(function () { return getElementAbsPosition(); }, [getElementAbsPosition]);
|
|
8925
|
+
//update element position
|
|
8926
|
+
var updateElementPosition = React.useCallback(function (newPosition) {
|
|
8927
|
+
setPosition({ x: newPosition.x, y: newPosition.y });
|
|
8928
|
+
props.element.position = { x: newPosition.x, y: newPosition.y };
|
|
8929
|
+
}, [props.element]);
|
|
8930
|
+
//update element size
|
|
8931
|
+
var updateElementSize = React.useCallback(function (newSize) {
|
|
8932
|
+
setSize({ width: newSize.width, height: newSize.height });
|
|
8933
|
+
props.element.size = { width: newSize.width, height: newSize.height };
|
|
8934
|
+
}, [props.element]);
|
|
8935
|
+
//Listen to manually trigger render event
|
|
8871
8936
|
React.useEffect(function () {
|
|
8872
|
-
var
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
return port;
|
|
8937
|
+
var off = onManuallyTriggerRenderPort === null || onManuallyTriggerRenderPort === void 0 ? void 0 : onManuallyTriggerRenderPort(function (portId, elementId) {
|
|
8938
|
+
if (elementId !== id)
|
|
8939
|
+
return;
|
|
8940
|
+
logger.info('onManuallyTriggerRenderPort', id);
|
|
8941
|
+
handlePortsState(portsRef.current);
|
|
8878
8942
|
});
|
|
8879
|
-
|
|
8880
|
-
|
|
8943
|
+
return function () {
|
|
8944
|
+
off === null || off === void 0 ? void 0 : off();
|
|
8945
|
+
};
|
|
8946
|
+
}, [id, onManuallyTriggerRenderPort, handlePortsState, props.element]);
|
|
8947
|
+
//Initialize ports state
|
|
8948
|
+
React.useEffect(function () {
|
|
8949
|
+
handlePortsState(propPorts || []);
|
|
8950
|
+
}, [handlePortsState, propPorts]);
|
|
8951
|
+
// const normalizePortsPosition = useCallback(() => {
|
|
8952
|
+
// const newPorts = portsRef.current.map(port => {
|
|
8953
|
+
// const newPosition = normalizePortPosition(port.position);
|
|
8954
|
+
// port.position = newPosition;
|
|
8955
|
+
// return port;
|
|
8956
|
+
// });
|
|
8957
|
+
// return newPorts;
|
|
8958
|
+
// }, [normalizePortPosition]);
|
|
8959
|
+
// //Normalize port position when element is resized
|
|
8960
|
+
// useEffect(() => {
|
|
8961
|
+
// //const newPorts = normalizePortsPosition();
|
|
8962
|
+
// //handlePortsState(newPorts);
|
|
8963
|
+
// }, [size, _paperEventEmitterContext, id, normalizePortPosition, onPortMoved, normalizePortsPosition, handlePortsState]);
|
|
8881
8964
|
//Listen trigger of Delete key, handle delete port is selected
|
|
8882
8965
|
React.useEffect(function () {
|
|
8883
8966
|
var listener = _paperEventEmitterContext.onCommandDeleteSelectedPort(function () {
|
|
8884
|
-
if (selectedPort) {
|
|
8967
|
+
if (selectedPort && selectedPort.removable !== false) {
|
|
8885
8968
|
var newPorts = portsRef.current.filter(function (p) { return p.id !== selectedPort.id; });
|
|
8886
|
-
|
|
8969
|
+
handlePortsState(newPorts);
|
|
8887
8970
|
setSelectedPort(undefined);
|
|
8888
|
-
onPortsChanged
|
|
8971
|
+
//onPortsChanged?.(newPorts, id)
|
|
8889
8972
|
}
|
|
8890
8973
|
});
|
|
8891
8974
|
return function () {
|
|
8892
8975
|
listener.off();
|
|
8893
8976
|
};
|
|
8894
|
-
}, [_paperEventEmitterContext, id,
|
|
8977
|
+
}, [_paperEventEmitterContext, id, selectedPort, handlePortsState, props.element.ports]);
|
|
8895
8978
|
React.useEffect(function () {
|
|
8896
8979
|
//Listener onMouseDown event on #paper-container
|
|
8897
8980
|
var eventListener = _paperEventEmitterContext.onPaperClicked(function (ev) {
|
|
@@ -8904,26 +8987,38 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
8904
8987
|
React.useEffect(function () {
|
|
8905
8988
|
//listen element resize to update position of the ports by element size.
|
|
8906
8989
|
var eleResizeListener = _paperEventEmitterContext.onElementResized(id, function () {
|
|
8907
|
-
|
|
8990
|
+
//let isChanged = false;
|
|
8908
8991
|
var newPorts = portsRef.current.map(function (port) {
|
|
8909
8992
|
var newPosition = normalizePortPosition({ x: port.position.x, y: port.position.y });
|
|
8910
8993
|
//Check port moved
|
|
8911
8994
|
if (port.position.x !== newPosition.x || port.position.y !== newPosition.y) {
|
|
8912
|
-
isChanged = true;
|
|
8995
|
+
//isChanged = true;
|
|
8913
8996
|
_paperEventEmitterContext.emitPortMoved(port, id, port.position, newPosition);
|
|
8914
8997
|
}
|
|
8915
8998
|
port.position = newPosition;
|
|
8916
8999
|
return port;
|
|
8917
9000
|
});
|
|
8918
|
-
|
|
8919
|
-
if (isChanged) {
|
|
8920
|
-
|
|
8921
|
-
}
|
|
9001
|
+
handlePortsState(newPorts);
|
|
9002
|
+
// if (isChanged) {
|
|
9003
|
+
// onPortsChanged?.(newPorts, id);
|
|
9004
|
+
// }
|
|
8922
9005
|
});
|
|
8923
9006
|
return function () {
|
|
8924
9007
|
eleResizeListener.off();
|
|
8925
9008
|
};
|
|
8926
|
-
}, [_paperEventEmitterContext, id,
|
|
9009
|
+
}, [_paperEventEmitterContext, id, normalizePortPosition, size, portMoveableAreas, portSlideRailSVGClassName, handlePortsState, props.element.ports]);
|
|
9010
|
+
//list to port added
|
|
9011
|
+
React.useEffect(function () {
|
|
9012
|
+
var _a, _b;
|
|
9013
|
+
//Listen a new port added, then re-render the element component
|
|
9014
|
+
var off = (_b = (_a = props.element).onAddedPort) === null || _b === void 0 ? void 0 : _b.call(_a, function (newPort) {
|
|
9015
|
+
logger.info("A new port has been added to element ".concat(id));
|
|
9016
|
+
handlePortsState(props.element.ports || []);
|
|
9017
|
+
});
|
|
9018
|
+
return function () {
|
|
9019
|
+
off === null || off === void 0 ? void 0 : off();
|
|
9020
|
+
};
|
|
9021
|
+
}, [handlePortsState, id, props.element]);
|
|
8927
9022
|
//Listen creating element link started, ended.
|
|
8928
9023
|
React.useEffect(function () {
|
|
8929
9024
|
var elementStartedListener = _paperEventEmitterContext.onElementLinkStarted(function (tempLink) {
|
|
@@ -8973,30 +9068,30 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
8973
9068
|
var handleSelectedPort = React.useCallback(function (portId, e) {
|
|
8974
9069
|
e.stopPropagation();
|
|
8975
9070
|
logger.debug('Port selected', portId, e);
|
|
8976
|
-
var port =
|
|
9071
|
+
var port = ports.find(function (p) { return p.id === portId; });
|
|
8977
9072
|
if (!port)
|
|
8978
9073
|
return;
|
|
8979
9074
|
setSelectedPort(port);
|
|
8980
9075
|
_paperEventEmitterContext.emitPortSelected(port, id);
|
|
8981
|
-
}, [id, _paperEventEmitterContext]);
|
|
9076
|
+
}, [ports, id, _paperEventEmitterContext]);
|
|
8982
9077
|
//Calculate the position of the 4 vertices of a rectangle relative to element
|
|
8983
9078
|
var calculateSlideRailRectSVGPositions = React.useCallback(function (slideRailSVG) {
|
|
8984
9079
|
var coordinates = getRectangleCorners(slideRailSVG);
|
|
8985
9080
|
var ownerSVG = slideRailSVG.ownerSVGElement;
|
|
8986
9081
|
var rotationAngle = getElementRotationInfo(ownerSVG);
|
|
8987
9082
|
if (rotationAngle !== 0) {
|
|
8988
|
-
var rotationCenterX = width / 2;
|
|
8989
|
-
var rotationCenterY = height / 2;
|
|
9083
|
+
var rotationCenterX = size.width / 2;
|
|
9084
|
+
var rotationCenterY = size.height / 2;
|
|
8990
9085
|
coordinates = getRotatedRectangleCoordinates(coordinates, rotationCenterX, rotationCenterY, rotationAngle);
|
|
8991
9086
|
}
|
|
8992
9087
|
return coordinates;
|
|
8993
|
-
}, [
|
|
9088
|
+
}, [size]);
|
|
8994
9089
|
var getSlideRailSVG = React.useCallback(function (portSlideRailSVGClassName) {
|
|
8995
9090
|
var _a;
|
|
8996
9091
|
var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
|
|
8997
9092
|
return slideRailSVG;
|
|
8998
9093
|
}, []);
|
|
8999
|
-
var handlePortMove = function (newX, newY) {
|
|
9094
|
+
var handlePortMove = React.useCallback(function (newX, newY) {
|
|
9000
9095
|
if (!selectedPort)
|
|
9001
9096
|
return;
|
|
9002
9097
|
var oldPosition = __assign({}, selectedPort.position);
|
|
@@ -9008,13 +9103,14 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
9008
9103
|
var newPosition = normalizePortPosition(tempNewPosition);
|
|
9009
9104
|
if (newPosition) {
|
|
9010
9105
|
selectedPort.position = newPosition;
|
|
9011
|
-
onPortMoved
|
|
9012
|
-
|
|
9106
|
+
//onPortMoved?.(selectedPort, id, oldPosition, newPosition)
|
|
9107
|
+
handlePortsState(portsRef.current);
|
|
9013
9108
|
if (_paperEventEmitterContext.emitter.listenerCount(EVENT_NAME.PORT_MOVED) > 0) {
|
|
9014
9109
|
_paperEventEmitterContext.emitPortMoved(selectedPort, id, oldPosition, newPosition);
|
|
9015
9110
|
}
|
|
9111
|
+
onPortMoved === null || onPortMoved === void 0 ? void 0 : onPortMoved(selectedPort, id, oldPosition, newPosition);
|
|
9016
9112
|
}
|
|
9017
|
-
};
|
|
9113
|
+
}, [selectedPort, elementAbsPosition, normalizePortPosition, _paperEventEmitterContext, id, onPortMoved, handlePortsState]);
|
|
9018
9114
|
//Handle when mouse down on port
|
|
9019
9115
|
var handlePortMouseDown = React.useCallback(function (portId, e) {
|
|
9020
9116
|
e.stopPropagation();
|
|
@@ -9025,7 +9121,7 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
9025
9121
|
return;
|
|
9026
9122
|
_paperEventEmitterContext.emitPortMouseDown(e, port, id);
|
|
9027
9123
|
onPortMouseDown === null || onPortMouseDown === void 0 ? void 0 : onPortMouseDown(e, port, id);
|
|
9028
|
-
}, [id,
|
|
9124
|
+
}, [id, _paperEventEmitterContext, onPortMouseDown]);
|
|
9029
9125
|
//Handle when mouse up on port
|
|
9030
9126
|
var handlePortMouseUp = React.useCallback(function (portId, e) {
|
|
9031
9127
|
e.stopPropagation();
|
|
@@ -9038,50 +9134,44 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
9038
9134
|
if (potentialPortPosition) {
|
|
9039
9135
|
setPotentialPortPosition(undefined);
|
|
9040
9136
|
}
|
|
9041
|
-
}, [id, onPortMouseUp,
|
|
9137
|
+
}, [_paperEventEmitterContext, id, onPortMouseUp, potentialPortPosition]);
|
|
9042
9138
|
//Update state when label of port is moved
|
|
9043
9139
|
var handlePortLabelMoved = React.useCallback(function (newX, newY, portId) {
|
|
9044
|
-
|
|
9045
|
-
|
|
9046
|
-
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
});
|
|
9058
|
-
}, []);
|
|
9140
|
+
handlePortsState(portsRef.current.map(function (p) {
|
|
9141
|
+
if (p.id === portId && p.label) {
|
|
9142
|
+
var newLabel = Object.assign(Object.create(Object.getPrototypeOf(p.label)), p.label);
|
|
9143
|
+
var newPosition = {
|
|
9144
|
+
x: newX,
|
|
9145
|
+
y: newY
|
|
9146
|
+
};
|
|
9147
|
+
newLabel.position = newPosition;
|
|
9148
|
+
p.label = newLabel;
|
|
9149
|
+
}
|
|
9150
|
+
return p;
|
|
9151
|
+
}));
|
|
9152
|
+
}, [handlePortsState]);
|
|
9059
9153
|
//Update state when label of port is resized
|
|
9060
9154
|
var handlePortLabelResized = React.useCallback(function (width, height, portId) {
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
});
|
|
9072
|
-
}, []);
|
|
9155
|
+
handlePortsState(portsRef.current.map(function (p) {
|
|
9156
|
+
if (p.id === portId && p.label) {
|
|
9157
|
+
p.label.size = {
|
|
9158
|
+
width: width,
|
|
9159
|
+
height: height
|
|
9160
|
+
};
|
|
9161
|
+
}
|
|
9162
|
+
return p;
|
|
9163
|
+
}));
|
|
9164
|
+
}, [handlePortsState]);
|
|
9073
9165
|
//Update state when label of port is changed content
|
|
9074
9166
|
var handlePortLabelContentChanged = React.useCallback(function (ev, newValue, portId) {
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
}, []);
|
|
9084
|
-
function handleElementMouseMove(ev) {
|
|
9167
|
+
handlePortsState(portsRef.current.map(function (p) {
|
|
9168
|
+
if (p.id === portId && p.label) {
|
|
9169
|
+
p.label.content = newValue;
|
|
9170
|
+
}
|
|
9171
|
+
return p;
|
|
9172
|
+
}));
|
|
9173
|
+
}, [handlePortsState]);
|
|
9174
|
+
var handleElementMouseMove = React.useCallback(function (ev) {
|
|
9085
9175
|
//ev.stopPropagation(); //Can't use stopPropagation here, because do not create tempLink
|
|
9086
9176
|
onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove(ev, id);
|
|
9087
9177
|
if (someElementLinkStarted && elementRef.current) {
|
|
@@ -9108,19 +9198,19 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
9108
9198
|
setPotentialPortPosition(undefined);
|
|
9109
9199
|
}
|
|
9110
9200
|
}
|
|
9111
|
-
}
|
|
9112
|
-
|
|
9201
|
+
}, [onMouseMove, id, someElementLinkStarted, container, zoom, getElementAbsPosition, normalizePortPosition, hoveredPort]);
|
|
9202
|
+
var handleElementMouseLeave = React.useCallback(function (ev) {
|
|
9113
9203
|
ev.stopPropagation();
|
|
9114
9204
|
onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(ev, id);
|
|
9115
9205
|
if (someElementLinkStarted) { //If an element link is being created, clear the placeholder when the mouse leaves the element.
|
|
9116
9206
|
setPotentialPortPosition(undefined);
|
|
9117
9207
|
}
|
|
9118
|
-
}
|
|
9119
|
-
var handleElementMouseDown = function (ev) {
|
|
9208
|
+
}, [onMouseLeave, id, someElementLinkStarted]);
|
|
9209
|
+
var handleElementMouseDown = React.useCallback(function (ev) {
|
|
9120
9210
|
ev.stopPropagation();
|
|
9121
9211
|
onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(ev, id);
|
|
9122
|
-
};
|
|
9123
|
-
var handleElementMouseUp = function (ev) {
|
|
9212
|
+
}, [onMouseDown, id]);
|
|
9213
|
+
var handleElementMouseUp = React.useCallback(function (ev) {
|
|
9124
9214
|
ev.stopPropagation();
|
|
9125
9215
|
onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(ev, id);
|
|
9126
9216
|
//If an element link is being created, trigger onMouseUpAtLinkedPortPlaceholder when the mouse up the element.
|
|
@@ -9129,16 +9219,16 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
9129
9219
|
onMouseUpAtLinkedPortPlaceholder === null || onMouseUpAtLinkedPortPlaceholder === void 0 ? void 0 : onMouseUpAtLinkedPortPlaceholder(newElementLink, potentialPortPosition, id);
|
|
9130
9220
|
elementLinkStarted.current = undefined;
|
|
9131
9221
|
}
|
|
9132
|
-
};
|
|
9222
|
+
}, [potentialPortPosition, elementLinkStarted, onMouseUpAtLinkedPortPlaceholder, id]);
|
|
9133
9223
|
//Handle when mouse move on port
|
|
9134
9224
|
var handlePortMouseMove = React.useCallback(function (portId) {
|
|
9135
9225
|
if (someElementLinkStarted) {
|
|
9136
|
-
var port =
|
|
9226
|
+
var port = ports.find(function (p) { return p.id === portId; });
|
|
9137
9227
|
if (!port)
|
|
9138
9228
|
return;
|
|
9139
9229
|
setHoveredPort(port);
|
|
9140
9230
|
}
|
|
9141
|
-
}, [someElementLinkStarted]);
|
|
9231
|
+
}, [someElementLinkStarted, ports]);
|
|
9142
9232
|
//Handle when mouse leave on port
|
|
9143
9233
|
var handlePortMouseLeave = React.useCallback(function () {
|
|
9144
9234
|
if (someElementLinkStarted)
|
|
@@ -9147,11 +9237,11 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
9147
9237
|
//Handle when context menu is opened on port
|
|
9148
9238
|
var handlePortContextMenu = React.useCallback(function (portId, e) {
|
|
9149
9239
|
e.preventDefault();
|
|
9150
|
-
var port =
|
|
9240
|
+
var port = ports.find(function (p) { return p.id === portId; });
|
|
9151
9241
|
if (!port)
|
|
9152
9242
|
return;
|
|
9153
9243
|
onPortContextMenu === null || onPortContextMenu === void 0 ? void 0 : onPortContextMenu(port, id, e);
|
|
9154
|
-
}, [onPortContextMenu, id]);
|
|
9244
|
+
}, [ports, onPortContextMenu, id]);
|
|
9155
9245
|
//Get rotate angle of port by port direction is defined.
|
|
9156
9246
|
var rotatePort = React.useCallback(function (x, y) {
|
|
9157
9247
|
// logger.info('calculating port rotation', x, y)
|
|
@@ -9166,8 +9256,8 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
9166
9256
|
switch (portDirection) {
|
|
9167
9257
|
case exports.SubObjectDirection.Radial:
|
|
9168
9258
|
var center = {
|
|
9169
|
-
x: width / 2,
|
|
9170
|
-
y: height / 2
|
|
9259
|
+
x: size.width / 2,
|
|
9260
|
+
y: size.height / 2
|
|
9171
9261
|
};
|
|
9172
9262
|
rotationAngle = calculateAngleWithOx(normalizedPosition, center);
|
|
9173
9263
|
break;
|
|
@@ -9192,46 +9282,149 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
9192
9282
|
break;
|
|
9193
9283
|
}
|
|
9194
9284
|
return rotationAngle;
|
|
9195
|
-
}, [width, height, portSlideRailSVGClassName, portDirection, getSlideRailSVG, normalizePortPosition, calculateSlideRailRectSVGPositions]);
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
|
|
9285
|
+
}, [size.width, size.height, portSlideRailSVGClassName, portDirection, getSlideRailSVG, normalizePortPosition, calculateSlideRailRectSVGPositions]);
|
|
9286
|
+
// const prevElms = elementsRef.current;
|
|
9287
|
+
var handleTextChanged = React.useCallback(function (textId, content) {
|
|
9288
|
+
var textToUpdate = texts === null || texts === void 0 ? void 0 : texts.find(function (t) { return t.id === textId; });
|
|
9289
|
+
if (!textToUpdate)
|
|
9290
|
+
return;
|
|
9291
|
+
textToUpdate.content = content;
|
|
9292
|
+
setTexts(__spreadArray([], texts, true));
|
|
9293
|
+
}, [texts]);
|
|
9294
|
+
// const renderedShape = useMemo(() => {
|
|
9295
|
+
// if (renderShape) return renderShape(props);
|
|
9296
|
+
// return null;
|
|
9297
|
+
// }, [props, size, position, renderShape])
|
|
9298
|
+
var adjustElementPositionOnParentPortArea = React.useCallback(function (toBeAdjustedPosition, isAbsolutePosition) {
|
|
9299
|
+
if (isAbsolutePosition === void 0) { isAbsolutePosition = false; }
|
|
9300
|
+
if (props.element.moveAsPortOnParent && props.element.parentElement && parentDOM) {
|
|
9301
|
+
var newRelativePosition = {
|
|
9302
|
+
x: toBeAdjustedPosition.x,
|
|
9303
|
+
y: toBeAdjustedPosition.y
|
|
9304
|
+
};
|
|
9305
|
+
if (isAbsolutePosition) {
|
|
9306
|
+
newRelativePosition = transformAbsPositionToElementRelativePosition(toBeAdjustedPosition, props.element);
|
|
9307
|
+
}
|
|
9308
|
+
return correctPortPositionInElement(newRelativePosition, props.element.size.width, props.element.size.height, props.element.parentElement.portMoveableAreas, props.element.parentElement.portSlideRailSVGClassName, parentDOM);
|
|
9309
|
+
}
|
|
9310
|
+
return toBeAdjustedPosition;
|
|
9311
|
+
}, [props.element, parentDOM]);
|
|
9312
|
+
//update absolute position of element and absolute position of children elements
|
|
9313
|
+
// const updateElementPosition = (element: IElementInTreeState, x: number, y: number, isRelativePosition?: boolean): IElementInTreeState => {
|
|
9314
|
+
// if (isRelativePosition) {
|
|
9315
|
+
// element.position.x = x;
|
|
9316
|
+
// element.position.y = y;
|
|
9317
|
+
// } else {
|
|
9318
|
+
// const relativePosition = transformAbsPositionToElementRelativePosition({ x, y }, element)
|
|
9319
|
+
// element.position.x = relativePosition.x;
|
|
9320
|
+
// element.position.y = relativePosition.y;
|
|
9321
|
+
// }
|
|
9322
|
+
// return element;
|
|
9323
|
+
// }
|
|
9201
9324
|
//Re-render port again after rendered to automation rotate port
|
|
9202
9325
|
//Because elementRef.current equals null in first render so automation rotate port is incorrect.
|
|
9203
9326
|
//TODO: check if this is still needed -> Still needed
|
|
9204
9327
|
// useLayoutEffect(() => {
|
|
9205
9328
|
// if (elementRef.current) {
|
|
9206
|
-
//
|
|
9329
|
+
// handlePortsState(portsRef.current);
|
|
9207
9330
|
// }
|
|
9208
|
-
// }, [])
|
|
9209
|
-
//
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
: 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 :
|
|
9217
|
-
ports.map(function (p, index) {
|
|
9218
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9219
|
-
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, calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: handlePortLabelMoved, onPortLabelResized: handlePortLabelResized, onPortLabelContentChanged: handlePortLabelContentChanged, onSelected: handleSelectedPort, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, onMouseMove: handlePortMouseMove, onMouseLeave: handlePortMouseLeave, onContextMenu: handlePortContextMenu, renderShape: p.renderShape },
|
|
9220
|
-
selectedPort && selectedPort.id === p.id && (hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.id) !== p.id &&
|
|
9221
|
-
(React.createElement(SelectionFrame, { container: container, targetSVGElement: ((_g = selectedPort === null || selectedPort === void 0 ? void 0 : selectedPort.ref) === null || _g === void 0 ? void 0 : _g.current) || undefined, resizability: {
|
|
9222
|
-
enabled: false,
|
|
9223
|
-
keepRatio: false
|
|
9224
|
-
}, objectX: elementAbsPosition.x + selectedPort.position.x, objectY: elementAbsPosition.y + selectedPort.position.y, onMove: handlePortMove, zoom: zoom })),
|
|
9225
|
-
hoveredPort && hoveredPort.id === p.id && (React.createElement(SelectionFrame, { container: container, targetSVGElement: ((_h = hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.ref) === null || _h === void 0 ? void 0 : _h.current) || undefined, resizability: {
|
|
9331
|
+
// }, [handlePortsState])
|
|
9332
|
+
//cache render ports
|
|
9333
|
+
var renderedPorts = React.useMemo(function () {
|
|
9334
|
+
return ports === null || ports === void 0 ? void 0 : ports.map(function (p, index) {
|
|
9335
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9336
|
+
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, calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: handlePortLabelMoved, onPortLabelResized: handlePortLabelResized, onPortLabelContentChanged: handlePortLabelContentChanged, onSelected: handleSelectedPort, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, onMouseMove: handlePortMouseMove, onMouseLeave: handlePortMouseLeave, onContextMenu: handlePortContextMenu, renderShape: p.renderShape },
|
|
9337
|
+
selectedPort && selectedPort.id === p.id && (hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.id) !== p.id &&
|
|
9338
|
+
(React.createElement(SelectionFrame, { container: container, targetSVGElement: ((_g = p.ref) === null || _g === void 0 ? void 0 : _g.current) || undefined, resizability: {
|
|
9226
9339
|
enabled: false,
|
|
9227
9340
|
keepRatio: false
|
|
9228
|
-
}, zoom: zoom }))
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9341
|
+
}, objectX: elementAbsPosition.x + selectedPort.position.x, objectY: elementAbsPosition.y + selectedPort.position.y, onMove: handlePortMove, zoom: zoom })),
|
|
9342
|
+
hoveredPort && hoveredPort.id === p.id && (React.createElement(SelectionFrame, { container: container, targetSVGElement: ((_h = hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.ref) === null || _h === void 0 ? void 0 : _h.current) || undefined, resizability: {
|
|
9343
|
+
enabled: false,
|
|
9344
|
+
keepRatio: false
|
|
9345
|
+
}, zoom: zoom })));
|
|
9346
|
+
});
|
|
9347
|
+
}, [ports, elementAbsPosition, defaultPortSize, container, rotatePort, handlePortLabelMoved, handlePortLabelResized, handlePortLabelContentChanged, handleSelectedPort, handlePortMouseDown, handlePortMouseUp, handlePortMouseMove, handlePortMouseLeave, handlePortContextMenu, selectedPort, hoveredPort, handlePortMove, zoom]);
|
|
9348
|
+
//cache render texts
|
|
9349
|
+
var renderedTexts = React.useMemo(function () {
|
|
9350
|
+
return texts === null || texts === void 0 ? void 0 : texts.map(function (t, index) {
|
|
9351
|
+
var _a, _b;
|
|
9352
|
+
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, selectable: t.selectable, align: t.align, fontSize: t.fontSize, border: t.border, container: container, style: t.style, parentAbsolutePosition: elementAbsPosition, onContentChanged: function (ev, newContent) { return handleTextChanged(t.id, newContent); } });
|
|
9353
|
+
});
|
|
9354
|
+
}, [id, texts, container, elementAbsPosition, handleTextChanged]);
|
|
9355
|
+
//log element render
|
|
9356
|
+
logger.debug('Rendering Element', id, position.x, position.y, size.width, size.height, cssClass, portPlaceholderShape, children, container, getParentAbsolutePosition(), textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition, textsPlaceHolderClassName, texts, ports, portSlideRailSVGClassName, portMoveableAreas, portDirection, defaultPortSize);
|
|
9357
|
+
return (React.createElement(ElementWrapper, { key: "ElementWrapper", ref: elementRef, x: position.x, y: position.y, cssClass: cssClass, onClick: function (e) { return onClick ? onClick(id, e, elementRef.current) : true; }, onMouseMove: handleElementMouseMove, onMouseLeave: handleElementMouseLeave, onMouseDown: handleElementMouseDown, onMouseUp: handleElementMouseUp, onContextMenu: function (e) { return onContextMenu ? onContextMenu(id, e, elementRef.current) : true; } }, renderShape === null || renderShape === void 0 ? void 0 :
|
|
9358
|
+
renderShape(props),
|
|
9359
|
+
!!container && !!beingSelected &&
|
|
9360
|
+
React.createElement(SelectionFrame, { key: id, container: container, targetSVGElement: elementRef.current || undefined, resizability: resizability || {
|
|
9361
|
+
enabled: true,
|
|
9362
|
+
keepRatio: true
|
|
9363
|
+
}, objectX: elementAbsPosition === null || elementAbsPosition === void 0 ? void 0 : elementAbsPosition.x, objectY: elementAbsPosition === null || elementAbsPosition === void 0 ? void 0 : elementAbsPosition.y, width: size.width, height: size.height, zoom: zoom, draggingByDefault: draggingByDefault,
|
|
9364
|
+
//movingOffsetThreshold: ELEMENT_MOVING_OFFSET_THRESHOLD,
|
|
9365
|
+
onMouseDown: function (ev) {
|
|
9366
|
+
windowsPositionToPaperPosition({
|
|
9367
|
+
x: ev.clientX,
|
|
9368
|
+
y: ev.clientY
|
|
9369
|
+
}, container, zoomRef.current);
|
|
9370
|
+
onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(ev, id);
|
|
9371
|
+
}, onMouseUp: function (ev) {
|
|
9372
|
+
windowsPositionToPaperPosition({
|
|
9373
|
+
x: ev.clientX,
|
|
9374
|
+
y: ev.clientY
|
|
9375
|
+
}, container, zoomRef.current);
|
|
9376
|
+
onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(ev, id);
|
|
9377
|
+
}, onMove: function (newX, newY) {
|
|
9378
|
+
var _a;
|
|
9379
|
+
var oldPosition = __assign({}, position);
|
|
9380
|
+
// Relative position to the paper container
|
|
9381
|
+
var paperPosition = {
|
|
9382
|
+
x: newX,
|
|
9383
|
+
y: newY
|
|
9384
|
+
};
|
|
9385
|
+
//Call onElementMoving to check if the element should be moved or not
|
|
9386
|
+
if (onMoving) {
|
|
9387
|
+
var _b = (_a = onMoving(props.element, paperPosition)) !== null && _a !== void 0 ? _a : {}, horizontalAllowed = _b.horizontalAllowed, verticalAllowed = _b.verticalAllowed;
|
|
9388
|
+
//If both horizontalAllowed and verticalAllowed are false, do not move the element
|
|
9389
|
+
if (!horizontalAllowed && !verticalAllowed) {
|
|
9390
|
+
return;
|
|
9391
|
+
}
|
|
9392
|
+
//If horizontalAllowed is false, keep the old x position
|
|
9393
|
+
if (!horizontalAllowed) {
|
|
9394
|
+
paperPosition.x = oldPosition.x;
|
|
9395
|
+
}
|
|
9396
|
+
//If verticalAllowed is false, keep the old y position
|
|
9397
|
+
if (!verticalAllowed) {
|
|
9398
|
+
paperPosition.y = oldPosition.y;
|
|
9399
|
+
}
|
|
9400
|
+
}
|
|
9401
|
+
logger.info("Element ".concat(props.element.id, " is dragging to position ").concat(JSON.stringify(paperPosition)));
|
|
9402
|
+
//Adjust position of element if it should move as a port on parent port area
|
|
9403
|
+
if (props.element.moveAsPortOnParent && props.element.parentElement) {
|
|
9404
|
+
paperPosition = adjustElementPositionOnParentPortArea(paperPosition, true);
|
|
9405
|
+
updateElementPosition(paperPosition);
|
|
9406
|
+
}
|
|
9407
|
+
else {
|
|
9408
|
+
var relativePosition = transformAbsPositionToElementRelativePosition(paperPosition, props.element);
|
|
9409
|
+
updateElementPosition(relativePosition);
|
|
9410
|
+
}
|
|
9411
|
+
//let newElementPosition = updateElementPosition(props.element, newPosition.x, newPosition.y, true)
|
|
9412
|
+
logger.info("Element ".concat(props.element.id, " is moving to relative position ").concat(JSON.stringify(props.element.position)));
|
|
9413
|
+
onMoved === null || onMoved === void 0 ? void 0 : onMoved(props.element, oldPosition, paperPosition);
|
|
9414
|
+
}, onResize: function (width, height) {
|
|
9415
|
+
var oldSize = size;
|
|
9416
|
+
var newSize = { width: width, height: height };
|
|
9417
|
+
updateElementSize(newSize);
|
|
9418
|
+
if (onResized) {
|
|
9419
|
+
onResized(props.element, oldSize, newSize);
|
|
9420
|
+
}
|
|
9421
|
+
} }),
|
|
9422
|
+
potentialPortPosition && (portPlaceholderShape
|
|
9423
|
+
? React.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
|
|
9424
|
+
: 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 })),
|
|
9425
|
+
renderedPorts,
|
|
9426
|
+
renderedTexts,
|
|
9427
|
+
children));
|
|
9235
9428
|
});
|
|
9236
9429
|
var Element$1 = React.memo(Element);
|
|
9237
9430
|
|
|
@@ -9478,19 +9671,18 @@ function convertElementsToTree(elements) {
|
|
|
9478
9671
|
return parsedElementsInTree;
|
|
9479
9672
|
}
|
|
9480
9673
|
var Paper = function (props) {
|
|
9481
|
-
var _a,
|
|
9482
|
-
var _c = React.useState({ elements: [], elementsInTree: [] }), elementsState = _c[0], setElementsState = _c[1];
|
|
9674
|
+
var _a = React.useState({ elements: [], elementsInTree: [] }), elementsState = _a[0], setElementsState = _a[1];
|
|
9483
9675
|
// const [elements, setElements] = React.useState<IElementState[]>([]);
|
|
9484
9676
|
// const [elementsInTree, setElementsInTree] = React.useState<IElementInTreeState[]>([]);
|
|
9485
|
-
var
|
|
9486
|
-
var
|
|
9487
|
-
var
|
|
9488
|
-
var
|
|
9489
|
-
var
|
|
9490
|
-
var
|
|
9491
|
-
var
|
|
9492
|
-
var
|
|
9493
|
-
var
|
|
9677
|
+
var _b = React.useState(), selectedElement = _b[0], setSelectedElement = _b[1];
|
|
9678
|
+
var _c = React.useState(false), autoEnabledDraggingSelectedElement = _c[0], setAutoEnabledDraggingSelectedElement = _c[1];
|
|
9679
|
+
var _d = React.useState([]), links = _d[0], setLinks = _d[1];
|
|
9680
|
+
var _e = React.useState(), selectedLink = _e[0], setSelectedLink = _e[1];
|
|
9681
|
+
var _f = React.useState(null), tempLink = _f[0], setTempLink = _f[1];
|
|
9682
|
+
var _g = React.useState([]), texts = _g[0], setTexts = _g[1];
|
|
9683
|
+
var _h = React.useState(), selectedText = _h[0], setSelectedText = _h[1];
|
|
9684
|
+
var _j = React.useState(null), selectedElementSVG = _j[0], setSelectedElementSVG = _j[1];
|
|
9685
|
+
var _k = React.useState(false), mouseDownedOnPaper = _k[0], setMouseDownedOnPaper = _k[1];
|
|
9494
9686
|
var paperEventEmitter = React.useContext(paperEventEmitterContext);
|
|
9495
9687
|
var zoom = useZoomContext().zoom;
|
|
9496
9688
|
var zoomRef = React.useRef(zoom);
|
|
@@ -9500,14 +9692,13 @@ var Paper = function (props) {
|
|
|
9500
9692
|
var linksRef = React.useRef(links); //Cache links to avoid re-render when links changed
|
|
9501
9693
|
var textsRef = React.useRef(texts); //Cache texts to avoid re-render when texts changed
|
|
9502
9694
|
var size = props.size;
|
|
9503
|
-
var selectedElementAbsPosition = React.useMemo(function () { return selectedElement ? getAbsolutePosition(selectedElement) : null; }, [selectedElement, (_a = selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.position) === null || _a === void 0 ? void 0 : _a.x, (_b = selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.position) === null || _b === void 0 ? void 0 : _b.y, selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.size]);
|
|
9504
9695
|
var onPortMoved = props.onPortMoved, onPortSelected = props.onPortSelected, onPortMouseDown = props.onPortMouseDown, onPortMouseUp = props.onPortMouseUp,
|
|
9505
9696
|
//onPortsChanged,
|
|
9506
9697
|
onPortContextMenu = props.onPortContextMenu, onElementSelected = props.onElementSelected, onElementsChanged = props.onElementsChanged, onElementResized = props.onElementResized, onElementContextMenu = props.onElementContextMenu, onElementMouseUp = props.onElementMouseUp, onElementMouseDown = props.onElementMouseDown, onElementMouseMove = props.onElementMouseMove, onElementMoved = props.onElementMoved, onElementMouseLeave = props.onElementMouseLeave, onElementDeleted = props.onElementDeleted, onLinksChanged = props.onLinksChanged, onLinkSelected = props.onLinkSelected, onTextSelected = props.onTextSelected, onTextsChanged = props.onTextsChanged, manuallyTriggerRenderElementHandler = props.manuallyTriggerRenderElementHandler, manuallyTriggerRenderPortHandler = props.manuallyTriggerRenderPortHandler, onCreatingPortByLinking = props.onCreatingPortByLinking, onCreatingLink = props.onCreatingLink, onElementMoving = props.onElementMoving, manuallySelectElementHandler = props.manuallySelectElementHandler, manuallyTriggerDraggingElementHandler = props.manuallyTriggerDraggingElementHandler, manuallyTriggerStartedLinkingHandler = props.manuallyTriggerStartedLinkingHandler;
|
|
9507
9698
|
var handleElementsState = React.useCallback(function (elements) {
|
|
9508
9699
|
var elementsInTree = convertElementsToTree(elements);
|
|
9509
9700
|
setElementsState({ elements: __spreadArray([], elements, true), elementsInTree: elementsInTree });
|
|
9510
|
-
elementsRef.current =
|
|
9701
|
+
// elementsRef.current = [...elements];
|
|
9511
9702
|
}, []);
|
|
9512
9703
|
var rerenderWhenAnyElementChanged = React.useCallback(function () {
|
|
9513
9704
|
setElementsState(function (prev) { return ({ elements: __spreadArray([], prev.elements, true), elementsInTree: __spreadArray([], prev.elementsInTree, true) }); });
|
|
@@ -9526,36 +9717,45 @@ var Paper = function (props) {
|
|
|
9526
9717
|
}, [props.texts]);
|
|
9527
9718
|
React.useEffect(function () {
|
|
9528
9719
|
var off = manuallyTriggerRenderElementHandler(function (elementId) {
|
|
9529
|
-
|
|
9530
|
-
|
|
9531
|
-
|
|
9532
|
-
|
|
9533
|
-
|
|
9720
|
+
//find the element
|
|
9721
|
+
var element = elementsState.elements.find(function (elm) { return elm.id === elementId; });
|
|
9722
|
+
if (!element)
|
|
9723
|
+
return;
|
|
9724
|
+
element.version = (element.version || 0) + 1;
|
|
9725
|
+
handleElementsState(elementsState.elements);
|
|
9534
9726
|
});
|
|
9535
9727
|
return function () {
|
|
9536
9728
|
off();
|
|
9537
9729
|
};
|
|
9538
|
-
}, [manuallyTriggerRenderElementHandler, rerenderWhenAnyElementChanged]);
|
|
9730
|
+
}, [elementsState.elements, handleElementsState, manuallyTriggerRenderElementHandler, onElementsChanged, rerenderWhenAnyElementChanged]);
|
|
9539
9731
|
React.useEffect(function () {
|
|
9540
|
-
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9732
|
+
if (manuallySelectElementHandler) {
|
|
9733
|
+
var off_1 = manuallySelectElementHandler(function (element) {
|
|
9734
|
+
setSelectedElement(element || undefined);
|
|
9735
|
+
if (element) {
|
|
9736
|
+
onElementSelected === null || onElementSelected === void 0 ? void 0 : onElementSelected(element);
|
|
9737
|
+
}
|
|
9738
|
+
});
|
|
9739
|
+
return function () {
|
|
9740
|
+
off_1();
|
|
9741
|
+
};
|
|
9742
|
+
}
|
|
9743
|
+
}, [manuallySelectElementHandler, onElementSelected]);
|
|
9744
|
+
React.useEffect(function () {
|
|
9745
|
+
if (manuallyTriggerDraggingElementHandler) {
|
|
9746
|
+
var off_2 = manuallyTriggerDraggingElementHandler(function (element) {
|
|
9747
|
+
setSelectedElement(element);
|
|
9544
9748
|
onElementSelected === null || onElementSelected === void 0 ? void 0 : onElementSelected(element);
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
return function () {
|
|
9553
|
-
offs.forEach(function (off) { return off(); });
|
|
9554
|
-
};
|
|
9555
|
-
}, [manuallySelectElementHandler, manuallyTriggerDraggingElementHandler, onElementSelected]);
|
|
9749
|
+
setAutoEnabledDraggingSelectedElement(true);
|
|
9750
|
+
});
|
|
9751
|
+
return function () {
|
|
9752
|
+
off_2();
|
|
9753
|
+
};
|
|
9754
|
+
}
|
|
9755
|
+
}, [elementsState.elements, manuallyTriggerDraggingElementHandler, onElementSelected]);
|
|
9556
9756
|
React.useEffect(function () {
|
|
9557
9757
|
if (manuallyTriggerStartedLinkingHandler) {
|
|
9558
|
-
var
|
|
9758
|
+
var off_3 = manuallyTriggerStartedLinkingHandler(function (sourceElement, sourcePort) {
|
|
9559
9759
|
var newLink = {
|
|
9560
9760
|
id: generateUniqueId(),
|
|
9561
9761
|
points: [],
|
|
@@ -9566,7 +9766,7 @@ var Paper = function (props) {
|
|
|
9566
9766
|
paperEventEmitter.emitElementLinkStarted(newLink);
|
|
9567
9767
|
});
|
|
9568
9768
|
return function () {
|
|
9569
|
-
|
|
9769
|
+
off_3();
|
|
9570
9770
|
};
|
|
9571
9771
|
}
|
|
9572
9772
|
}, [manuallyTriggerStartedLinkingHandler, paperEventEmitter]);
|
|
@@ -9614,7 +9814,7 @@ var Paper = function (props) {
|
|
|
9614
9814
|
setSelectedElementSVG(null);
|
|
9615
9815
|
setSelectedLink(undefined);
|
|
9616
9816
|
//broadcast selected port to parent component
|
|
9617
|
-
var element =
|
|
9817
|
+
var element = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
9618
9818
|
if (element) {
|
|
9619
9819
|
onPortSelected === null || onPortSelected === void 0 ? void 0 : onPortSelected(port, element);
|
|
9620
9820
|
}
|
|
@@ -9622,36 +9822,44 @@ var Paper = function (props) {
|
|
|
9622
9822
|
return function () {
|
|
9623
9823
|
portSelectedListener.off();
|
|
9624
9824
|
};
|
|
9625
|
-
}, [paperEventEmitter, onPortSelected]);
|
|
9825
|
+
}, [paperEventEmitter, onPortSelected, elementsState]);
|
|
9626
9826
|
React.useEffect(function () {
|
|
9627
9827
|
//Listen parent of elements changed, then update elements tree
|
|
9628
|
-
var parentChangedCancelers =
|
|
9828
|
+
var parentChangedCancelers = elementsState.elements.map(function (element) {
|
|
9629
9829
|
var _a;
|
|
9630
9830
|
return (_a = element.onParentChanged) === null || _a === void 0 ? void 0 : _a.call(element, function (newPa, oldPa) {
|
|
9631
9831
|
logger.info('onParentChanged');
|
|
9632
|
-
handleElementsState(
|
|
9832
|
+
handleElementsState(elementsState.elements);
|
|
9633
9833
|
});
|
|
9634
9834
|
});
|
|
9635
|
-
|
|
9636
|
-
|
|
9835
|
+
return function () {
|
|
9836
|
+
parentChangedCancelers.forEach(function (canceller) { return canceller === null || canceller === void 0 ? void 0 : canceller(); });
|
|
9837
|
+
};
|
|
9838
|
+
}, [handleElementsState, rerenderWhenAnyElementChanged, elementsState]);
|
|
9839
|
+
React.useEffect(function () {
|
|
9840
|
+
//Listen a new text added, then re-render the element component
|
|
9841
|
+
//TODO: to be moved to Element component
|
|
9842
|
+
var addedTextCancelers = elementsRef.current.map(function (element) {
|
|
9637
9843
|
var _a;
|
|
9638
|
-
return (_a = element.
|
|
9639
|
-
logger.info("A new
|
|
9640
|
-
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9844
|
+
return (_a = element.onAddedText) === null || _a === void 0 ? void 0 : _a.call(element, function (newText) {
|
|
9845
|
+
logger.info("A new text has been added to element ".concat(element.id));
|
|
9846
|
+
rerenderWhenAnyElementChanged();
|
|
9847
|
+
});
|
|
9848
|
+
});
|
|
9849
|
+
// Listen a text deleted, then re-render the element component
|
|
9850
|
+
//TODO: to be moved to Element component
|
|
9851
|
+
var deletedTextCancelers = elementsRef.current.map(function (element) {
|
|
9852
|
+
var _a;
|
|
9853
|
+
return (_a = element.onDeletedText) === null || _a === void 0 ? void 0 : _a.call(element, function (deletedTextId) {
|
|
9854
|
+
logger.info("A text has been deleted from element ".concat(element.id));
|
|
9647
9855
|
rerenderWhenAnyElementChanged();
|
|
9648
9856
|
});
|
|
9649
9857
|
});
|
|
9650
9858
|
return function () {
|
|
9651
|
-
|
|
9652
|
-
|
|
9859
|
+
addedTextCancelers.forEach(function (canceller) { return canceller(); });
|
|
9860
|
+
deletedTextCancelers.forEach(function (canceller) { return canceller(); });
|
|
9653
9861
|
};
|
|
9654
|
-
}, [
|
|
9862
|
+
}, [elementsState.elements, onElementsChanged, rerenderWhenAnyElementChanged]);
|
|
9655
9863
|
// //Update elements tree when length of elements change
|
|
9656
9864
|
// useEffect(() => {
|
|
9657
9865
|
// updateElementsTree();
|
|
@@ -9669,11 +9877,11 @@ var Paper = function (props) {
|
|
|
9669
9877
|
//Listen command delete selected for element
|
|
9670
9878
|
React.useEffect(function () {
|
|
9671
9879
|
var listener = paperEventEmitter.onCommandDeleteSelectedElement(function () {
|
|
9672
|
-
if (selectedElement) {
|
|
9880
|
+
if (selectedElement && selectedElement.removable !== false) {
|
|
9673
9881
|
selectedElement.parentElement = undefined; //Remove parent element to avoid memory leak. This will remove the element from the parent element's childrenElements array.
|
|
9674
9882
|
var deletedChildElements = getChildOfElement(selectedElement);
|
|
9675
9883
|
var deletedElementIds_1 = __spreadArray(__spreadArray([], deletedChildElements, true), [selectedElement], false).map(function (e) { return e.id; });
|
|
9676
|
-
var prevElements =
|
|
9884
|
+
var prevElements = elementsState.elements;
|
|
9677
9885
|
var newElements = prevElements.filter(function (e) { return !deletedElementIds_1.includes(e.id); });
|
|
9678
9886
|
onElementDeleted === null || onElementDeleted === void 0 ? void 0 : onElementDeleted(selectedElement);
|
|
9679
9887
|
//Set state to re-render component
|
|
@@ -9699,14 +9907,20 @@ var Paper = function (props) {
|
|
|
9699
9907
|
return function () {
|
|
9700
9908
|
listener.off();
|
|
9701
9909
|
};
|
|
9702
|
-
}, [selectedElement, onElementSelected, onElementsChanged, onLinksChanged, getChildOfElement, paperEventEmitter, onElementDeleted, handleElementsState]);
|
|
9910
|
+
}, [selectedElement, elementsState, onElementSelected, onElementsChanged, onLinksChanged, getChildOfElement, paperEventEmitter, onElementDeleted, handleElementsState]);
|
|
9911
|
+
var removeElementLink = React.useCallback(function (elementLink) {
|
|
9912
|
+
if (elementLink.removable === false)
|
|
9913
|
+
return linksRef.current;
|
|
9914
|
+
var prevLinks = linksRef.current;
|
|
9915
|
+
var newLinks = prevLinks.filter(function (l) { return l.id !== elementLink.id; });
|
|
9916
|
+
return newLinks;
|
|
9917
|
+
}, []);
|
|
9703
9918
|
//Listen command delete selected for link
|
|
9704
9919
|
React.useEffect(function () {
|
|
9705
9920
|
var listener = paperEventEmitter.onCommandDeleteSelectedLink(function () {
|
|
9706
9921
|
if (selectedLink) {
|
|
9707
|
-
var
|
|
9708
|
-
|
|
9709
|
-
setLinks(links);
|
|
9922
|
+
var newLinks = removeElementLink(selectedLink);
|
|
9923
|
+
setLinks(newLinks);
|
|
9710
9924
|
setSelectedLink(undefined);
|
|
9711
9925
|
if (onLinksChanged) {
|
|
9712
9926
|
onLinksChanged(newLinks);
|
|
@@ -9720,11 +9934,11 @@ var Paper = function (props) {
|
|
|
9720
9934
|
return function () {
|
|
9721
9935
|
listener.off();
|
|
9722
9936
|
};
|
|
9723
|
-
}, [selectedLink, onLinksChanged, onLinkSelected,
|
|
9937
|
+
}, [selectedLink, onLinksChanged, onLinkSelected, paperEventEmitter, removeElementLink]);
|
|
9724
9938
|
//Listen command delete selected for Text
|
|
9725
9939
|
React.useEffect(function () {
|
|
9726
9940
|
var listener = paperEventEmitter.onCommandDeleteSelectedText(function () {
|
|
9727
|
-
if (selectedText) {
|
|
9941
|
+
if (selectedText && selectedText.removable !== false) {
|
|
9728
9942
|
var prevTexts = textsRef.current;
|
|
9729
9943
|
var newTexts = prevTexts.filter(function (t) { return t.id !== selectedText.id; });
|
|
9730
9944
|
setTexts(newTexts);
|
|
@@ -9813,33 +10027,59 @@ var Paper = function (props) {
|
|
|
9813
10027
|
y: yPosOnPaper
|
|
9814
10028
|
});
|
|
9815
10029
|
};
|
|
9816
|
-
var
|
|
9817
|
-
//
|
|
9818
|
-
|
|
9819
|
-
var
|
|
9820
|
-
|
|
9821
|
-
var
|
|
10030
|
+
var handleElementMoved = React.useCallback(function (element, oldPosition, paperPosition) {
|
|
10031
|
+
// Start updating the position of links connected to the selected element
|
|
10032
|
+
var childElements = getChildOfElement(element);
|
|
10033
|
+
var elementIds = __spreadArray(__spreadArray([], childElements.map(function (e) { return e.id; }), true), [element.id], false);
|
|
10034
|
+
var offsetX = element.position.x - oldPosition.x;
|
|
10035
|
+
var offsetY = element.position.y - oldPosition.y;
|
|
10036
|
+
// Update position of all points of links that are connected to the selected element
|
|
10037
|
+
var newLinks = linksRef.current.map(function (link) {
|
|
10038
|
+
var isUpdate = elementIds.includes(link.sourceElement.id) && elementIds.includes(link.targetElement.id);
|
|
10039
|
+
if (link.points && isUpdate) {
|
|
10040
|
+
link.points.forEach(function (p) {
|
|
10041
|
+
p.x += offsetX;
|
|
10042
|
+
p.y += offsetY;
|
|
10043
|
+
});
|
|
10044
|
+
}
|
|
10045
|
+
return link;
|
|
10046
|
+
});
|
|
9822
10047
|
setLinks(newLinks);
|
|
9823
|
-
|
|
9824
|
-
|
|
10048
|
+
// onLinksChanged?.(newLinks);
|
|
10049
|
+
// End updating the position of links connected to the selected element
|
|
10050
|
+
if (onElementMoved) {
|
|
10051
|
+
onElementMoved(element.position, element, paperPosition);
|
|
9825
10052
|
}
|
|
9826
|
-
|
|
9827
|
-
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
if (onLinksChanged) {
|
|
9833
|
-
onLinksChanged(newLinks);
|
|
10053
|
+
paperEventEmitter.emitElementMoved(element, oldPosition, element.position);
|
|
10054
|
+
setMouseDownedOnPaper(false);
|
|
10055
|
+
}, [getChildOfElement, onElementMoved, paperEventEmitter]);
|
|
10056
|
+
var handleElementResized = React.useCallback(function (element, oldSize, newSize) {
|
|
10057
|
+
if (onElementResized) {
|
|
10058
|
+
onElementResized(newSize, element);
|
|
9834
10059
|
}
|
|
9835
|
-
|
|
10060
|
+
paperEventEmitter.emitElementResized(element, oldSize, newSize);
|
|
10061
|
+
setMouseDownedOnPaper(false);
|
|
10062
|
+
}, [paperEventEmitter, onElementResized]);
|
|
10063
|
+
// const handlePathChange = useCallback((path: string, id: string) => {
|
|
10064
|
+
// //Update path of element link, that changed
|
|
10065
|
+
// //const prevLinks = linksRef.current;
|
|
10066
|
+
// const updatedLink = linksRef.current.find(l => l.id === id)
|
|
10067
|
+
// if (updatedLink) {
|
|
10068
|
+
// updatedLink.path = path;
|
|
10069
|
+
// }
|
|
10070
|
+
// }, [])
|
|
10071
|
+
//TODO: to be cleaned
|
|
10072
|
+
var handlePointsOfLinkChange = React.useCallback(function (points, linkId) {
|
|
10073
|
+
var updatedLinkIndex = linksRef.current.findIndex(function (l) { return l.id === linkId; });
|
|
10074
|
+
linksRef.current[updatedLinkIndex].points = points;
|
|
10075
|
+
}, []);
|
|
9836
10076
|
var handlePortMoved = React.useCallback(function (port, elementId, oldPosition, newPosition) {
|
|
9837
10077
|
var _a;
|
|
9838
|
-
var element =
|
|
10078
|
+
var element = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
9839
10079
|
if (element) {
|
|
9840
10080
|
//set links equals a clone links to re-render links with new position
|
|
9841
10081
|
var prevLinks = linksRef.current;
|
|
9842
|
-
|
|
10082
|
+
prevLinks.map(function (link) {
|
|
9843
10083
|
var _a, _b;
|
|
9844
10084
|
if (link.sourceElement.id === elementId && link.sourcePort.id === port.id) {
|
|
9845
10085
|
link.sourcePort.position = newPosition;
|
|
@@ -9861,9 +10101,9 @@ var Paper = function (props) {
|
|
|
9861
10101
|
return link;
|
|
9862
10102
|
});
|
|
9863
10103
|
});
|
|
9864
|
-
if (onLinksChanged) {
|
|
9865
|
-
|
|
9866
|
-
}
|
|
10104
|
+
// if (onLinksChanged) {
|
|
10105
|
+
// onLinksChanged(newLinks)
|
|
10106
|
+
// }
|
|
9867
10107
|
//const newElements = elementsRef.current;
|
|
9868
10108
|
// newElements[updatedElementIndex].ports = newElements[updatedElementIndex].ports?.map(p => {
|
|
9869
10109
|
// if (p.id === port.id) {
|
|
@@ -9875,7 +10115,7 @@ var Paper = function (props) {
|
|
|
9875
10115
|
//To avoid re-render
|
|
9876
10116
|
// setElements(prev => {
|
|
9877
10117
|
// const newElements = [...prev]
|
|
9878
|
-
var updatedElement =
|
|
10118
|
+
var updatedElement = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
9879
10119
|
if (updatedElement) {
|
|
9880
10120
|
updatedElement.ports = (_a = updatedElement.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
|
|
9881
10121
|
if (p.id === port.id) {
|
|
@@ -9891,16 +10131,32 @@ var Paper = function (props) {
|
|
|
9891
10131
|
onPortMoved(newPosition, port, element);
|
|
9892
10132
|
}
|
|
9893
10133
|
}
|
|
9894
|
-
}, [onPortMoved,
|
|
10134
|
+
}, [onPortMoved, elementsState, rerenderWhenAnyElementChanged]);
|
|
10135
|
+
React.useEffect(function () {
|
|
10136
|
+
//on port manually trigger render
|
|
10137
|
+
var off = manuallyTriggerRenderPortHandler(function (portId, elementId) {
|
|
10138
|
+
var _a;
|
|
10139
|
+
//find the element
|
|
10140
|
+
var element = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
10141
|
+
//find the port
|
|
10142
|
+
var port = (_a = element === null || element === void 0 ? void 0 : element.ports) === null || _a === void 0 ? void 0 : _a.find(function (p) { return p.id === portId; });
|
|
10143
|
+
if (!element || !port)
|
|
10144
|
+
return;
|
|
10145
|
+
//rerender links connected to the port
|
|
10146
|
+
handlePortMoved(port, elementId, __assign({}, port.position), __assign({}, port.position));
|
|
10147
|
+
});
|
|
10148
|
+
return function () {
|
|
10149
|
+
off();
|
|
10150
|
+
};
|
|
10151
|
+
}, [manuallyTriggerRenderPortHandler, handlePortMoved, elementsState]);
|
|
9895
10152
|
//Handle creating a new element link
|
|
9896
10153
|
var handlePortMouseDown = React.useCallback(function (ev, port, elementId) {
|
|
9897
10154
|
ev.stopPropagation();
|
|
9898
|
-
var element =
|
|
10155
|
+
var element = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
9899
10156
|
var paperPosition = windowsPositionToPaperPosition({
|
|
9900
10157
|
x: ev.clientX,
|
|
9901
10158
|
y: ev.clientY
|
|
9902
10159
|
}, paperContainerRef.current, zoomRef.current);
|
|
9903
|
-
console.log(paperPosition);
|
|
9904
10160
|
//broadcast port mouse down to parent component
|
|
9905
10161
|
if (element) {
|
|
9906
10162
|
onPortMouseDown === null || onPortMouseDown === void 0 ? void 0 : onPortMouseDown(port, element, paperPosition);
|
|
@@ -9916,7 +10172,7 @@ var Paper = function (props) {
|
|
|
9916
10172
|
setTempLink(newLink);
|
|
9917
10173
|
paperEventEmitter.emitElementLinkStarted(newLink);
|
|
9918
10174
|
}
|
|
9919
|
-
}, [paperEventEmitter, onPortMouseDown]);
|
|
10175
|
+
}, [paperEventEmitter, elementsState, onPortMouseDown]);
|
|
9920
10176
|
var createElementLink = React.useCallback(function (sourcePort, sourceElement, targetPort, targetElement) {
|
|
9921
10177
|
//if no onCreatingLink prop, no link will be created
|
|
9922
10178
|
if (!onCreatingLink) {
|
|
@@ -9927,14 +10183,14 @@ var Paper = function (props) {
|
|
|
9927
10183
|
return null;
|
|
9928
10184
|
//Automatic bending, if is not defined points
|
|
9929
10185
|
if (!newElementLink.points || newElementLink.points.length === 0) {
|
|
9930
|
-
var elements =
|
|
10186
|
+
var elements = elementsState.elements;
|
|
9931
10187
|
newElementLink = automationAddPointsToLink(newElementLink, elements, MAX_LINK_KNOT_COUNT);
|
|
9932
10188
|
}
|
|
9933
10189
|
return newElementLink;
|
|
9934
|
-
}, [onCreatingLink]);
|
|
10190
|
+
}, [onCreatingLink, elementsState]);
|
|
9935
10191
|
var handlePortMouseUp = React.useCallback(function (ev, port, elementId) {
|
|
9936
10192
|
ev.stopPropagation();
|
|
9937
|
-
var element =
|
|
10193
|
+
var element = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
9938
10194
|
var paperPosition = windowsPositionToPaperPosition({
|
|
9939
10195
|
x: ev.clientX,
|
|
9940
10196
|
y: ev.clientY
|
|
@@ -9950,7 +10206,7 @@ var Paper = function (props) {
|
|
|
9950
10206
|
var newElementLink = null;
|
|
9951
10207
|
if (isMouseUpOnNotSelf) {
|
|
9952
10208
|
var _a = tempLinkRef.current, sourcePort = _a.sourcePort, sourceElement = _a.sourceElement;
|
|
9953
|
-
var targetElement =
|
|
10209
|
+
var targetElement = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
9954
10210
|
newElementLink = createElementLink(sourcePort, sourceElement, port, targetElement);
|
|
9955
10211
|
}
|
|
9956
10212
|
if (newElementLink) {
|
|
@@ -9967,7 +10223,7 @@ var Paper = function (props) {
|
|
|
9967
10223
|
}
|
|
9968
10224
|
setTempLink(null);
|
|
9969
10225
|
}
|
|
9970
|
-
}, [paperEventEmitter, createElementLink, onPortMouseUp, onLinksChanged]);
|
|
10226
|
+
}, [paperEventEmitter, elementsState, createElementLink, onPortMouseUp, onLinksChanged]);
|
|
9971
10227
|
// const handlePortsChanged = useCallback((ports: IPort[], elementId: string) => {
|
|
9972
10228
|
// const element = elementsRef.current.find(e => e.id === elementId);
|
|
9973
10229
|
// if (element) {
|
|
@@ -10066,19 +10322,6 @@ var Paper = function (props) {
|
|
|
10066
10322
|
var handleDeselectLink = function (link, index) {
|
|
10067
10323
|
setSelectedLink(undefined);
|
|
10068
10324
|
};
|
|
10069
|
-
//update absolute position of element and absolute position of children elements
|
|
10070
|
-
var updateElementPosition = function (element, x, y, isRelativePosition) {
|
|
10071
|
-
if (isRelativePosition) {
|
|
10072
|
-
element.position.x = x;
|
|
10073
|
-
element.position.y = y;
|
|
10074
|
-
}
|
|
10075
|
-
else {
|
|
10076
|
-
var relativePosition = transformAbsPositionToElementRelativePosition({ x: x, y: y }, element);
|
|
10077
|
-
element.position.x = relativePosition.x;
|
|
10078
|
-
element.position.y = relativePosition.y;
|
|
10079
|
-
}
|
|
10080
|
-
return element;
|
|
10081
|
-
};
|
|
10082
10325
|
/*
|
|
10083
10326
|
Cache to avoid re-initializing the function when the component re-renders to
|
|
10084
10327
|
avoid causing the components using it to re-render unnecessarily
|
|
@@ -10108,17 +10351,16 @@ var Paper = function (props) {
|
|
|
10108
10351
|
}, [handleLinkLabelContentChanged]);
|
|
10109
10352
|
var handleClickLinkDelete = React.useCallback(function (link, index) {
|
|
10110
10353
|
return function () {
|
|
10111
|
-
var
|
|
10112
|
-
var newLinks = __spreadArray([], prevLinks, true);
|
|
10113
|
-
newLinks.splice(index, 1);
|
|
10354
|
+
var newLinks = removeElementLink(link);
|
|
10114
10355
|
setLinks(newLinks);
|
|
10356
|
+
setSelectedLink(undefined);
|
|
10115
10357
|
if (onLinksChanged) {
|
|
10116
10358
|
onLinksChanged(newLinks);
|
|
10117
10359
|
}
|
|
10118
10360
|
};
|
|
10119
|
-
}, [onLinksChanged]);
|
|
10361
|
+
}, [onLinksChanged, removeElementLink]);
|
|
10120
10362
|
var handleMouseUpAtLinkedPortPlaceholder = React.useCallback(function (link, position, targetElementId) {
|
|
10121
|
-
var targetElement =
|
|
10363
|
+
var targetElement = elementsState.elements.find(function (e) { return e.id === targetElementId; });
|
|
10122
10364
|
if (!targetElement)
|
|
10123
10365
|
return;
|
|
10124
10366
|
logger.info("A port could have been created at position ".concat(JSON.stringify(position), " on element ").concat(targetElementId, " by linking from element ").concat(link.sourceElement.id));
|
|
@@ -10148,20 +10390,20 @@ var Paper = function (props) {
|
|
|
10148
10390
|
//Clear tempLink
|
|
10149
10391
|
setTempLink(null);
|
|
10150
10392
|
paperEventEmitter.emitElementLinkEnded();
|
|
10151
|
-
}, [onCreatingPortByLinking, createElementLink, paperEventEmitter, onLinksChanged]);
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
|
|
10158
|
-
|
|
10159
|
-
|
|
10160
|
-
|
|
10161
|
-
|
|
10162
|
-
|
|
10163
|
-
|
|
10164
|
-
}, [rerenderWhenAnyElementChanged])
|
|
10393
|
+
}, [onCreatingPortByLinking, elementsState, createElementLink, paperEventEmitter, onLinksChanged]);
|
|
10394
|
+
// const handleElementTextChange = useCallback((elementId: string, textId: string, newContent: string) => {
|
|
10395
|
+
// // const prevElms = elementsRef.current;
|
|
10396
|
+
// elementsState.elements.forEach(curEle => {
|
|
10397
|
+
// //Find changed text of element to update the content for it.
|
|
10398
|
+
// if (curEle.id === elementId && curEle.texts) {
|
|
10399
|
+
// const updatedTextId = curEle.texts.findIndex(t => t.id === textId)
|
|
10400
|
+
// if (updatedTextId !== undefined) {
|
|
10401
|
+
// curEle.texts[updatedTextId].content = newContent;
|
|
10402
|
+
// }
|
|
10403
|
+
// }
|
|
10404
|
+
// })
|
|
10405
|
+
// rerenderWhenAnyElementChanged();
|
|
10406
|
+
// }, [rerenderWhenAnyElementChanged, elementsState])
|
|
10165
10407
|
var handleElementClicked = React.useCallback(function (elementId, e, ref) {
|
|
10166
10408
|
e.stopPropagation();
|
|
10167
10409
|
var tempLink = tempLinkRef.current;
|
|
@@ -10171,7 +10413,7 @@ var Paper = function (props) {
|
|
|
10171
10413
|
paperEventEmitter.emitElementLinkEnded();
|
|
10172
10414
|
}
|
|
10173
10415
|
else {
|
|
10174
|
-
var element =
|
|
10416
|
+
var element = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
10175
10417
|
// Select the element only if it is selectable
|
|
10176
10418
|
if (element && element.selectable) {
|
|
10177
10419
|
setSelectedElementSVG(ref);
|
|
@@ -10181,24 +10423,24 @@ var Paper = function (props) {
|
|
|
10181
10423
|
}
|
|
10182
10424
|
}
|
|
10183
10425
|
setMouseDownedOnPaper(false);
|
|
10184
|
-
}, [paperEventEmitter]);
|
|
10426
|
+
}, [paperEventEmitter, elementsState.elements]);
|
|
10185
10427
|
var handlePortContextMenu = React.useCallback(function (port, elementId, e) {
|
|
10186
10428
|
e.preventDefault();
|
|
10187
|
-
var element =
|
|
10429
|
+
var element = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
10188
10430
|
if (element) {
|
|
10189
10431
|
onPortContextMenu === null || onPortContextMenu === void 0 ? void 0 : onPortContextMenu(port, element, e);
|
|
10190
10432
|
}
|
|
10191
|
-
}, [onPortContextMenu]);
|
|
10433
|
+
}, [onPortContextMenu, elementsState]);
|
|
10192
10434
|
var handleContextMenu = React.useCallback(function (elementId, e, ref) {
|
|
10193
10435
|
e.preventDefault();
|
|
10194
|
-
var element =
|
|
10436
|
+
var element = elementsState.elements.find(function (e) { return e.id === elementId; });
|
|
10195
10437
|
if (element) {
|
|
10196
10438
|
handleElementClicked(elementId, e, ref);
|
|
10197
10439
|
onElementContextMenu === null || onElementContextMenu === void 0 ? void 0 : onElementContextMenu(element, e);
|
|
10198
10440
|
}
|
|
10199
|
-
}, [onElementContextMenu, handleElementClicked]);
|
|
10441
|
+
}, [onElementContextMenu, handleElementClicked, elementsState]);
|
|
10200
10442
|
var handleMouseUp = React.useCallback(function (ev, elementId) {
|
|
10201
|
-
var element =
|
|
10443
|
+
var element = elementsState.elements.find(function (ele) { return ele.id === elementId; });
|
|
10202
10444
|
var paperPosition = windowsPositionToPaperPosition({
|
|
10203
10445
|
x: ev.clientX,
|
|
10204
10446
|
y: ev.clientY
|
|
@@ -10206,9 +10448,9 @@ var Paper = function (props) {
|
|
|
10206
10448
|
if (element) {
|
|
10207
10449
|
onElementMouseUp === null || onElementMouseUp === void 0 ? void 0 : onElementMouseUp(ev, element, paperPosition);
|
|
10208
10450
|
}
|
|
10209
|
-
}, [onElementMouseUp]);
|
|
10451
|
+
}, [onElementMouseUp, elementsState]);
|
|
10210
10452
|
var handleMouseDown = React.useCallback(function (ev, elementId) {
|
|
10211
|
-
var element =
|
|
10453
|
+
var element = elementsState.elements.find(function (ele) { return ele.id === elementId; });
|
|
10212
10454
|
var paperPosition = windowsPositionToPaperPosition({
|
|
10213
10455
|
x: ev.clientX,
|
|
10214
10456
|
y: ev.clientY
|
|
@@ -10216,9 +10458,9 @@ var Paper = function (props) {
|
|
|
10216
10458
|
if (element) {
|
|
10217
10459
|
onElementMouseDown === null || onElementMouseDown === void 0 ? void 0 : onElementMouseDown(ev, element, paperPosition);
|
|
10218
10460
|
}
|
|
10219
|
-
}, [onElementMouseDown]);
|
|
10461
|
+
}, [onElementMouseDown, elementsState]);
|
|
10220
10462
|
var handleMouseMove = React.useCallback(function (ev, elementId) {
|
|
10221
|
-
var element =
|
|
10463
|
+
var element = elementsState.elements.find(function (ele) { return ele.id === elementId; });
|
|
10222
10464
|
var paperPosition = windowsPositionToPaperPosition({
|
|
10223
10465
|
x: ev.clientX,
|
|
10224
10466
|
y: ev.clientY
|
|
@@ -10226,9 +10468,9 @@ var Paper = function (props) {
|
|
|
10226
10468
|
if (element) {
|
|
10227
10469
|
onElementMouseMove === null || onElementMouseMove === void 0 ? void 0 : onElementMouseMove(ev, element, paperPosition);
|
|
10228
10470
|
}
|
|
10229
|
-
}, [onElementMouseMove]);
|
|
10471
|
+
}, [onElementMouseMove, elementsState]);
|
|
10230
10472
|
var handleMouseLeave = React.useCallback(function (ev, elementId) {
|
|
10231
|
-
var element =
|
|
10473
|
+
var element = elementsState.elements.find(function (ele) { return ele.id === elementId; });
|
|
10232
10474
|
var paperPosition = windowsPositionToPaperPosition({
|
|
10233
10475
|
x: ev.clientX,
|
|
10234
10476
|
y: ev.clientY
|
|
@@ -10236,109 +10478,38 @@ var Paper = function (props) {
|
|
|
10236
10478
|
if (element) {
|
|
10237
10479
|
onElementMouseLeave === null || onElementMouseLeave === void 0 ? void 0 : onElementMouseLeave(ev, element, paperPosition);
|
|
10238
10480
|
}
|
|
10239
|
-
}, [onElementMouseLeave]);
|
|
10481
|
+
}, [onElementMouseLeave, elementsState]);
|
|
10240
10482
|
var renderElementInTree = React.useCallback(function (element) {
|
|
10483
|
+
var _a;
|
|
10241
10484
|
logger.info("Rendering element tree for element ".concat(element.id));
|
|
10242
10485
|
//use the defined react element or the default Element component
|
|
10243
10486
|
var ReactElement = element.reactElement || Element$1;
|
|
10244
10487
|
return (React.createElement("g", { id: "group-of-element-".concat(element.id), key: element.id },
|
|
10245
|
-
React.createElement(ReactElement, { key: "element-".concat(element.id
|
|
10488
|
+
React.createElement(ReactElement, { key: "element-".concat(element.id, "-").concat(element.version), element: element,
|
|
10489
|
+
//id={element.id}
|
|
10490
|
+
//ref={(refDOM) => element.DOM = refDOM}
|
|
10491
|
+
//height={element.size.height}
|
|
10492
|
+
//width={element.size.width}
|
|
10493
|
+
//x={element.positionAnchor === PositioningAnchor.Center ? element.position.x - element.size.width / 2 : element.position.x}
|
|
10494
|
+
//y={element.positionAnchor === PositioningAnchor.Center ? element.position.y - element.size.height / 2 : element.position.y}
|
|
10495
|
+
//selectable={element.selectable}
|
|
10496
|
+
onClick: handleElementClicked, onContextMenu: handleContextMenu, onMouseUp: handleMouseUp, onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onMouseLeave: handleMouseLeave, onMoving: onElementMoving, onMoved: handleElementMoved, onResized: handleElementResized, container: paperContainerRef.current,
|
|
10497
|
+
// renderShape={element.renderShape}
|
|
10498
|
+
// cssClass={element.cssClass}
|
|
10499
|
+
// texts={element.texts}
|
|
10500
|
+
// ports={element.ports}
|
|
10501
|
+
// portMoveableAreas={element.portMoveableAreas}
|
|
10502
|
+
// portSlideRailSVGClassName={element.portSlideRailSVGClassName}
|
|
10503
|
+
// portDirection={element.portDirection}
|
|
10504
|
+
// defaultPortSize={element.defaultPortSize}
|
|
10505
|
+
onPortMoved: handlePortMoved, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp,
|
|
10246
10506
|
// onPortsChanged={handlePortsChanged}
|
|
10247
10507
|
onPortContextMenu: handlePortContextMenu,
|
|
10248
10508
|
// portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
|
|
10249
|
-
onMouseUpAtLinkedPortPlaceholder: handleMouseUpAtLinkedPortPlaceholder,
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
enabled: true,
|
|
10254
|
-
keepRatio: true
|
|
10255
|
-
}, objectX: selectedElementAbsPosition === null || selectedElementAbsPosition === void 0 ? void 0 : selectedElementAbsPosition.x, objectY: selectedElementAbsPosition === null || selectedElementAbsPosition === void 0 ? void 0 : selectedElementAbsPosition.y, width: selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.size.width, height: selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.size.height, zoom: zoom, draggingByDefault: autoEnabledDraggingSelectedElement,
|
|
10256
|
-
//movingOffsetThreshold: ELEMENT_MOVING_OFFSET_THRESHOLD,
|
|
10257
|
-
onMouseDown: function (ev) {
|
|
10258
|
-
if (selectedElement) {
|
|
10259
|
-
var paperPosition = windowsPositionToPaperPosition({
|
|
10260
|
-
x: ev.clientX,
|
|
10261
|
-
y: ev.clientY
|
|
10262
|
-
}, paperContainerRef.current, zoomRef.current);
|
|
10263
|
-
onElementMouseDown === null || onElementMouseDown === void 0 ? void 0 : onElementMouseDown(ev, selectedElement, paperPosition);
|
|
10264
|
-
}
|
|
10265
|
-
}, onMouseUp: function (ev) {
|
|
10266
|
-
if (selectedElement) {
|
|
10267
|
-
var paperPosition = windowsPositionToPaperPosition({
|
|
10268
|
-
x: ev.clientX,
|
|
10269
|
-
y: ev.clientY
|
|
10270
|
-
}, paperContainerRef.current, zoomRef.current);
|
|
10271
|
-
onElementMouseUp === null || onElementMouseUp === void 0 ? void 0 : onElementMouseUp(ev, selectedElement, paperPosition);
|
|
10272
|
-
}
|
|
10273
|
-
}, onMove: function (newX, newY) {
|
|
10274
|
-
if (!selectedElement)
|
|
10275
|
-
return;
|
|
10276
|
-
var oldPosition = __assign({}, selectedElement.position);
|
|
10277
|
-
// Relative position to the paper container
|
|
10278
|
-
var paperPosition = {
|
|
10279
|
-
x: newX,
|
|
10280
|
-
y: newY
|
|
10281
|
-
};
|
|
10282
|
-
//Call onElementMoving to check if the element should be moved or not
|
|
10283
|
-
if (onElementMoving) {
|
|
10284
|
-
var isSkip = onElementMoving(selectedElement, paperPosition);
|
|
10285
|
-
if (!isSkip) {
|
|
10286
|
-
return;
|
|
10287
|
-
}
|
|
10288
|
-
}
|
|
10289
|
-
logger.info("Element ".concat(selectedElement.id, " is dragging to position ").concat(JSON.stringify(paperPosition)));
|
|
10290
|
-
//Adjust position of element if it should move as a port on parent port area
|
|
10291
|
-
if (selectedElement.moveAsPortOnParent && selectedElement.parentElement) {
|
|
10292
|
-
paperPosition = adjustElementPositionOnParentPortArea(selectedElement, paperPosition, true);
|
|
10293
|
-
updateElementPosition(selectedElement, paperPosition.x, paperPosition.y, true);
|
|
10294
|
-
}
|
|
10295
|
-
else {
|
|
10296
|
-
updateElementPosition(selectedElement, paperPosition.x, paperPosition.y, false);
|
|
10297
|
-
}
|
|
10298
|
-
//let newElementPosition = updateElementPosition(selectedElement, newPosition.x, newPosition.y, true)
|
|
10299
|
-
var indexSelectedElement = elementsRef.current.findIndex(function (e) { return e.id === selectedElement.id; });
|
|
10300
|
-
logger.info("Element ".concat(selectedElement.id, " is moving to relative position ").concat(JSON.stringify(selectedElement.position)));
|
|
10301
|
-
// Start updating the position of links connected to the selected element
|
|
10302
|
-
var childElements = getChildOfElement(selectedElement);
|
|
10303
|
-
var elementIds = __spreadArray(__spreadArray([], childElements.map(function (e) { return e.id; }), true), [selectedElement.id], false);
|
|
10304
|
-
var offsetX = selectedElement.position.x - oldPosition.x;
|
|
10305
|
-
var offsetY = selectedElement.position.y - oldPosition.y;
|
|
10306
|
-
// Update position of all points of links that are connected to the selected element
|
|
10307
|
-
var newLinks = linksRef.current.map(function (link) {
|
|
10308
|
-
var isUpdate = elementIds.includes(link.sourceElement.id) && elementIds.includes(link.targetElement.id);
|
|
10309
|
-
if (link.points && isUpdate) {
|
|
10310
|
-
link.points.forEach(function (p) {
|
|
10311
|
-
p.x += offsetX;
|
|
10312
|
-
p.y += offsetY;
|
|
10313
|
-
});
|
|
10314
|
-
}
|
|
10315
|
-
return link;
|
|
10316
|
-
});
|
|
10317
|
-
onLinksChanged === null || onLinksChanged === void 0 ? void 0 : onLinksChanged(newLinks);
|
|
10318
|
-
// End updating the position of links connected to the selected element
|
|
10319
|
-
//Set state to re-render UI with new position
|
|
10320
|
-
rerenderWhenAnyElementChanged();
|
|
10321
|
-
if (onElementMoved) {
|
|
10322
|
-
console.log('onElementMoved', selectedElement.position, paperPosition);
|
|
10323
|
-
onElementMoved(selectedElement.position, selectedElement, indexSelectedElement, paperPosition);
|
|
10324
|
-
}
|
|
10325
|
-
paperEventEmitter.emitElementMoved(selectedElement, oldPosition, selectedElement.position);
|
|
10326
|
-
setMouseDownedOnPaper(false);
|
|
10327
|
-
}, onResize: function (width, height) {
|
|
10328
|
-
if (!selectedElement)
|
|
10329
|
-
return;
|
|
10330
|
-
var indexSelectedElement = elementsRef.current.findIndex(function (e) { return e.id === selectedElement.id; });
|
|
10331
|
-
var oldSize = selectedElement.size;
|
|
10332
|
-
var newSize = { width: width, height: height };
|
|
10333
|
-
elementsRef.current[indexSelectedElement].size = newSize;
|
|
10334
|
-
rerenderWhenAnyElementChanged();
|
|
10335
|
-
if (onElementResized) {
|
|
10336
|
-
onElementResized(newSize, selectedElement, indexSelectedElement);
|
|
10337
|
-
}
|
|
10338
|
-
paperEventEmitter.emitElementResized(selectedElement, oldSize, newSize);
|
|
10339
|
-
setMouseDownedOnPaper(false);
|
|
10340
|
-
} }))));
|
|
10341
|
-
}, [manuallyTriggerRenderPortHandler, handleElementClicked, handleContextMenu, handleMouseUp, handleMouseDown, handleMouseMove, handleMouseLeave, handlePortMoved, handlePortMouseDown, handlePortMouseUp, handlePortContextMenu, handleMouseUpAtLinkedPortPlaceholder, handleElementTextChange, selectedElement, selectedElementSVG, selectedElementAbsPosition === null || selectedElementAbsPosition === void 0 ? void 0 : selectedElementAbsPosition.x, selectedElementAbsPosition === null || selectedElementAbsPosition === void 0 ? void 0 : selectedElementAbsPosition.y, zoom, autoEnabledDraggingSelectedElement, getChildOfElement, paperEventEmitter, onElementResized, onElementMoved, onElementMouseDown, onElementMouseUp, onLinksChanged, onElementMoving, rerenderWhenAnyElementChanged]);
|
|
10509
|
+
onMouseUpAtLinkedPortPlaceholder: handleMouseUpAtLinkedPortPlaceholder,
|
|
10510
|
+
// onTextUpdated={handleElementTextChange}
|
|
10511
|
+
onManuallyTriggerRenderPort: manuallyTriggerRenderPortHandler, parentDOM: (_a = element.parentElementInTree) === null || _a === void 0 ? void 0 : _a.DOM, beingSelected: (selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.id) === element.id, draggingByDefault: autoEnabledDraggingSelectedElement && (selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.id) === element.id }, element.childrenElementsInTree && element.childrenElementsInTree.map(renderElementInTree))));
|
|
10512
|
+
}, [handleElementClicked, handleContextMenu, handleMouseUp, handleMouseDown, handleMouseMove, handleMouseLeave, onElementMoving, handleElementMoved, handleElementResized, handlePortMoved, handlePortMouseDown, handlePortMouseUp, handlePortContextMenu, handleMouseUpAtLinkedPortPlaceholder, manuallyTriggerRenderPortHandler, selectedElement === null || selectedElement === void 0 ? void 0 : selectedElement.id, autoEnabledDraggingSelectedElement]);
|
|
10342
10513
|
var ElementsInTree = React.useMemo(function () {
|
|
10343
10514
|
return elementsState.elementsInTree.map(function (element, index) {
|
|
10344
10515
|
return renderElementInTree(element);
|
|
@@ -10351,18 +10522,11 @@ var Paper = function (props) {
|
|
|
10351
10522
|
links && links.map(function (link, index) {
|
|
10352
10523
|
if (!link.targetElement || !link.targetPort)
|
|
10353
10524
|
return null;
|
|
10354
|
-
return (React.createElement(ElementLink, { key: link.id, id: link.id, path: link.path,
|
|
10355
|
-
|
|
10356
|
-
|
|
10357
|
-
}, targetPosition: {
|
|
10358
|
-
x: getAbsolutePosition(link.targetElement).x + link.targetPort.position.x,
|
|
10359
|
-
y: getAbsolutePosition(link.targetElement).y + link.targetPort.position.y
|
|
10360
|
-
}, points: link.points, onPathChanged: handlePathChange, onPointsChanged: handlePointsOfLinkChange, onClickDelete: handleClickLinkDelete(link, index), onSelected: function () { return handleSelectLink(link); }, onDeselected: function () { return handleDeselectLink(); }, container: paperContainerRef.current, markerStart: link.markerStart, markerEnd: link.markerEnd, markerDistanceFromPort: link.markerDistanceFromPort, markerSize: link.markerSize, label: link.label, sourceLabel: link.sourceLabel, targetLabel: link.targetLabel, onLabelMoved: onLabelMoved(index), onLabelResized: onLabelResized(index), onLabelContentChanged: onLabelContentChanged(index) }));
|
|
10525
|
+
return (React.createElement(ElementLink, { key: link.id, id: link.id, path: link.path, sourcePositionX: getAbsolutePosition(link.sourceElement).x + link.sourcePort.position.x, sourcePositionY: getAbsolutePosition(link.sourceElement).y + link.sourcePort.position.y, targetPositionX: getAbsolutePosition(link.targetElement).x + link.targetPort.position.x, targetPositionY: getAbsolutePosition(link.targetElement).y + link.targetPort.position.y, points: link.points,
|
|
10526
|
+
//onPathChanged={handlePathChange}
|
|
10527
|
+
onPointsChanged: handlePointsOfLinkChange, onClickDelete: handleClickLinkDelete(link, index), onSelected: function () { return handleSelectLink(link); }, onDeselected: function () { return handleDeselectLink(); }, container: paperContainerRef.current, markerStart: link.markerStart, markerEnd: link.markerEnd, markerDistanceFromPort: link.markerDistanceFromPort, markerSize: link.markerSize, label: link.label, sourceLabel: link.sourceLabel, targetLabel: link.targetLabel, onLabelMoved: onLabelMoved(index), onLabelResized: onLabelResized(index), onLabelContentChanged: onLabelContentChanged(index) }));
|
|
10361
10528
|
}),
|
|
10362
|
-
(tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React.createElement(ElementLink, { id: tempLink.id, points: tempLink.points,
|
|
10363
|
-
x: getAbsolutePosition(tempLink.sourceElement).x + tempLink.sourcePort.position.x,
|
|
10364
|
-
y: getAbsolutePosition(tempLink.sourceElement).y + tempLink.sourcePort.position.y
|
|
10365
|
-
}, targetPosition: tempLink.tempTargetPosition, container: paperContainerRef.current, markerStart: tempLink.markerStart, markerEnd: tempLink.markerEnd, markerDistanceFromPort: tempLink.markerDistanceFromPort, markerSize: tempLink.markerSize }),
|
|
10529
|
+
(tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React.createElement(ElementLink, { id: tempLink.id, points: tempLink.points, sourcePositionX: getAbsolutePosition(tempLink.sourceElement).x + tempLink.sourcePort.position.x, sourcePositionY: getAbsolutePosition(tempLink.sourceElement).y + tempLink.sourcePort.position.y, targetPositionX: tempLink.tempTargetPosition.x, targetPositionY: tempLink.tempTargetPosition.y, container: paperContainerRef.current, markerStart: tempLink.markerStart, markerEnd: tempLink.markerEnd, markerDistanceFromPort: tempLink.markerDistanceFromPort, markerSize: tempLink.markerSize }),
|
|
10366
10530
|
texts.map(function (text, index) { return (React.createElement(Text$1, { key: text.id, id: text.id, x: text.position.x, y: text.position.y, width: text.size.width, height: text.size.height, editable: text.editable, selectable: text.selectable, fontSize: text.fontSize, border: text.border, container: paperContainerRef.current, content: text.content, align: text.align, onSelected: function () {
|
|
10367
10531
|
setSelectedText(text);
|
|
10368
10532
|
} })); })),
|
|
@@ -10471,7 +10635,7 @@ var Editor = function (_a) {
|
|
|
10471
10635
|
if (editorContext.onElementMovingHandler) {
|
|
10472
10636
|
return editorContext.onElementMovingHandler(element, newPaperPosition);
|
|
10473
10637
|
}
|
|
10474
|
-
return true;
|
|
10638
|
+
return { horizontalAllowed: true, verticalAllowed: true };
|
|
10475
10639
|
}, [editorContext]);
|
|
10476
10640
|
var handleOnCreatingPortByLinking = React.useCallback(function (sourceElement, sourcePort, targetElement, position) {
|
|
10477
10641
|
if (editorContext.onCreatingPortByLinkingHandler) {
|
|
@@ -10489,7 +10653,8 @@ var Editor = function (_a) {
|
|
|
10489
10653
|
editorContext.onPaperMouseUpHandler(position);
|
|
10490
10654
|
}, [editorContext]);
|
|
10491
10655
|
var handleElementRemoved = React.useCallback(function (element) {
|
|
10492
|
-
|
|
10656
|
+
var _a;
|
|
10657
|
+
editorContext.onElementRemovedHandler(element.id, (_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.id);
|
|
10493
10658
|
}, [editorContext]);
|
|
10494
10659
|
return (React.createElement(EditorConfigurationContextProvider, { value: editorContext.configuration },
|
|
10495
10660
|
React.createElement(ZoomContextProvider, null,
|