orcasvn-react-diagrams 0.1.15 → 0.1.17
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 +162 -140
- package/dist/cjs/types/components/paper.d.ts +5 -1
- package/dist/cjs/types/mocks/port1.d.ts +2 -2
- package/dist/cjs/types/mocks/portIn.d.ts +2 -2
- package/dist/cjs/types/models/IPortProps.d.ts +3 -0
- package/dist/cjs/types/models/implementations/EditorContext.d.ts +5 -1
- package/dist/cjs/types/models/implementations/Port.d.ts +6 -2
- package/dist/cjs/types/models/implementations/index.d.ts +0 -2
- package/dist/esm/index.js +163 -139
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/paper.d.ts +5 -1
- package/dist/esm/types/mocks/port1.d.ts +2 -2
- package/dist/esm/types/mocks/portIn.d.ts +2 -2
- package/dist/esm/types/models/IPortProps.d.ts +3 -0
- package/dist/esm/types/models/implementations/EditorContext.d.ts +5 -1
- package/dist/esm/types/models/implementations/Port.d.ts +6 -2
- package/dist/esm/types/models/implementations/index.d.ts +0 -2
- package/dist/index.d.ts +14 -11
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -560,8 +560,100 @@ var Element$1 = /** @class */ (function () {
|
|
|
560
560
|
return Element;
|
|
561
561
|
}());
|
|
562
562
|
|
|
563
|
+
/******************************************************************************
|
|
564
|
+
Copyright (c) Microsoft Corporation.
|
|
565
|
+
|
|
566
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
567
|
+
purpose with or without fee is hereby granted.
|
|
568
|
+
|
|
569
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
570
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
571
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
572
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
573
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
574
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
575
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
576
|
+
***************************************************************************** */
|
|
577
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
var __assign = function() {
|
|
581
|
+
__assign = Object.assign || function __assign(t) {
|
|
582
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
583
|
+
s = arguments[i];
|
|
584
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
585
|
+
}
|
|
586
|
+
return t;
|
|
587
|
+
};
|
|
588
|
+
return __assign.apply(this, arguments);
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
function __spreadArray(to, from, pack) {
|
|
592
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
593
|
+
if (ar || !(i in from)) {
|
|
594
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
595
|
+
ar[i] = from[i];
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
602
|
+
var e = new Error(message);
|
|
603
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
var ShapeWrapper = React$1.forwardRef(function (shapeProps, ref) {
|
|
607
|
+
//if direction is provided, rotation is based on direction
|
|
608
|
+
var rotation = shapeProps.rotation || 0;
|
|
609
|
+
if (shapeProps.direction) {
|
|
610
|
+
switch (shapeProps.direction) {
|
|
611
|
+
case 'left':
|
|
612
|
+
rotation = -90;
|
|
613
|
+
break;
|
|
614
|
+
case 'right':
|
|
615
|
+
rotation = 90;
|
|
616
|
+
break;
|
|
617
|
+
case 'down':
|
|
618
|
+
rotation = 180;
|
|
619
|
+
break;
|
|
620
|
+
default:
|
|
621
|
+
rotation = 0;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
var position = { x: shapeProps.x, y: shapeProps.y };
|
|
626
|
+
var transformOrigin = "center";
|
|
627
|
+
if (typeof shapeProps.positioningAnchor === 'object') {
|
|
628
|
+
position.x = position.x - shapeProps.positioningAnchor.x / 100 * shapeProps.width;
|
|
629
|
+
position.y = position.y - shapeProps.positioningAnchor.y / 100 * shapeProps.height;
|
|
630
|
+
transformOrigin = "".concat(shapeProps.positioningAnchor.x, "% ").concat(shapeProps.positioningAnchor.y, "%");
|
|
631
|
+
}
|
|
632
|
+
else if (shapeProps.positioningAnchor === exports.PositioningAnchor.Center) {
|
|
633
|
+
position.x = position.x - shapeProps.width / 2;
|
|
634
|
+
position.y = position.y - shapeProps.height / 2;
|
|
635
|
+
}
|
|
636
|
+
var objectOfAllEventAttributes = React$1.useMemo(function () {
|
|
637
|
+
var arrayOfAllEventAttributes = Object.entries(shapeProps).filter(function (_a) {
|
|
638
|
+
var k = _a[0]; _a[1];
|
|
639
|
+
return k.startsWith('on');
|
|
640
|
+
});
|
|
641
|
+
return Object.fromEntries(arrayOfAllEventAttributes);
|
|
642
|
+
}, [shapeProps]);
|
|
643
|
+
var viewboxWidth = shapeProps.width > shapeProps.height ? 100 : shapeProps.width / shapeProps.height * 100;
|
|
644
|
+
var viewBoxHeight = shapeProps.height > shapeProps.width ? 100 : shapeProps.height / shapeProps.width * 100;
|
|
645
|
+
var viewBox = shapeProps.viewBox || "0 0 ".concat(viewboxWidth, " ").concat(viewBoxHeight);
|
|
646
|
+
return (React$1.createElement("g", { transform: "rotate(".concat(rotation, ")"), style: { transformOrigin: transformOrigin, transformBox: "content-box" } },
|
|
647
|
+
React$1.createElement("svg", __assign({ ref: ref, style: { overflow: "visible" }, x: position.x, y: position.y, width: shapeProps.width, height: shapeProps.height, className: shapeProps.cssClass, viewBox: viewBox }, objectOfAllEventAttributes), shapeProps.children)));
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
var CustomShape = React$1.forwardRef(function (props, ref) {
|
|
651
|
+
return (React$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref }), props.children));
|
|
652
|
+
});
|
|
653
|
+
|
|
563
654
|
var Port$1 = /** @class */ (function () {
|
|
564
|
-
function Port(x, y, label,
|
|
655
|
+
function Port(x, y, label, shapeRenderer, width, height) {
|
|
656
|
+
var _this = this;
|
|
565
657
|
this._id = generateUniqueId();
|
|
566
658
|
this.position = { x: x, y: y };
|
|
567
659
|
if (!height) {
|
|
@@ -571,7 +663,14 @@ var Port$1 = /** @class */ (function () {
|
|
|
571
663
|
this.size = { width: width, height: height };
|
|
572
664
|
}
|
|
573
665
|
this.label = label;
|
|
574
|
-
|
|
666
|
+
if (shapeRenderer && shapeRenderer.shape) {
|
|
667
|
+
this.renderShape = shapeRenderer.shape;
|
|
668
|
+
}
|
|
669
|
+
else if (shapeRenderer && shapeRenderer.customShapeWithJSX) {
|
|
670
|
+
this.renderShape = React$1.forwardRef(function (props, ref) {
|
|
671
|
+
return (React$1.createElement(CustomShape, { ref: ref, x: props.x, y: props.y, width: props.width, height: props.height, rotation: props.rotation, positioningAnchor: shapeRenderer.positioningAnchor, onClick: function (e) { var _a; return (_a = props.onSelected) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseDown: function (e) { var _a; return (_a = props.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseUp: function (e) { var _a; return (_a = props.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); } }, shapeRenderer.customShapeWithJSX));
|
|
672
|
+
});
|
|
673
|
+
}
|
|
575
674
|
}
|
|
576
675
|
Object.defineProperty(Port.prototype, "id", {
|
|
577
676
|
get: function () {
|
|
@@ -701,130 +800,6 @@ var EditorContext = /** @class */ (function () {
|
|
|
701
800
|
return EditorContext;
|
|
702
801
|
}());
|
|
703
802
|
|
|
704
|
-
/******************************************************************************
|
|
705
|
-
Copyright (c) Microsoft Corporation.
|
|
706
|
-
|
|
707
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
708
|
-
purpose with or without fee is hereby granted.
|
|
709
|
-
|
|
710
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
711
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
712
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
713
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
714
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
715
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
716
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
717
|
-
***************************************************************************** */
|
|
718
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
719
|
-
|
|
720
|
-
var extendStatics = function(d, b) {
|
|
721
|
-
extendStatics = Object.setPrototypeOf ||
|
|
722
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
723
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
724
|
-
return extendStatics(d, b);
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
function __extends(d, b) {
|
|
728
|
-
if (typeof b !== "function" && b !== null)
|
|
729
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
730
|
-
extendStatics(d, b);
|
|
731
|
-
function __() { this.constructor = d; }
|
|
732
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
var __assign = function() {
|
|
736
|
-
__assign = Object.assign || function __assign(t) {
|
|
737
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
738
|
-
s = arguments[i];
|
|
739
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
740
|
-
}
|
|
741
|
-
return t;
|
|
742
|
-
};
|
|
743
|
-
return __assign.apply(this, arguments);
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
function __spreadArray(to, from, pack) {
|
|
747
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
748
|
-
if (ar || !(i in from)) {
|
|
749
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
750
|
-
ar[i] = from[i];
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
757
|
-
var e = new Error(message);
|
|
758
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
var ShapeWrapper = React$1.forwardRef(function (shapeProps, ref) {
|
|
762
|
-
//if direction is provided, rotation is based on direction
|
|
763
|
-
var rotation = shapeProps.rotation || 0;
|
|
764
|
-
if (shapeProps.direction) {
|
|
765
|
-
switch (shapeProps.direction) {
|
|
766
|
-
case 'left':
|
|
767
|
-
rotation = -90;
|
|
768
|
-
break;
|
|
769
|
-
case 'right':
|
|
770
|
-
rotation = 90;
|
|
771
|
-
break;
|
|
772
|
-
case 'down':
|
|
773
|
-
rotation = 180;
|
|
774
|
-
break;
|
|
775
|
-
default:
|
|
776
|
-
rotation = 0;
|
|
777
|
-
break;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
var position = { x: shapeProps.x, y: shapeProps.y };
|
|
781
|
-
var transformOrigin = "center";
|
|
782
|
-
if (typeof shapeProps.positioningAnchor === 'object') {
|
|
783
|
-
position.x = position.x - shapeProps.positioningAnchor.x / 100 * shapeProps.width;
|
|
784
|
-
position.y = position.y - shapeProps.positioningAnchor.y / 100 * shapeProps.height;
|
|
785
|
-
transformOrigin = "".concat(shapeProps.positioningAnchor.x, "% ").concat(shapeProps.positioningAnchor.y, "%");
|
|
786
|
-
}
|
|
787
|
-
else if (shapeProps.positioningAnchor === exports.PositioningAnchor.Center) {
|
|
788
|
-
position.x = position.x - shapeProps.width / 2;
|
|
789
|
-
position.y = position.y - shapeProps.height / 2;
|
|
790
|
-
}
|
|
791
|
-
var objectOfAllEventAttributes = React$1.useMemo(function () {
|
|
792
|
-
var arrayOfAllEventAttributes = Object.entries(shapeProps).filter(function (_a) {
|
|
793
|
-
var k = _a[0]; _a[1];
|
|
794
|
-
return k.startsWith('on');
|
|
795
|
-
});
|
|
796
|
-
return Object.fromEntries(arrayOfAllEventAttributes);
|
|
797
|
-
}, [shapeProps]);
|
|
798
|
-
var viewboxWidth = shapeProps.width > shapeProps.height ? 100 : shapeProps.width / shapeProps.height * 100;
|
|
799
|
-
var viewBoxHeight = shapeProps.height > shapeProps.width ? 100 : shapeProps.height / shapeProps.width * 100;
|
|
800
|
-
var viewBox = shapeProps.viewBox || "0 0 ".concat(viewboxWidth, " ").concat(viewBoxHeight);
|
|
801
|
-
return (React$1.createElement("g", { transform: "rotate(".concat(rotation, ")"), style: { transformOrigin: transformOrigin, transformBox: "content-box" } },
|
|
802
|
-
React$1.createElement("svg", __assign({ ref: ref, style: { overflow: "visible" }, x: position.x, y: position.y, width: shapeProps.width, height: shapeProps.height, className: shapeProps.cssClass, viewBox: viewBox }, objectOfAllEventAttributes), shapeProps.children)));
|
|
803
|
-
});
|
|
804
|
-
|
|
805
|
-
var CustomShape = React$1.forwardRef(function (props, ref) {
|
|
806
|
-
return (React$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref }), props.children));
|
|
807
|
-
});
|
|
808
|
-
|
|
809
|
-
var CustomPortFromJSXElement = /** @class */ (function (_super) {
|
|
810
|
-
__extends(CustomPortFromJSXElement, _super);
|
|
811
|
-
function CustomPortFromJSXElement(x, y, renderCustomShape, label, shapePositioningAnchor, width, height) {
|
|
812
|
-
var _this = _super.call(this, x, y, label, React$1.forwardRef(function (props, ref) {
|
|
813
|
-
return (React$1.createElement(CustomShape, { ref: ref, x: props.x, y: props.y, width: props.width, height: props.height, rotation: props.rotation, positioningAnchor: shapePositioningAnchor, onClick: function (e) { var _a; return (_a = props.onSelected) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseDown: function (e) { var _a; return (_a = props.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseUp: function (e) { var _a; return (_a = props.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); } }, renderCustomShape));
|
|
814
|
-
}), width, height) || this;
|
|
815
|
-
return _this;
|
|
816
|
-
}
|
|
817
|
-
return CustomPortFromJSXElement;
|
|
818
|
-
}(Port$1));
|
|
819
|
-
|
|
820
|
-
var CustomPortFromShape = /** @class */ (function (_super) {
|
|
821
|
-
__extends(CustomPortFromShape, _super);
|
|
822
|
-
function CustomPortFromShape(x, y, shape, label, width, height) {
|
|
823
|
-
return _super.call(this, x, y, label, shape, width, height) || this;
|
|
824
|
-
}
|
|
825
|
-
return CustomPortFromShape;
|
|
826
|
-
}(Port$1));
|
|
827
|
-
|
|
828
803
|
var Circle = React$1.forwardRef(function (props, ref) {
|
|
829
804
|
var s = { height: 100, width: 100 };
|
|
830
805
|
if (props.r) {
|
|
@@ -1482,7 +1457,7 @@ var Text = React$1.forwardRef(function (_a, ref) {
|
|
|
1482
1457
|
var Text$1 = React$1.memo(Text);
|
|
1483
1458
|
|
|
1484
1459
|
var Port1 = React$1.forwardRef(function (props, ref) {
|
|
1485
|
-
var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, container = props.container, label = props.label, onPortLabelMoved = props.onPortLabelMoved, onPortLabelResized = props.onPortLabelResized, onPortLabelContentChanged = props.onPortLabelContentChanged, onSelected = props.onSelected, onMouseDown = props.onMouseDown, onMouseUp = props.onMouseUp, calculateRotationAngle = props.calculateRotationAngle, renderShape = props.renderShape;
|
|
1460
|
+
var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, container = props.container, label = props.label, onPortLabelMoved = props.onPortLabelMoved, onPortLabelResized = props.onPortLabelResized, onPortLabelContentChanged = props.onPortLabelContentChanged, onSelected = props.onSelected, onMouseDown = props.onMouseDown, onMouseUp = props.onMouseUp, onMouseEnter = props.onMouseEnter, onMouseLeave = props.onMouseLeave, onMouseMove = props.onMouseMove, calculateRotationAngle = props.calculateRotationAngle, renderShape = props.renderShape;
|
|
1486
1461
|
var textRef = React$1.useRef(null);
|
|
1487
1462
|
var rotationAngle = React$1.useMemo(function () {
|
|
1488
1463
|
if (!calculateRotationAngle)
|
|
@@ -1500,7 +1475,7 @@ var Port1 = React$1.forwardRef(function (props, ref) {
|
|
|
1500
1475
|
return (React$1.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
|
|
1501
1476
|
}
|
|
1502
1477
|
else {
|
|
1503
|
-
return React$1.createElement(Circle, { onMouseDown: function (e) { return onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(id, e); }, onMouseUp: function (e) { return onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(id, e); }, onClick: function (e) { return onSelected === null || onSelected === void 0 ? void 0 : onSelected(id, e); }, ref: ref, x: x, y: y, positioningAnchor: exports.PositioningAnchor.Center, height: height, width: width, stroke: "black", fill: "black" });
|
|
1478
|
+
return React$1.createElement(Circle, { onMouseDown: function (e) { return onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(id, e); }, onMouseUp: function (e) { return onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(id, e); }, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onMouseMove: onMouseMove, onClick: function (e) { return onSelected === null || onSelected === void 0 ? void 0 : onSelected(id, e); }, ref: ref, x: x, y: y, positioningAnchor: exports.PositioningAnchor.Center, height: height, width: width, stroke: "black", fill: "black" });
|
|
1504
1479
|
}
|
|
1505
1480
|
}, [props]);
|
|
1506
1481
|
return (React$1.createElement(React$1.Fragment, null,
|
|
@@ -8979,11 +8954,12 @@ var Element = function (props) {
|
|
|
8979
8954
|
var _a, _b, _c;
|
|
8980
8955
|
var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container, textsPlaceHolderFlexStyle = props.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition = props.textsPlaceHolderFlexboxPosition, textsPlaceHolderClassName = props.textsPlaceHolderClassName, texts = props.texts, portSlideRailSVGClassName = props.portSlideRailSVGClassName, portMoveableAreas = props.portMoveableAreas, portDirection = props.portDirection, defaultPortSize = props.defaultPortSize, onClick = props.onClick, onContextMenu = props.onContextMenu, renderShape = props.renderShape; props.onMoved; var onPortMoved = props.onPortMoved; props.onResized; var onPortMouseDown = props.onPortMouseDown, onPortMouseUp = props.onPortMouseUp; props.onMouseMove; props.onMouseLeave; props.onMouseUp; var onMouseUpAtLinkedPortPlaceholder = props.onMouseUpAtLinkedPortPlaceholder, onTextUpdated = props.onTextUpdated;
|
|
8981
8956
|
var _d = React$1.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
|
|
8982
|
-
var _e = React$1.useState(
|
|
8957
|
+
var _e = React$1.useState(), hoveredPort = _e[0], setHoveredPort = _e[1];
|
|
8958
|
+
var _f = React$1.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
|
|
8983
8959
|
return __assign(__assign({}, p), { id: p.id, ref: React$1.createRef() });
|
|
8984
|
-
})) !== null && _b !== void 0 ? _b : []), ports =
|
|
8985
|
-
var
|
|
8986
|
-
var
|
|
8960
|
+
})) !== null && _b !== void 0 ? _b : []), ports = _f[0], setPorts = _f[1];
|
|
8961
|
+
var _g = React$1.useState(false), someElementLinkStarted = _g[0], setSomeElementLinkStarted = _g[1];
|
|
8962
|
+
var _h = React$1.useState(), potentialPortPosition = _h[0], setPotentialPortPosition = _h[1];
|
|
8987
8963
|
var _paperEventEmitterContext = React$1.useContext(paperEventEmitterContext);
|
|
8988
8964
|
var elementRef = React$1.useRef(null);
|
|
8989
8965
|
var elementLinkStarted = React$1.useRef();
|
|
@@ -9049,6 +9025,7 @@ var Element = function (props) {
|
|
|
9049
9025
|
elementLinkStarted.current = undefined;
|
|
9050
9026
|
setSomeElementLinkStarted(false);
|
|
9051
9027
|
setPotentialPortPosition(undefined);
|
|
9028
|
+
setHoveredPort(undefined);
|
|
9052
9029
|
});
|
|
9053
9030
|
return function () {
|
|
9054
9031
|
elementStartedListener.off();
|
|
@@ -9187,7 +9164,6 @@ var Element = function (props) {
|
|
|
9187
9164
|
};
|
|
9188
9165
|
//Normalize port position
|
|
9189
9166
|
var normalizePortPosition = function (tempNewPosition) {
|
|
9190
|
-
console.info('normalizePortPosition', tempNewPosition);
|
|
9191
9167
|
var newPosition;
|
|
9192
9168
|
if (portMoveableAreas && portMoveableAreas.length > 0) { //If moveable areas is defined
|
|
9193
9169
|
newPosition = normalizePortPositionOnMoveableAreas(portMoveableAreas, tempNewPosition);
|
|
@@ -9271,6 +9247,11 @@ var Element = function (props) {
|
|
|
9271
9247
|
function handleElementMouseMove(ev) {
|
|
9272
9248
|
//ev.stopPropagation(); //Can't use stopPropagation here, because do not create tempLink
|
|
9273
9249
|
if (someElementLinkStarted && elementRef.current) {
|
|
9250
|
+
//If an element link is being created, calculate the potential port position when the mouse moves over the element.
|
|
9251
|
+
if (hoveredPort) {
|
|
9252
|
+
setPotentialPortPosition(undefined);
|
|
9253
|
+
return;
|
|
9254
|
+
}
|
|
9274
9255
|
/* The above code is calculating the relative position of the mouse within a specific
|
|
9275
9256
|
element on the page. It first gets the bounding rectangle of the element using
|
|
9276
9257
|
`getBoundingClientRect()` and the bounding box of the element using `getBBox()`. Then,
|
|
@@ -9314,7 +9295,7 @@ var Element = function (props) {
|
|
|
9314
9295
|
};
|
|
9315
9296
|
//Get rotate angle of port by port direction is defined.
|
|
9316
9297
|
var rotatePort = React$1.useCallback(function (x, y) {
|
|
9317
|
-
console.info('calculating port rotation', x, y)
|
|
9298
|
+
// console.info('calculating port rotation', x, y)
|
|
9318
9299
|
if (!portSlideRailSVGClassName)
|
|
9319
9300
|
return 0;
|
|
9320
9301
|
var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
|
|
@@ -9379,6 +9360,14 @@ var Element = function (props) {
|
|
|
9379
9360
|
movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
|
|
9380
9361
|
onMove: handlePortMove
|
|
9381
9362
|
});
|
|
9363
|
+
useSelectionFrame({
|
|
9364
|
+
container: container,
|
|
9365
|
+
targetSVGElement: (hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.ref.current) || undefined,
|
|
9366
|
+
resizability: {
|
|
9367
|
+
enabled: false,
|
|
9368
|
+
keepRatio: false
|
|
9369
|
+
},
|
|
9370
|
+
});
|
|
9382
9371
|
return (React$1.createElement(ElementWrapper, { ref: elementRef, x: x, y: y, onClick: function (e) { return onClick ? onClick(id, e, elementRef.current) : true; }, onMouseMove: handleElementMouseMove, onMouseLeave: handleElementMouseLeave, onMouseUp: handleElementMouseUp, onContextMenu: function (e) { return onContextMenu ? onContextMenu(id, e, elementRef.current) : true; } },
|
|
9383
9372
|
renderedShape,
|
|
9384
9373
|
potentialPortPosition && (portPlaceholderShape
|
|
@@ -9388,7 +9377,18 @@ var Element = function (props) {
|
|
|
9388
9377
|
var _a, _b, _c, _d, _e, _f;
|
|
9389
9378
|
return React$1.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: (_c = (_b = (_a = p.size) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : defaultPortSize) !== null && _c !== void 0 ? _c : PORT_DEFAULT_SIZE, height: (_f = (_e = (_d = p.size) === null || _d === void 0 ? void 0 : _d.height) !== null && _e !== void 0 ? _e : defaultPortSize) !== null && _f !== void 0 ? _f : PORT_DEFAULT_SIZE, container: container,
|
|
9390
9379
|
// rotation={rotatePort(p)}
|
|
9391
|
-
calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: function (x, y) { return handlePortLabelMoved(x, y, p, index); }, onPortLabelResized: function (w, h) { return handlePortLabelResized(w, h, p, index); }, onPortLabelContentChanged: function (ev, newValue) { return handlePortLabelContentChanged(newValue, p, index); }, onSelected: function (portId, event) { return handleSelectedPort(p, event); }, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp,
|
|
9380
|
+
calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: function (x, y) { return handlePortLabelMoved(x, y, p, index); }, onPortLabelResized: function (w, h) { return handlePortLabelResized(w, h, p, index); }, onPortLabelContentChanged: function (ev, newValue) { return handlePortLabelContentChanged(newValue, p, index); }, onSelected: function (portId, event) { return handleSelectedPort(p, event); }, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, onMouseMove: function () {
|
|
9381
|
+
if (someElementLinkStarted)
|
|
9382
|
+
setHoveredPort(p);
|
|
9383
|
+
},
|
|
9384
|
+
// onMouseEnter={() => {
|
|
9385
|
+
// if (someElementLinkStarted) setHoveredPort(p)
|
|
9386
|
+
// }}
|
|
9387
|
+
onMouseLeave: function () {
|
|
9388
|
+
console.log('onMouseLeave');
|
|
9389
|
+
if (someElementLinkStarted)
|
|
9390
|
+
setHoveredPort(undefined);
|
|
9391
|
+
}, renderShape: p.renderShape });
|
|
9392
9392
|
}),
|
|
9393
9393
|
React$1.createElement(Flexbox$1, { className: textsPlaceHolderClassName, style: textsPlaceHolderFlexStyle, x: textsPlaceHolderFlexboxPosition === null || textsPlaceHolderFlexboxPosition === void 0 ? void 0 : textsPlaceHolderFlexboxPosition.x, y: textsPlaceHolderFlexboxPosition === null || textsPlaceHolderFlexboxPosition === void 0 ? void 0 : textsPlaceHolderFlexboxPosition.y }, texts === null || texts === void 0 ? void 0 : texts.map(function (t, index) {
|
|
9394
9394
|
var _a, _b;
|
|
@@ -9648,9 +9648,12 @@ var Paper = function (props) {
|
|
|
9648
9648
|
//Listen text is selected
|
|
9649
9649
|
React$1.useEffect(function () {
|
|
9650
9650
|
var textSelectedListener = paperEventEmitter.onTextSelected(function (text) {
|
|
9651
|
+
var _a;
|
|
9651
9652
|
setSelectedElement(undefined);
|
|
9652
9653
|
setSelectedElementSVG(null);
|
|
9653
9654
|
setSelectedLink(undefined);
|
|
9655
|
+
//broadcast selected text to parent component
|
|
9656
|
+
(_a = props.onTextSelected) === null || _a === void 0 ? void 0 : _a.call(props, text);
|
|
9654
9657
|
});
|
|
9655
9658
|
return function () {
|
|
9656
9659
|
textSelectedListener.off();
|
|
@@ -9658,10 +9661,16 @@ var Paper = function (props) {
|
|
|
9658
9661
|
}, []);
|
|
9659
9662
|
//Listen port is selected
|
|
9660
9663
|
React$1.useEffect(function () {
|
|
9661
|
-
var portSelectedListener = paperEventEmitter.onPortSelected(function (port) {
|
|
9664
|
+
var portSelectedListener = paperEventEmitter.onPortSelected(function (port, elementId) {
|
|
9665
|
+
var _a;
|
|
9662
9666
|
setSelectedElement(undefined);
|
|
9663
9667
|
setSelectedElementSVG(null);
|
|
9664
9668
|
setSelectedLink(undefined);
|
|
9669
|
+
//broadcast selected port to parent component
|
|
9670
|
+
var element = elements.find(function (e) { return e.id === elementId; });
|
|
9671
|
+
if (element) {
|
|
9672
|
+
(_a = props.onPortSelected) === null || _a === void 0 ? void 0 : _a.call(props, port, element);
|
|
9673
|
+
}
|
|
9665
9674
|
});
|
|
9666
9675
|
return function () {
|
|
9667
9676
|
portSelectedListener.off();
|
|
@@ -9709,6 +9718,7 @@ var Paper = function (props) {
|
|
|
9709
9718
|
};
|
|
9710
9719
|
//Listen command delete selected for element
|
|
9711
9720
|
React$1.useEffect(function () {
|
|
9721
|
+
var _a;
|
|
9712
9722
|
var listener = paperEventEmitter.onCommandDeleteSelectedElement(function () {
|
|
9713
9723
|
if (selectedElement) {
|
|
9714
9724
|
var deletedChildElements = getDeletedChildElements(selectedElement);
|
|
@@ -9719,30 +9729,44 @@ var Paper = function (props) {
|
|
|
9719
9729
|
setSelectedElementSVG(null);
|
|
9720
9730
|
}
|
|
9721
9731
|
});
|
|
9732
|
+
//broadcast selected element to parent component
|
|
9733
|
+
if (selectedElement) {
|
|
9734
|
+
(_a = props.onElementSelected) === null || _a === void 0 ? void 0 : _a.call(props, selectedElement);
|
|
9735
|
+
}
|
|
9722
9736
|
return function () {
|
|
9723
9737
|
listener.off();
|
|
9724
9738
|
};
|
|
9725
9739
|
}, [selectedElement]);
|
|
9726
9740
|
//Listen command delete selected for link
|
|
9727
9741
|
React$1.useEffect(function () {
|
|
9742
|
+
var _a;
|
|
9728
9743
|
var listener = paperEventEmitter.onCommandDeleteSelectedLink(function () {
|
|
9729
9744
|
if (selectedLink) {
|
|
9730
9745
|
setLinks(function (prev) { return prev.filter(function (l) { return l.id !== selectedLink.id; }); });
|
|
9731
9746
|
setSelectedLink(undefined);
|
|
9732
9747
|
}
|
|
9733
9748
|
});
|
|
9749
|
+
//broadcast selected link to parent component
|
|
9750
|
+
if (selectedLink) {
|
|
9751
|
+
(_a = props.onLinkSelected) === null || _a === void 0 ? void 0 : _a.call(props, selectedLink);
|
|
9752
|
+
}
|
|
9734
9753
|
return function () {
|
|
9735
9754
|
listener.off();
|
|
9736
9755
|
};
|
|
9737
9756
|
}, [selectedLink]);
|
|
9738
9757
|
//Listen command delete selected for Text
|
|
9739
9758
|
React$1.useEffect(function () {
|
|
9759
|
+
var _a;
|
|
9740
9760
|
var listener = paperEventEmitter.onCommandDeleteSelectedText(function () {
|
|
9741
9761
|
if (selectedText) {
|
|
9742
9762
|
setTexts(function (prev) { return prev.filter(function (t) { return t.id !== selectedText.id; }); });
|
|
9743
9763
|
setSelectedText(undefined);
|
|
9744
9764
|
}
|
|
9745
9765
|
});
|
|
9766
|
+
//broadcast selected text to parent component
|
|
9767
|
+
if (selectedText) {
|
|
9768
|
+
(_a = props.onTextSelected) === null || _a === void 0 ? void 0 : _a.call(props, selectedText);
|
|
9769
|
+
}
|
|
9746
9770
|
return function () {
|
|
9747
9771
|
listener.off();
|
|
9748
9772
|
};
|
|
@@ -9885,7 +9909,7 @@ var Paper = function (props) {
|
|
|
9885
9909
|
if (!newElementLink)
|
|
9886
9910
|
return null;
|
|
9887
9911
|
//Automatic bending, if is not defined points
|
|
9888
|
-
if (!newElementLink.points) {
|
|
9912
|
+
if (!newElementLink.points || newElementLink.points.length === 0) {
|
|
9889
9913
|
newElementLink = automationAddPointsToLink(newElementLink, MAX_LINK_KNOT_COUNT);
|
|
9890
9914
|
}
|
|
9891
9915
|
var isValid = true;
|
|
@@ -10202,13 +10226,11 @@ var Paper = function (props) {
|
|
|
10202
10226
|
function Editor(_a) {
|
|
10203
10227
|
var editorContext = _a.editorContext;
|
|
10204
10228
|
return (React$1.createElement(React$1.Fragment, null,
|
|
10205
|
-
React$1.createElement(Paper, { size: { width: 3000, height: 3000 }, elements: editorContext.elements, links: editorContext.links, texts: editorContext.texts, onPaperClicked: editorContext.onPaperClicked, onPortMoved: editorContext.onPortMoved, onElementContextMenu: editorContext.onElementContextMenu, onElementMoved: editorContext.onElementMoved, onElementResized: editorContext.onElementResized, onLinkValidation: editorContext.validateLink, onCreatingLink: editorContext.onCreatingLink, onCreatingPortByLinking: editorContext.onCreatingPortByLinking })));
|
|
10229
|
+
React$1.createElement(Paper, { size: { width: 3000, height: 3000 }, elements: editorContext.elements, links: editorContext.links, texts: editorContext.texts, onPaperClicked: editorContext.onPaperClicked, onPortMoved: editorContext.onPortMoved, onPortSelected: editorContext.onPortSelected, onElementContextMenu: editorContext.onElementContextMenu, onElementMoved: editorContext.onElementMoved, onElementResized: editorContext.onElementResized, onElementSelected: editorContext.onElementSelected, onLinkValidation: editorContext.validateLink, onCreatingLink: editorContext.onCreatingLink, onCreatingPortByLinking: editorContext.onCreatingPortByLinking, onLinkSelected: editorContext.onLinkSelected, onTextSelected: editorContext.onTextSelected })));
|
|
10206
10230
|
}
|
|
10207
10231
|
|
|
10208
10232
|
exports.CircleRC = Circle;
|
|
10209
10233
|
exports.CrescentRC = Crescent;
|
|
10210
|
-
exports.CustomPortFromJSXElement = CustomPortFromJSXElement;
|
|
10211
|
-
exports.CustomPortFromShape = CustomPortFromShape;
|
|
10212
10234
|
exports.CustomShapeRC = CustomShape;
|
|
10213
10235
|
exports.EditorContext = EditorContext;
|
|
10214
10236
|
exports.Element = Element$1;
|
|
@@ -3,7 +3,7 @@ import IElement from '../models/IElement';
|
|
|
3
3
|
import IElementLink from '../models/IElementLink';
|
|
4
4
|
import IPosition from '../models/position';
|
|
5
5
|
import IPort from '../models/IPort';
|
|
6
|
-
import { IPaperText } from '../models/IText';
|
|
6
|
+
import IText, { IPaperText } from '../models/IText';
|
|
7
7
|
import ISize from '../models/size';
|
|
8
8
|
interface PaperProps {
|
|
9
9
|
size: {
|
|
@@ -15,10 +15,14 @@ interface PaperProps {
|
|
|
15
15
|
texts: IPaperText[];
|
|
16
16
|
onPaperClicked?: () => void;
|
|
17
17
|
onPortMoved?: (position: IPosition, port: IPort, element: IElement) => void;
|
|
18
|
+
onPortSelected?: (port: IPort, element: IElement) => void;
|
|
18
19
|
onElementContextMenu?: (element: IElement, mouseEvent: React.MouseEvent<SVGElement>) => void;
|
|
19
20
|
onElementMoved?: (position: IPosition, element: IElement, index: number) => void;
|
|
20
21
|
onElementResized?: (size: ISize, element: IElement, index: number) => void;
|
|
22
|
+
onElementSelected?: (element: IElement) => void;
|
|
21
23
|
onLinkValidation?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => boolean;
|
|
24
|
+
onLinkSelected?: (link: IElementLink) => void;
|
|
25
|
+
onTextSelected?: (text: IText) => void;
|
|
22
26
|
onCreatingPortByLinking?: (sourceElement: IElement, sourcePort: IPort, targetElement: IElement, position: IPosition) => IPort | null;
|
|
23
27
|
onCreatingLink?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => IElementLink | null;
|
|
24
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import IText from "../models/IText";
|
|
2
|
-
import {
|
|
3
|
-
export declare class CustomPort1 extends
|
|
2
|
+
import { Port } from '../models';
|
|
3
|
+
export declare class CustomPort1 extends Port {
|
|
4
4
|
constructor(x: number, y: number, label?: IText, width?: number, height?: number);
|
|
5
5
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class PortIn extends
|
|
1
|
+
import { Port } from "../models";
|
|
2
|
+
export default class PortIn extends Port {
|
|
3
3
|
constructor(x: number, y: number, width?: number, height?: number);
|
|
4
4
|
}
|
|
@@ -17,6 +17,9 @@ export interface IPortProps {
|
|
|
17
17
|
onMouseDown?: (portId: string, e: React.MouseEvent<SVGElement>) => void;
|
|
18
18
|
moveableAreas?: IPosition[][];
|
|
19
19
|
label?: IText;
|
|
20
|
+
onMouseEnter?: (ev: React.MouseEvent) => void;
|
|
21
|
+
onMouseLeave?: (ev: React.MouseEvent) => void;
|
|
22
|
+
onMouseMove?: (ev: React.MouseEvent) => void;
|
|
20
23
|
onPortLabelMoved?: (offsetX: number, offsetY: number) => void;
|
|
21
24
|
onPortLabelResized?: (width: number, height: number) => void;
|
|
22
25
|
onPortLabelContentChanged?: (ev: React.ChangeEvent, newValue: string) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import IElement from "../IElement";
|
|
3
3
|
import IElementLink from "../IElementLink";
|
|
4
|
-
import { IPaperText } from "../IText";
|
|
4
|
+
import IText, { IPaperText } from "../IText";
|
|
5
5
|
import IPosition from "../position";
|
|
6
6
|
import IPort from "../IPort";
|
|
7
7
|
import ISize from "../size";
|
|
@@ -11,12 +11,16 @@ export declare class EditorContext {
|
|
|
11
11
|
private _texts;
|
|
12
12
|
onPaperClicked?: () => void;
|
|
13
13
|
onPortMoved?: (position: IPosition, port: IPort, element: IElement) => void;
|
|
14
|
+
onPortSelected?: (port: IPort, element: IElement) => void;
|
|
14
15
|
onElementContextMenu?: (element: IElement, mouseEvent: React.MouseEvent<SVGElement>) => void;
|
|
15
16
|
onElementMoved?: (position: IPosition, element: IElement, index: number) => void;
|
|
16
17
|
onElementResized?: (size: ISize, element: IElement, index: number) => void;
|
|
18
|
+
onElementSelected?: (element: IElement) => void;
|
|
17
19
|
validateLink?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => boolean;
|
|
18
20
|
onCreatingPortByLinking?: (sourceElement: IElement, sourcePort: IPort, targetElement: IElement, position: IPosition) => IPort | null;
|
|
19
21
|
onCreatingLink?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => IElementLink | null;
|
|
22
|
+
onLinkSelected?: (link: IElementLink) => void;
|
|
23
|
+
onTextSelected?: (text: IText) => void;
|
|
20
24
|
constructor(elements: IElement[], links: IElementLink[], texts: IPaperText[]);
|
|
21
25
|
get elements(): IElement[];
|
|
22
26
|
get links(): IElementLink[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
2
|
import IPort from "../IPort";
|
|
3
3
|
import { IPortProps } from "../IPortProps";
|
|
4
4
|
import IText from "../IText";
|
|
@@ -10,6 +10,10 @@ export default class Port implements IPort {
|
|
|
10
10
|
size?: ISize;
|
|
11
11
|
label?: IText;
|
|
12
12
|
renderShape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>;
|
|
13
|
-
constructor(x: number, y: number, label?: IText,
|
|
13
|
+
constructor(x: number, y: number, label?: IText, shapeRenderer?: {
|
|
14
|
+
shape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>;
|
|
15
|
+
customShapeWithJSX?: JSX.Element;
|
|
16
|
+
positioningAnchor?: IPosition;
|
|
17
|
+
}, width?: number, height?: number);
|
|
14
18
|
get id(): string;
|
|
15
19
|
}
|