orcasvn-react-diagrams 0.1.29 → 0.1.31
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 +119 -73
- package/dist/cjs/types/models/IElement.d.ts +1 -0
- package/dist/cjs/types/models/implementations/Element.d.ts +2 -0
- package/dist/cjs/types/utils/positionUtil.d.ts +1 -0
- package/dist/esm/index.js +119 -73
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/models/IElement.d.ts +1 -0
- package/dist/esm/types/models/implementations/Element.d.ts +2 -0
- package/dist/esm/types/utils/positionUtil.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -36,6 +36,49 @@ exports.TextAlign = void 0;
|
|
|
36
36
|
TextAlign[TextAlign["center"] = 2] = "center";
|
|
37
37
|
})(exports.TextAlign || (exports.TextAlign = {}));
|
|
38
38
|
|
|
39
|
+
/******************************************************************************
|
|
40
|
+
Copyright (c) Microsoft Corporation.
|
|
41
|
+
|
|
42
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
43
|
+
purpose with or without fee is hereby granted.
|
|
44
|
+
|
|
45
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
46
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
47
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
48
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
49
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
50
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
51
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
52
|
+
***************************************************************************** */
|
|
53
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
var __assign = function() {
|
|
57
|
+
__assign = Object.assign || function __assign(t) {
|
|
58
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
59
|
+
s = arguments[i];
|
|
60
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
61
|
+
}
|
|
62
|
+
return t;
|
|
63
|
+
};
|
|
64
|
+
return __assign.apply(this, arguments);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function __spreadArray(to, from, pack) {
|
|
68
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
69
|
+
if (ar || !(i in from)) {
|
|
70
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
71
|
+
ar[i] = from[i];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
78
|
+
var e = new Error(message);
|
|
79
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
80
|
+
};
|
|
81
|
+
|
|
39
82
|
function getDefaultExportFromCjs (x) {
|
|
40
83
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
41
84
|
}
|
|
@@ -443,6 +486,7 @@ function generateUniqueId() {
|
|
|
443
486
|
var Element$2 = /** @class */ (function () {
|
|
444
487
|
function Element(x, y, width, height, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection, parentElement, textsPlaceHolderClassName, textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition) {
|
|
445
488
|
if (portMovealeAreas === void 0) { portMovealeAreas = []; }
|
|
489
|
+
this._childrenElements = [];
|
|
446
490
|
this.resizability = {
|
|
447
491
|
enabled: true,
|
|
448
492
|
keepRatio: false
|
|
@@ -519,9 +563,34 @@ var Element$2 = /** @class */ (function () {
|
|
|
519
563
|
return this._parentElement;
|
|
520
564
|
},
|
|
521
565
|
set: function (value) {
|
|
566
|
+
var _this = this;
|
|
522
567
|
var oldParent = this._parentElement;
|
|
568
|
+
if ((oldParent === null || oldParent === void 0 ? void 0 : oldParent.id) === (value === null || value === void 0 ? void 0 : value.id))
|
|
569
|
+
return;
|
|
523
570
|
this._parentElement = value;
|
|
524
571
|
this._eventEmitter.emit('parentChanged', oldParent, value);
|
|
572
|
+
if (value) {
|
|
573
|
+
value.childrenElements = __spreadArray(__spreadArray([], value.childrenElements, true), [this], false);
|
|
574
|
+
}
|
|
575
|
+
var index = oldParent === null || oldParent === void 0 ? void 0 : oldParent.childrenElements.findIndex(function (e) { return e.id === _this.id; });
|
|
576
|
+
if (index !== undefined && index !== -1) {
|
|
577
|
+
oldParent === null || oldParent === void 0 ? void 0 : oldParent.childrenElements.splice(index, 1);
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
enumerable: false,
|
|
581
|
+
configurable: true
|
|
582
|
+
});
|
|
583
|
+
Object.defineProperty(Element.prototype, "childrenElements", {
|
|
584
|
+
get: function () {
|
|
585
|
+
return this._childrenElements;
|
|
586
|
+
},
|
|
587
|
+
/** @internal */
|
|
588
|
+
/**
|
|
589
|
+
* Warning: This setter should only be used if you fully understand its implications.
|
|
590
|
+
* Directly setting childrenElements can lead to inconsistencies in the element hierarchy. Please only use this in the setter of parentElement of the child element.
|
|
591
|
+
*/
|
|
592
|
+
set: function (value) {
|
|
593
|
+
this._childrenElements = value;
|
|
525
594
|
},
|
|
526
595
|
enumerable: false,
|
|
527
596
|
configurable: true
|
|
@@ -577,49 +646,6 @@ var Element$2 = /** @class */ (function () {
|
|
|
577
646
|
return Element;
|
|
578
647
|
}());
|
|
579
648
|
|
|
580
|
-
/******************************************************************************
|
|
581
|
-
Copyright (c) Microsoft Corporation.
|
|
582
|
-
|
|
583
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
584
|
-
purpose with or without fee is hereby granted.
|
|
585
|
-
|
|
586
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
587
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
588
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
589
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
590
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
591
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
592
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
593
|
-
***************************************************************************** */
|
|
594
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
var __assign = function() {
|
|
598
|
-
__assign = Object.assign || function __assign(t) {
|
|
599
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
600
|
-
s = arguments[i];
|
|
601
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
602
|
-
}
|
|
603
|
-
return t;
|
|
604
|
-
};
|
|
605
|
-
return __assign.apply(this, arguments);
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
function __spreadArray(to, from, pack) {
|
|
609
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
610
|
-
if (ar || !(i in from)) {
|
|
611
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
612
|
-
ar[i] = from[i];
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
619
|
-
var e = new Error(message);
|
|
620
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
621
|
-
};
|
|
622
|
-
|
|
623
649
|
var ShapeWrapper = React.forwardRef(function (shapeProps, ref) {
|
|
624
650
|
//if direction is provided, rotation is based on direction
|
|
625
651
|
var rotation = shapeProps.rotation || 0;
|
|
@@ -7505,12 +7531,12 @@ var checkPointContainsPolygon = function (position, polygonPoints) {
|
|
|
7505
7531
|
*/
|
|
7506
7532
|
var makePolygonOfElement = function (ele) {
|
|
7507
7533
|
var polygon = new Flatten$1.Polygon();
|
|
7508
|
-
var
|
|
7534
|
+
var vertexes = getFourVertexesOfBBoxFromElement(ele);
|
|
7509
7535
|
polygon.addFace([
|
|
7510
|
-
Flatten$1.point(
|
|
7511
|
-
Flatten$1.point(
|
|
7512
|
-
Flatten$1.point(
|
|
7513
|
-
Flatten$1.point(
|
|
7536
|
+
Flatten$1.point(vertexes[0].x, vertexes[0].y),
|
|
7537
|
+
Flatten$1.point(vertexes[1].x, vertexes[1].y),
|
|
7538
|
+
Flatten$1.point(vertexes[2].x, vertexes[2].y),
|
|
7539
|
+
Flatten$1.point(vertexes[3].x, vertexes[3].y),
|
|
7514
7540
|
]);
|
|
7515
7541
|
return polygon;
|
|
7516
7542
|
};
|
|
@@ -7552,46 +7578,30 @@ var getFirstIntersection = function (startPosition, endPosition, elements) {
|
|
|
7552
7578
|
//Find a point next to an element from a point on the element
|
|
7553
7579
|
var generateSubstitutePosition = function (intersectedPosition, targetPosition, ele) {
|
|
7554
7580
|
var translationOffset = 20;
|
|
7555
|
-
var
|
|
7556
|
-
var vertex1Position = {
|
|
7557
|
-
x: ele.position.x + strokeWidthOffset,
|
|
7558
|
-
y: ele.position.y + strokeWidthOffset,
|
|
7559
|
-
};
|
|
7560
|
-
var vertex2Position = {
|
|
7561
|
-
x: ele.position.x + ele.size.width - strokeWidthOffset,
|
|
7562
|
-
y: ele.position.y + strokeWidthOffset,
|
|
7563
|
-
};
|
|
7564
|
-
var vertex3Position = {
|
|
7565
|
-
x: ele.position.x + ele.size.width - strokeWidthOffset,
|
|
7566
|
-
y: ele.position.y + ele.size.height - strokeWidthOffset,
|
|
7567
|
-
};
|
|
7568
|
-
var vertex4Position = {
|
|
7569
|
-
x: ele.position.x + strokeWidthOffset,
|
|
7570
|
-
y: ele.position.y + ele.size.height - strokeWidthOffset,
|
|
7571
|
-
};
|
|
7581
|
+
var _a = getFourVertexesOfBBoxFromElement(ele), vertex1Position = _a[0], vertex2Position = _a[1], vertex3Position = _a[2], vertex4Position = _a[3];
|
|
7572
7582
|
var replacementPosition = null;
|
|
7573
|
-
if (checkSamePosition(vertex1Position, intersectedPosition,
|
|
7583
|
+
if (checkSamePosition(vertex1Position, intersectedPosition, 0)) {
|
|
7574
7584
|
//Cut at vertex 1 of bbox, move out a distance x,y
|
|
7575
7585
|
replacementPosition = {
|
|
7576
7586
|
x: vertex1Position.x - translationOffset,
|
|
7577
7587
|
y: vertex1Position.y - translationOffset,
|
|
7578
7588
|
};
|
|
7579
7589
|
}
|
|
7580
|
-
else if (checkSamePosition(vertex2Position, intersectedPosition,
|
|
7590
|
+
else if (checkSamePosition(vertex2Position, intersectedPosition, 0)) {
|
|
7581
7591
|
//Cut at vertex 2 of bbox, move out a distance x,y
|
|
7582
7592
|
replacementPosition = {
|
|
7583
7593
|
x: vertex2Position.x + translationOffset,
|
|
7584
7594
|
y: vertex2Position.y - translationOffset,
|
|
7585
7595
|
};
|
|
7586
7596
|
}
|
|
7587
|
-
else if (checkSamePosition(vertex3Position, intersectedPosition,
|
|
7597
|
+
else if (checkSamePosition(vertex3Position, intersectedPosition, 0)) {
|
|
7588
7598
|
//Cut at vertex 3 of bbox, move out a distance x,y
|
|
7589
7599
|
replacementPosition = {
|
|
7590
7600
|
x: vertex3Position.x + translationOffset,
|
|
7591
7601
|
y: vertex3Position.y + translationOffset,
|
|
7592
7602
|
};
|
|
7593
7603
|
}
|
|
7594
|
-
else if (checkSamePosition(vertex4Position, intersectedPosition,
|
|
7604
|
+
else if (checkSamePosition(vertex4Position, intersectedPosition, 0)) {
|
|
7595
7605
|
//Cut at vertex 4 of bbox, move out a distance x,y
|
|
7596
7606
|
replacementPosition = {
|
|
7597
7607
|
x: vertex4Position.x - translationOffset,
|
|
@@ -7699,6 +7709,25 @@ var getRelativePosition = function (clientPosition, relativeElement) {
|
|
|
7699
7709
|
x: clientPosition.x - relativeRect.left,
|
|
7700
7710
|
y: clientPosition.y - relativeRect.top,
|
|
7701
7711
|
};
|
|
7712
|
+
};
|
|
7713
|
+
var getFourVertexesOfBBoxFromElement = function (element) {
|
|
7714
|
+
var vertex1Position = {
|
|
7715
|
+
x: element.position.x,
|
|
7716
|
+
y: element.position.y
|
|
7717
|
+
};
|
|
7718
|
+
var vertex2Position = {
|
|
7719
|
+
x: element.position.x + element.size.width,
|
|
7720
|
+
y: element.position.y
|
|
7721
|
+
};
|
|
7722
|
+
var vertex3Position = {
|
|
7723
|
+
x: element.position.x + element.size.width,
|
|
7724
|
+
y: element.position.y + element.size.height
|
|
7725
|
+
};
|
|
7726
|
+
var vertex4Position = {
|
|
7727
|
+
x: element.position.x,
|
|
7728
|
+
y: element.position.y + element.size.height
|
|
7729
|
+
};
|
|
7730
|
+
return [vertex1Position, vertex2Position, vertex3Position, vertex4Position];
|
|
7702
7731
|
};
|
|
7703
7732
|
|
|
7704
7733
|
var makerStart = React.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
|
|
@@ -8058,7 +8087,7 @@ var Element = function (props) {
|
|
|
8058
8087
|
}, [ports]);
|
|
8059
8088
|
React.useEffect(function () {
|
|
8060
8089
|
var _a;
|
|
8061
|
-
console.info('Rendering Element ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content) || id);
|
|
8090
|
+
console.info('Rendering Element ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content) || id, props.ports);
|
|
8062
8091
|
});
|
|
8063
8092
|
//Listen a new port is created, after add new port to ports state
|
|
8064
8093
|
React.useEffect(function () {
|
|
@@ -8703,7 +8732,7 @@ function convertElementsToTree(elements) {
|
|
|
8703
8732
|
//Find child elements in the child elements, that is possible child of element, then return element with child of it.
|
|
8704
8733
|
function findChildElementsOfNode(elementNodeInTree, possibleChildElements) {
|
|
8705
8734
|
if (possibleChildElements.length === 0) {
|
|
8706
|
-
elementNodeInTree.
|
|
8735
|
+
elementNodeInTree.childrenElementsInTree = undefined;
|
|
8707
8736
|
return elementNodeInTree;
|
|
8708
8737
|
}
|
|
8709
8738
|
var foundChildElements = possibleChildElements.filter(function (ele) { var _a; return ((_a = ele.parentElement) === null || _a === void 0 ? void 0 : _a.id) === elementNodeInTree.id; });
|
|
@@ -8839,7 +8868,7 @@ var Paper = function (props) {
|
|
|
8839
8868
|
parentChangedCancelers.forEach(function (canceller) { return canceller === null || canceller === void 0 ? void 0 : canceller(); });
|
|
8840
8869
|
addedPortCancelers.forEach(function (canceller) { return canceller(); });
|
|
8841
8870
|
};
|
|
8842
|
-
}, []);
|
|
8871
|
+
}, [elements]);
|
|
8843
8872
|
//Update elements tree when length of elements change
|
|
8844
8873
|
React.useEffect(function () {
|
|
8845
8874
|
updateElementsTree();
|
|
@@ -8912,6 +8941,9 @@ var Paper = function (props) {
|
|
|
8912
8941
|
//Automatically add points on the link so that the link does not cross elements, default maximum 10 points
|
|
8913
8942
|
var automationAddPointsToLink = React.useCallback(function (eleLink, limitPoint) {
|
|
8914
8943
|
if (limitPoint === void 0) { limitPoint = 10; }
|
|
8944
|
+
if (!eleLink.targetElement) {
|
|
8945
|
+
throw new Error("Target element is not found in element link");
|
|
8946
|
+
}
|
|
8915
8947
|
var sourceElement = eleLink.sourceElement, sourcePort = eleLink.sourcePort, targetElement = eleLink.targetElement, targetPort = eleLink.targetPort;
|
|
8916
8948
|
var sourcePosition = {
|
|
8917
8949
|
x: sourceElement.position.x + sourcePort.position.x,
|
|
@@ -8921,6 +8953,20 @@ var Paper = function (props) {
|
|
|
8921
8953
|
x: targetElement.position.x + targetPort.position.x,
|
|
8922
8954
|
y: targetElement.position.y + targetPort.position.y
|
|
8923
8955
|
};
|
|
8956
|
+
var fourVertexesOfSourceEleBBox = getFourVertexesOfBBoxFromElement(sourceElement);
|
|
8957
|
+
var fourVertexesOfTargetEleBBox = getFourVertexesOfBBoxFromElement(targetElement);
|
|
8958
|
+
var projectedSourcePositionOnBBox = findNearestProjectedPoint(sourcePosition, [
|
|
8959
|
+
[fourVertexesOfSourceEleBBox[0], fourVertexesOfSourceEleBBox[1]],
|
|
8960
|
+
[fourVertexesOfSourceEleBBox[1], fourVertexesOfSourceEleBBox[2]],
|
|
8961
|
+
[fourVertexesOfSourceEleBBox[2], fourVertexesOfSourceEleBBox[3]],
|
|
8962
|
+
[fourVertexesOfSourceEleBBox[3], fourVertexesOfSourceEleBBox[0]],
|
|
8963
|
+
]);
|
|
8964
|
+
var projectedTargetPositionOnBBox = findNearestProjectedPoint(targetPosition, [
|
|
8965
|
+
[fourVertexesOfTargetEleBBox[0], fourVertexesOfTargetEleBBox[1]],
|
|
8966
|
+
[fourVertexesOfTargetEleBBox[1], fourVertexesOfTargetEleBBox[2]],
|
|
8967
|
+
[fourVertexesOfTargetEleBBox[2], fourVertexesOfTargetEleBBox[3]],
|
|
8968
|
+
[fourVertexesOfTargetEleBBox[3], fourVertexesOfTargetEleBBox[0]],
|
|
8969
|
+
]);
|
|
8924
8970
|
var numberOfPoints = 0;
|
|
8925
8971
|
//create points between the start and end points, to create a line segment that passes through the points without intersecting the elements
|
|
8926
8972
|
function generatePositions(sourcePosition, targetPosition, elements) {
|
|
@@ -8940,7 +8986,7 @@ var Paper = function (props) {
|
|
|
8940
8986
|
return __spreadArray(__spreadArray(__spreadArray([], prependedPoints, true), [replacementPosition], false), appendedPoints, true);
|
|
8941
8987
|
}
|
|
8942
8988
|
var elements = elementsRef.current;
|
|
8943
|
-
var points = generatePositions(
|
|
8989
|
+
var points = generatePositions(projectedSourcePositionOnBBox, projectedTargetPositionOnBBox, elements);
|
|
8944
8990
|
return __assign(__assign({}, eleLink), { points: points });
|
|
8945
8991
|
}, []);
|
|
8946
8992
|
var handlePaperMouseMove = function (ev) {
|
|
@@ -25,6 +25,7 @@ export default interface IElement {
|
|
|
25
25
|
portDirection?: SubObjectDirection;
|
|
26
26
|
defaultPortSize?: number;
|
|
27
27
|
parentElement?: IElement;
|
|
28
|
+
childrenElements: IElement[];
|
|
28
29
|
onParentChanged?: (callback: (oldParent?: IElement, newParent?: IElement) => void) => (() => void);
|
|
29
30
|
addPort: (newPort: IPort) => void;
|
|
30
31
|
onAddedPort: (callback: (newPort: IPort) => void) => (() => void);
|
|
@@ -14,6 +14,7 @@ export default class Element implements IElement {
|
|
|
14
14
|
protected _position: IPosition;
|
|
15
15
|
protected _size: ISize;
|
|
16
16
|
private _parentElement?;
|
|
17
|
+
private _childrenElements;
|
|
17
18
|
cssClass?: string;
|
|
18
19
|
/**
|
|
19
20
|
* @deprecated This property is deprecated and will be removed in future versions.
|
|
@@ -41,6 +42,7 @@ export default class Element implements IElement {
|
|
|
41
42
|
get position(): IPosition;
|
|
42
43
|
get parentElement(): IElement | undefined;
|
|
43
44
|
set parentElement(value: IElement | undefined);
|
|
45
|
+
get childrenElements(): IElement[];
|
|
44
46
|
onParentChanged(callback: (oldParent?: IElement, newParent?: IElement) => void): () => void;
|
|
45
47
|
addPort(newPort: IPort): void;
|
|
46
48
|
onAddedPort(callback: (newPort: IPort) => void): () => void;
|
|
@@ -45,3 +45,4 @@ export declare const getFirstIntersection: (startPosition: IPosition, endPositio
|
|
|
45
45
|
} | undefined;
|
|
46
46
|
export declare const generateSubstitutePosition: (intersectedPosition: IPosition, targetPosition: IPosition, ele: IElement) => IPosition;
|
|
47
47
|
export declare const getRelativePosition: (clientPosition: IPosition, relativeElement: Element) => IPosition;
|
|
48
|
+
export declare const getFourVertexesOfBBoxFromElement: (element: IElement) => IPosition[];
|
package/dist/esm/index.js
CHANGED
|
@@ -32,6 +32,49 @@ var TextAlign;
|
|
|
32
32
|
TextAlign[TextAlign["center"] = 2] = "center";
|
|
33
33
|
})(TextAlign || (TextAlign = {}));
|
|
34
34
|
|
|
35
|
+
/******************************************************************************
|
|
36
|
+
Copyright (c) Microsoft Corporation.
|
|
37
|
+
|
|
38
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
39
|
+
purpose with or without fee is hereby granted.
|
|
40
|
+
|
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
42
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
43
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
44
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
45
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
46
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
47
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
48
|
+
***************************************************************************** */
|
|
49
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
var __assign = function() {
|
|
53
|
+
__assign = Object.assign || function __assign(t) {
|
|
54
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
55
|
+
s = arguments[i];
|
|
56
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
};
|
|
60
|
+
return __assign.apply(this, arguments);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function __spreadArray(to, from, pack) {
|
|
64
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
65
|
+
if (ar || !(i in from)) {
|
|
66
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
67
|
+
ar[i] = from[i];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
74
|
+
var e = new Error(message);
|
|
75
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
76
|
+
};
|
|
77
|
+
|
|
35
78
|
function getDefaultExportFromCjs (x) {
|
|
36
79
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
37
80
|
}
|
|
@@ -439,6 +482,7 @@ function generateUniqueId() {
|
|
|
439
482
|
var Element$2 = /** @class */ (function () {
|
|
440
483
|
function Element(x, y, width, height, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection, parentElement, textsPlaceHolderClassName, textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition) {
|
|
441
484
|
if (portMovealeAreas === void 0) { portMovealeAreas = []; }
|
|
485
|
+
this._childrenElements = [];
|
|
442
486
|
this.resizability = {
|
|
443
487
|
enabled: true,
|
|
444
488
|
keepRatio: false
|
|
@@ -515,9 +559,34 @@ var Element$2 = /** @class */ (function () {
|
|
|
515
559
|
return this._parentElement;
|
|
516
560
|
},
|
|
517
561
|
set: function (value) {
|
|
562
|
+
var _this = this;
|
|
518
563
|
var oldParent = this._parentElement;
|
|
564
|
+
if ((oldParent === null || oldParent === void 0 ? void 0 : oldParent.id) === (value === null || value === void 0 ? void 0 : value.id))
|
|
565
|
+
return;
|
|
519
566
|
this._parentElement = value;
|
|
520
567
|
this._eventEmitter.emit('parentChanged', oldParent, value);
|
|
568
|
+
if (value) {
|
|
569
|
+
value.childrenElements = __spreadArray(__spreadArray([], value.childrenElements, true), [this], false);
|
|
570
|
+
}
|
|
571
|
+
var index = oldParent === null || oldParent === void 0 ? void 0 : oldParent.childrenElements.findIndex(function (e) { return e.id === _this.id; });
|
|
572
|
+
if (index !== undefined && index !== -1) {
|
|
573
|
+
oldParent === null || oldParent === void 0 ? void 0 : oldParent.childrenElements.splice(index, 1);
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
enumerable: false,
|
|
577
|
+
configurable: true
|
|
578
|
+
});
|
|
579
|
+
Object.defineProperty(Element.prototype, "childrenElements", {
|
|
580
|
+
get: function () {
|
|
581
|
+
return this._childrenElements;
|
|
582
|
+
},
|
|
583
|
+
/** @internal */
|
|
584
|
+
/**
|
|
585
|
+
* Warning: This setter should only be used if you fully understand its implications.
|
|
586
|
+
* Directly setting childrenElements can lead to inconsistencies in the element hierarchy. Please only use this in the setter of parentElement of the child element.
|
|
587
|
+
*/
|
|
588
|
+
set: function (value) {
|
|
589
|
+
this._childrenElements = value;
|
|
521
590
|
},
|
|
522
591
|
enumerable: false,
|
|
523
592
|
configurable: true
|
|
@@ -573,49 +642,6 @@ var Element$2 = /** @class */ (function () {
|
|
|
573
642
|
return Element;
|
|
574
643
|
}());
|
|
575
644
|
|
|
576
|
-
/******************************************************************************
|
|
577
|
-
Copyright (c) Microsoft Corporation.
|
|
578
|
-
|
|
579
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
580
|
-
purpose with or without fee is hereby granted.
|
|
581
|
-
|
|
582
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
583
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
584
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
585
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
586
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
587
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
588
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
589
|
-
***************************************************************************** */
|
|
590
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
var __assign = function() {
|
|
594
|
-
__assign = Object.assign || function __assign(t) {
|
|
595
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
596
|
-
s = arguments[i];
|
|
597
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
598
|
-
}
|
|
599
|
-
return t;
|
|
600
|
-
};
|
|
601
|
-
return __assign.apply(this, arguments);
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
function __spreadArray(to, from, pack) {
|
|
605
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
606
|
-
if (ar || !(i in from)) {
|
|
607
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
608
|
-
ar[i] = from[i];
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
615
|
-
var e = new Error(message);
|
|
616
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
617
|
-
};
|
|
618
|
-
|
|
619
645
|
var ShapeWrapper = forwardRef(function (shapeProps, ref) {
|
|
620
646
|
//if direction is provided, rotation is based on direction
|
|
621
647
|
var rotation = shapeProps.rotation || 0;
|
|
@@ -7501,12 +7527,12 @@ var checkPointContainsPolygon = function (position, polygonPoints) {
|
|
|
7501
7527
|
*/
|
|
7502
7528
|
var makePolygonOfElement = function (ele) {
|
|
7503
7529
|
var polygon = new Flatten$1.Polygon();
|
|
7504
|
-
var
|
|
7530
|
+
var vertexes = getFourVertexesOfBBoxFromElement(ele);
|
|
7505
7531
|
polygon.addFace([
|
|
7506
|
-
Flatten$1.point(
|
|
7507
|
-
Flatten$1.point(
|
|
7508
|
-
Flatten$1.point(
|
|
7509
|
-
Flatten$1.point(
|
|
7532
|
+
Flatten$1.point(vertexes[0].x, vertexes[0].y),
|
|
7533
|
+
Flatten$1.point(vertexes[1].x, vertexes[1].y),
|
|
7534
|
+
Flatten$1.point(vertexes[2].x, vertexes[2].y),
|
|
7535
|
+
Flatten$1.point(vertexes[3].x, vertexes[3].y),
|
|
7510
7536
|
]);
|
|
7511
7537
|
return polygon;
|
|
7512
7538
|
};
|
|
@@ -7548,46 +7574,30 @@ var getFirstIntersection = function (startPosition, endPosition, elements) {
|
|
|
7548
7574
|
//Find a point next to an element from a point on the element
|
|
7549
7575
|
var generateSubstitutePosition = function (intersectedPosition, targetPosition, ele) {
|
|
7550
7576
|
var translationOffset = 20;
|
|
7551
|
-
var
|
|
7552
|
-
var vertex1Position = {
|
|
7553
|
-
x: ele.position.x + strokeWidthOffset,
|
|
7554
|
-
y: ele.position.y + strokeWidthOffset,
|
|
7555
|
-
};
|
|
7556
|
-
var vertex2Position = {
|
|
7557
|
-
x: ele.position.x + ele.size.width - strokeWidthOffset,
|
|
7558
|
-
y: ele.position.y + strokeWidthOffset,
|
|
7559
|
-
};
|
|
7560
|
-
var vertex3Position = {
|
|
7561
|
-
x: ele.position.x + ele.size.width - strokeWidthOffset,
|
|
7562
|
-
y: ele.position.y + ele.size.height - strokeWidthOffset,
|
|
7563
|
-
};
|
|
7564
|
-
var vertex4Position = {
|
|
7565
|
-
x: ele.position.x + strokeWidthOffset,
|
|
7566
|
-
y: ele.position.y + ele.size.height - strokeWidthOffset,
|
|
7567
|
-
};
|
|
7577
|
+
var _a = getFourVertexesOfBBoxFromElement(ele), vertex1Position = _a[0], vertex2Position = _a[1], vertex3Position = _a[2], vertex4Position = _a[3];
|
|
7568
7578
|
var replacementPosition = null;
|
|
7569
|
-
if (checkSamePosition(vertex1Position, intersectedPosition,
|
|
7579
|
+
if (checkSamePosition(vertex1Position, intersectedPosition, 0)) {
|
|
7570
7580
|
//Cut at vertex 1 of bbox, move out a distance x,y
|
|
7571
7581
|
replacementPosition = {
|
|
7572
7582
|
x: vertex1Position.x - translationOffset,
|
|
7573
7583
|
y: vertex1Position.y - translationOffset,
|
|
7574
7584
|
};
|
|
7575
7585
|
}
|
|
7576
|
-
else if (checkSamePosition(vertex2Position, intersectedPosition,
|
|
7586
|
+
else if (checkSamePosition(vertex2Position, intersectedPosition, 0)) {
|
|
7577
7587
|
//Cut at vertex 2 of bbox, move out a distance x,y
|
|
7578
7588
|
replacementPosition = {
|
|
7579
7589
|
x: vertex2Position.x + translationOffset,
|
|
7580
7590
|
y: vertex2Position.y - translationOffset,
|
|
7581
7591
|
};
|
|
7582
7592
|
}
|
|
7583
|
-
else if (checkSamePosition(vertex3Position, intersectedPosition,
|
|
7593
|
+
else if (checkSamePosition(vertex3Position, intersectedPosition, 0)) {
|
|
7584
7594
|
//Cut at vertex 3 of bbox, move out a distance x,y
|
|
7585
7595
|
replacementPosition = {
|
|
7586
7596
|
x: vertex3Position.x + translationOffset,
|
|
7587
7597
|
y: vertex3Position.y + translationOffset,
|
|
7588
7598
|
};
|
|
7589
7599
|
}
|
|
7590
|
-
else if (checkSamePosition(vertex4Position, intersectedPosition,
|
|
7600
|
+
else if (checkSamePosition(vertex4Position, intersectedPosition, 0)) {
|
|
7591
7601
|
//Cut at vertex 4 of bbox, move out a distance x,y
|
|
7592
7602
|
replacementPosition = {
|
|
7593
7603
|
x: vertex4Position.x - translationOffset,
|
|
@@ -7695,6 +7705,25 @@ var getRelativePosition = function (clientPosition, relativeElement) {
|
|
|
7695
7705
|
x: clientPosition.x - relativeRect.left,
|
|
7696
7706
|
y: clientPosition.y - relativeRect.top,
|
|
7697
7707
|
};
|
|
7708
|
+
};
|
|
7709
|
+
var getFourVertexesOfBBoxFromElement = function (element) {
|
|
7710
|
+
var vertex1Position = {
|
|
7711
|
+
x: element.position.x,
|
|
7712
|
+
y: element.position.y
|
|
7713
|
+
};
|
|
7714
|
+
var vertex2Position = {
|
|
7715
|
+
x: element.position.x + element.size.width,
|
|
7716
|
+
y: element.position.y
|
|
7717
|
+
};
|
|
7718
|
+
var vertex3Position = {
|
|
7719
|
+
x: element.position.x + element.size.width,
|
|
7720
|
+
y: element.position.y + element.size.height
|
|
7721
|
+
};
|
|
7722
|
+
var vertex4Position = {
|
|
7723
|
+
x: element.position.x,
|
|
7724
|
+
y: element.position.y + element.size.height
|
|
7725
|
+
};
|
|
7726
|
+
return [vertex1Position, vertex2Position, vertex3Position, vertex4Position];
|
|
7698
7727
|
};
|
|
7699
7728
|
|
|
7700
7729
|
var makerStart = React.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
|
|
@@ -8054,7 +8083,7 @@ var Element = function (props) {
|
|
|
8054
8083
|
}, [ports]);
|
|
8055
8084
|
useEffect(function () {
|
|
8056
8085
|
var _a;
|
|
8057
|
-
console.info('Rendering Element ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content) || id);
|
|
8086
|
+
console.info('Rendering Element ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content) || id, props.ports);
|
|
8058
8087
|
});
|
|
8059
8088
|
//Listen a new port is created, after add new port to ports state
|
|
8060
8089
|
useEffect(function () {
|
|
@@ -8699,7 +8728,7 @@ function convertElementsToTree(elements) {
|
|
|
8699
8728
|
//Find child elements in the child elements, that is possible child of element, then return element with child of it.
|
|
8700
8729
|
function findChildElementsOfNode(elementNodeInTree, possibleChildElements) {
|
|
8701
8730
|
if (possibleChildElements.length === 0) {
|
|
8702
|
-
elementNodeInTree.
|
|
8731
|
+
elementNodeInTree.childrenElementsInTree = undefined;
|
|
8703
8732
|
return elementNodeInTree;
|
|
8704
8733
|
}
|
|
8705
8734
|
var foundChildElements = possibleChildElements.filter(function (ele) { var _a; return ((_a = ele.parentElement) === null || _a === void 0 ? void 0 : _a.id) === elementNodeInTree.id; });
|
|
@@ -8835,7 +8864,7 @@ var Paper = function (props) {
|
|
|
8835
8864
|
parentChangedCancelers.forEach(function (canceller) { return canceller === null || canceller === void 0 ? void 0 : canceller(); });
|
|
8836
8865
|
addedPortCancelers.forEach(function (canceller) { return canceller(); });
|
|
8837
8866
|
};
|
|
8838
|
-
}, []);
|
|
8867
|
+
}, [elements]);
|
|
8839
8868
|
//Update elements tree when length of elements change
|
|
8840
8869
|
useEffect(function () {
|
|
8841
8870
|
updateElementsTree();
|
|
@@ -8908,6 +8937,9 @@ var Paper = function (props) {
|
|
|
8908
8937
|
//Automatically add points on the link so that the link does not cross elements, default maximum 10 points
|
|
8909
8938
|
var automationAddPointsToLink = useCallback(function (eleLink, limitPoint) {
|
|
8910
8939
|
if (limitPoint === void 0) { limitPoint = 10; }
|
|
8940
|
+
if (!eleLink.targetElement) {
|
|
8941
|
+
throw new Error("Target element is not found in element link");
|
|
8942
|
+
}
|
|
8911
8943
|
var sourceElement = eleLink.sourceElement, sourcePort = eleLink.sourcePort, targetElement = eleLink.targetElement, targetPort = eleLink.targetPort;
|
|
8912
8944
|
var sourcePosition = {
|
|
8913
8945
|
x: sourceElement.position.x + sourcePort.position.x,
|
|
@@ -8917,6 +8949,20 @@ var Paper = function (props) {
|
|
|
8917
8949
|
x: targetElement.position.x + targetPort.position.x,
|
|
8918
8950
|
y: targetElement.position.y + targetPort.position.y
|
|
8919
8951
|
};
|
|
8952
|
+
var fourVertexesOfSourceEleBBox = getFourVertexesOfBBoxFromElement(sourceElement);
|
|
8953
|
+
var fourVertexesOfTargetEleBBox = getFourVertexesOfBBoxFromElement(targetElement);
|
|
8954
|
+
var projectedSourcePositionOnBBox = findNearestProjectedPoint(sourcePosition, [
|
|
8955
|
+
[fourVertexesOfSourceEleBBox[0], fourVertexesOfSourceEleBBox[1]],
|
|
8956
|
+
[fourVertexesOfSourceEleBBox[1], fourVertexesOfSourceEleBBox[2]],
|
|
8957
|
+
[fourVertexesOfSourceEleBBox[2], fourVertexesOfSourceEleBBox[3]],
|
|
8958
|
+
[fourVertexesOfSourceEleBBox[3], fourVertexesOfSourceEleBBox[0]],
|
|
8959
|
+
]);
|
|
8960
|
+
var projectedTargetPositionOnBBox = findNearestProjectedPoint(targetPosition, [
|
|
8961
|
+
[fourVertexesOfTargetEleBBox[0], fourVertexesOfTargetEleBBox[1]],
|
|
8962
|
+
[fourVertexesOfTargetEleBBox[1], fourVertexesOfTargetEleBBox[2]],
|
|
8963
|
+
[fourVertexesOfTargetEleBBox[2], fourVertexesOfTargetEleBBox[3]],
|
|
8964
|
+
[fourVertexesOfTargetEleBBox[3], fourVertexesOfTargetEleBBox[0]],
|
|
8965
|
+
]);
|
|
8920
8966
|
var numberOfPoints = 0;
|
|
8921
8967
|
//create points between the start and end points, to create a line segment that passes through the points without intersecting the elements
|
|
8922
8968
|
function generatePositions(sourcePosition, targetPosition, elements) {
|
|
@@ -8936,7 +8982,7 @@ var Paper = function (props) {
|
|
|
8936
8982
|
return __spreadArray(__spreadArray(__spreadArray([], prependedPoints, true), [replacementPosition], false), appendedPoints, true);
|
|
8937
8983
|
}
|
|
8938
8984
|
var elements = elementsRef.current;
|
|
8939
|
-
var points = generatePositions(
|
|
8985
|
+
var points = generatePositions(projectedSourcePositionOnBBox, projectedTargetPositionOnBBox, elements);
|
|
8940
8986
|
return __assign(__assign({}, eleLink), { points: points });
|
|
8941
8987
|
}, []);
|
|
8942
8988
|
var handlePaperMouseMove = function (ev) {
|