orcasvn-react-diagrams 0.1.16 → 0.1.19

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.
Files changed (29) hide show
  1. package/dist/cjs/index.js +149 -148
  2. package/dist/cjs/types/components/paper.d.ts +0 -1
  3. package/dist/cjs/types/mocks/diamondElement.d.ts +11 -0
  4. package/dist/cjs/types/mocks/port1.d.ts +2 -2
  5. package/dist/cjs/types/mocks/portIn.d.ts +2 -2
  6. package/dist/cjs/types/mocks/rectangularFrameElement.d.ts +11 -0
  7. package/dist/cjs/types/models/IEditorContext.d.ts +34 -0
  8. package/dist/cjs/types/models/IElement.d.ts +2 -0
  9. package/dist/cjs/types/models/IPortProps.d.ts +3 -0
  10. package/dist/cjs/types/models/implementations/EditorContext.d.ts +4 -2
  11. package/dist/cjs/types/models/implementations/Element.d.ts +2 -0
  12. package/dist/cjs/types/models/implementations/Port.d.ts +6 -2
  13. package/dist/cjs/types/models/implementations/index.d.ts +0 -2
  14. package/dist/esm/index.js +150 -147
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/types/components/paper.d.ts +0 -1
  17. package/dist/esm/types/mocks/diamondElement.d.ts +11 -0
  18. package/dist/esm/types/mocks/port1.d.ts +2 -2
  19. package/dist/esm/types/mocks/portIn.d.ts +2 -2
  20. package/dist/esm/types/mocks/rectangularFrameElement.d.ts +11 -0
  21. package/dist/esm/types/models/IEditorContext.d.ts +34 -0
  22. package/dist/esm/types/models/IElement.d.ts +2 -0
  23. package/dist/esm/types/models/IPortProps.d.ts +3 -0
  24. package/dist/esm/types/models/implementations/EditorContext.d.ts +4 -2
  25. package/dist/esm/types/models/implementations/Element.d.ts +2 -0
  26. package/dist/esm/types/models/implementations/Port.d.ts +6 -2
  27. package/dist/esm/types/models/implementations/index.d.ts +0 -2
  28. package/dist/index.d.ts +45 -13
  29. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -466,6 +466,12 @@ var Element$1 = /** @class */ (function () {
466
466
  this.textsPlaceHolderFlexStyle = textsPlaceHolderFlexStyle;
467
467
  this.textsPlaceHolderFlexboxPosition = textsPlaceHolderFlexboxPosition;
468
468
  }
469
+ Element.prototype.manuallyTriggerRender = function () {
470
+ //TODO: Implement this
471
+ };
472
+ Element.prototype.manuallyTriggerRenderPort = function (portId) {
473
+ //TODO: Implement this
474
+ };
469
475
  Object.defineProperty(Element.prototype, "id", {
470
476
  get: function () {
471
477
  return this._id;
@@ -560,8 +566,100 @@ var Element$1 = /** @class */ (function () {
560
566
  return Element;
561
567
  }());
562
568
 
569
+ /******************************************************************************
570
+ Copyright (c) Microsoft Corporation.
571
+
572
+ Permission to use, copy, modify, and/or distribute this software for any
573
+ purpose with or without fee is hereby granted.
574
+
575
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
576
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
577
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
578
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
579
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
580
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
581
+ PERFORMANCE OF THIS SOFTWARE.
582
+ ***************************************************************************** */
583
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
584
+
585
+
586
+ var __assign = function() {
587
+ __assign = Object.assign || function __assign(t) {
588
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
589
+ s = arguments[i];
590
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
591
+ }
592
+ return t;
593
+ };
594
+ return __assign.apply(this, arguments);
595
+ };
596
+
597
+ function __spreadArray(to, from, pack) {
598
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
599
+ if (ar || !(i in from)) {
600
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
601
+ ar[i] = from[i];
602
+ }
603
+ }
604
+ return to.concat(ar || Array.prototype.slice.call(from));
605
+ }
606
+
607
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
608
+ var e = new Error(message);
609
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
610
+ };
611
+
612
+ var ShapeWrapper = React$1.forwardRef(function (shapeProps, ref) {
613
+ //if direction is provided, rotation is based on direction
614
+ var rotation = shapeProps.rotation || 0;
615
+ if (shapeProps.direction) {
616
+ switch (shapeProps.direction) {
617
+ case 'left':
618
+ rotation = -90;
619
+ break;
620
+ case 'right':
621
+ rotation = 90;
622
+ break;
623
+ case 'down':
624
+ rotation = 180;
625
+ break;
626
+ default:
627
+ rotation = 0;
628
+ break;
629
+ }
630
+ }
631
+ var position = { x: shapeProps.x, y: shapeProps.y };
632
+ var transformOrigin = "center";
633
+ if (typeof shapeProps.positioningAnchor === 'object') {
634
+ position.x = position.x - shapeProps.positioningAnchor.x / 100 * shapeProps.width;
635
+ position.y = position.y - shapeProps.positioningAnchor.y / 100 * shapeProps.height;
636
+ transformOrigin = "".concat(shapeProps.positioningAnchor.x, "% ").concat(shapeProps.positioningAnchor.y, "%");
637
+ }
638
+ else if (shapeProps.positioningAnchor === exports.PositioningAnchor.Center) {
639
+ position.x = position.x - shapeProps.width / 2;
640
+ position.y = position.y - shapeProps.height / 2;
641
+ }
642
+ var objectOfAllEventAttributes = React$1.useMemo(function () {
643
+ var arrayOfAllEventAttributes = Object.entries(shapeProps).filter(function (_a) {
644
+ var k = _a[0]; _a[1];
645
+ return k.startsWith('on');
646
+ });
647
+ return Object.fromEntries(arrayOfAllEventAttributes);
648
+ }, [shapeProps]);
649
+ var viewboxWidth = shapeProps.width > shapeProps.height ? 100 : shapeProps.width / shapeProps.height * 100;
650
+ var viewBoxHeight = shapeProps.height > shapeProps.width ? 100 : shapeProps.height / shapeProps.width * 100;
651
+ var viewBox = shapeProps.viewBox || "0 0 ".concat(viewboxWidth, " ").concat(viewBoxHeight);
652
+ return (React$1.createElement("g", { transform: "rotate(".concat(rotation, ")"), style: { transformOrigin: transformOrigin, transformBox: "content-box" } },
653
+ 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)));
654
+ });
655
+
656
+ var CustomShape = React$1.forwardRef(function (props, ref) {
657
+ return (React$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref }), props.children));
658
+ });
659
+
563
660
  var Port$1 = /** @class */ (function () {
564
- function Port(x, y, label, renderShape, width, height) {
661
+ function Port(x, y, label, shapeRenderer, width, height) {
662
+ var _this = this;
565
663
  this._id = generateUniqueId();
566
664
  this.position = { x: x, y: y };
567
665
  if (!height) {
@@ -571,7 +669,14 @@ var Port$1 = /** @class */ (function () {
571
669
  this.size = { width: width, height: height };
572
670
  }
573
671
  this.label = label;
574
- this.renderShape = renderShape;
672
+ if (shapeRenderer && shapeRenderer.shape) {
673
+ this.renderShape = shapeRenderer.shape;
674
+ }
675
+ else if (shapeRenderer && shapeRenderer.customShapeWithJSX) {
676
+ this.renderShape = React$1.forwardRef(function (props, ref) {
677
+ 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));
678
+ });
679
+ }
575
680
  }
576
681
  Object.defineProperty(Port.prototype, "id", {
577
682
  get: function () {
@@ -698,133 +803,15 @@ var EditorContext = /** @class */ (function () {
698
803
  EditorContext.prototype.removeText = function (textId) {
699
804
  this._texts = this._texts.filter(function (t) { return t.id !== textId; });
700
805
  };
806
+ EditorContext.prototype.triggerRenderElement = function (elementId) {
807
+ //TODO: to be implemented
808
+ };
809
+ EditorContext.prototype.triggerRenderPort = function (portId, elementId) {
810
+ //TODO: to be implemented
811
+ };
701
812
  return EditorContext;
702
813
  }());
703
814
 
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
815
  var Circle = React$1.forwardRef(function (props, ref) {
829
816
  var s = { height: 100, width: 100 };
830
817
  if (props.r) {
@@ -1482,7 +1469,7 @@ var Text = React$1.forwardRef(function (_a, ref) {
1482
1469
  var Text$1 = React$1.memo(Text);
1483
1470
 
1484
1471
  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;
1472
+ 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
1473
  var textRef = React$1.useRef(null);
1487
1474
  var rotationAngle = React$1.useMemo(function () {
1488
1475
  if (!calculateRotationAngle)
@@ -1500,7 +1487,7 @@ var Port1 = React$1.forwardRef(function (props, ref) {
1500
1487
  return (React$1.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1501
1488
  }
1502
1489
  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" });
1490
+ 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
1491
  }
1505
1492
  }, [props]);
1506
1493
  return (React$1.createElement(React$1.Fragment, null,
@@ -8979,11 +8966,12 @@ var Element = function (props) {
8979
8966
  var _a, _b, _c;
8980
8967
  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
8968
  var _d = React$1.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
8982
- var _e = React$1.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
8969
+ var _e = React$1.useState(), hoveredPort = _e[0], setHoveredPort = _e[1];
8970
+ var _f = React$1.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
8983
8971
  return __assign(__assign({}, p), { id: p.id, ref: React$1.createRef() });
8984
- })) !== null && _b !== void 0 ? _b : []), ports = _e[0], setPorts = _e[1];
8985
- var _f = React$1.useState(false), someElementLinkStarted = _f[0], setSomeElementLinkStarted = _f[1];
8986
- var _g = React$1.useState(), potentialPortPosition = _g[0], setPotentialPortPosition = _g[1];
8972
+ })) !== null && _b !== void 0 ? _b : []), ports = _f[0], setPorts = _f[1];
8973
+ var _g = React$1.useState(false), someElementLinkStarted = _g[0], setSomeElementLinkStarted = _g[1];
8974
+ var _h = React$1.useState(), potentialPortPosition = _h[0], setPotentialPortPosition = _h[1];
8987
8975
  var _paperEventEmitterContext = React$1.useContext(paperEventEmitterContext);
8988
8976
  var elementRef = React$1.useRef(null);
8989
8977
  var elementLinkStarted = React$1.useRef();
@@ -9049,6 +9037,7 @@ var Element = function (props) {
9049
9037
  elementLinkStarted.current = undefined;
9050
9038
  setSomeElementLinkStarted(false);
9051
9039
  setPotentialPortPosition(undefined);
9040
+ setHoveredPort(undefined);
9052
9041
  });
9053
9042
  return function () {
9054
9043
  elementStartedListener.off();
@@ -9187,7 +9176,6 @@ var Element = function (props) {
9187
9176
  };
9188
9177
  //Normalize port position
9189
9178
  var normalizePortPosition = function (tempNewPosition) {
9190
- console.info('normalizePortPosition', tempNewPosition);
9191
9179
  var newPosition;
9192
9180
  if (portMoveableAreas && portMoveableAreas.length > 0) { //If moveable areas is defined
9193
9181
  newPosition = normalizePortPositionOnMoveableAreas(portMoveableAreas, tempNewPosition);
@@ -9271,6 +9259,11 @@ var Element = function (props) {
9271
9259
  function handleElementMouseMove(ev) {
9272
9260
  //ev.stopPropagation(); //Can't use stopPropagation here, because do not create tempLink
9273
9261
  if (someElementLinkStarted && elementRef.current) {
9262
+ //If an element link is being created, calculate the potential port position when the mouse moves over the element.
9263
+ if (hoveredPort) {
9264
+ setPotentialPortPosition(undefined);
9265
+ return;
9266
+ }
9274
9267
  /* The above code is calculating the relative position of the mouse within a specific
9275
9268
  element on the page. It first gets the bounding rectangle of the element using
9276
9269
  `getBoundingClientRect()` and the bounding box of the element using `getBBox()`. Then,
@@ -9314,7 +9307,7 @@ var Element = function (props) {
9314
9307
  };
9315
9308
  //Get rotate angle of port by port direction is defined.
9316
9309
  var rotatePort = React$1.useCallback(function (x, y) {
9317
- console.info('calculating port rotation', x, y);
9310
+ // console.info('calculating port rotation', x, y)
9318
9311
  if (!portSlideRailSVGClassName)
9319
9312
  return 0;
9320
9313
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
@@ -9379,6 +9372,14 @@ var Element = function (props) {
9379
9372
  movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
9380
9373
  onMove: handlePortMove
9381
9374
  });
9375
+ useSelectionFrame({
9376
+ container: container,
9377
+ targetSVGElement: (hoveredPort === null || hoveredPort === void 0 ? void 0 : hoveredPort.ref.current) || undefined,
9378
+ resizability: {
9379
+ enabled: false,
9380
+ keepRatio: false
9381
+ },
9382
+ });
9382
9383
  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
9384
  renderedShape,
9384
9385
  potentialPortPosition && (portPlaceholderShape
@@ -9388,7 +9389,18 @@ var Element = function (props) {
9388
9389
  var _a, _b, _c, _d, _e, _f;
9389
9390
  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
9391
  // 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, renderShape: p.renderShape });
9392
+ 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 () {
9393
+ if (someElementLinkStarted)
9394
+ setHoveredPort(p);
9395
+ },
9396
+ // onMouseEnter={() => {
9397
+ // if (someElementLinkStarted) setHoveredPort(p)
9398
+ // }}
9399
+ onMouseLeave: function () {
9400
+ console.log('onMouseLeave');
9401
+ if (someElementLinkStarted)
9402
+ setHoveredPort(undefined);
9403
+ }, renderShape: p.renderShape });
9392
9404
  }),
9393
9405
  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
9406
  var _a, _b;
@@ -9909,18 +9921,9 @@ var Paper = function (props) {
9909
9921
  if (!newElementLink)
9910
9922
  return null;
9911
9923
  //Automatic bending, if is not defined points
9912
- if (!newElementLink.points) {
9924
+ if (!newElementLink.points || newElementLink.points.length === 0) {
9913
9925
  newElementLink = automationAddPointsToLink(newElementLink, MAX_LINK_KNOT_COUNT);
9914
9926
  }
9915
- var isValid = true;
9916
- //Validate element link
9917
- if (props.onLinkValidation && newElementLink.targetPort && newElementLink.targetElement) {
9918
- isValid = props.onLinkValidation(newElementLink.sourcePort, newElementLink.sourceElement, newElementLink.targetPort, newElementLink.targetElement);
9919
- }
9920
- if (!isValid) {
9921
- console.info("Link cancelled by validation");
9922
- return null;
9923
- }
9924
9927
  return newElementLink;
9925
9928
  };
9926
9929
  var handlePortMouseUp = function (ev, port, elementId) {
@@ -10226,13 +10229,11 @@ var Paper = function (props) {
10226
10229
  function Editor(_a) {
10227
10230
  var editorContext = _a.editorContext;
10228
10231
  return (React$1.createElement(React$1.Fragment, null,
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 })));
10232
+ 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, onCreatingLink: editorContext.onCreatingLink, onCreatingPortByLinking: editorContext.onCreatingPortByLinking, onLinkSelected: editorContext.onLinkSelected, onTextSelected: editorContext.onTextSelected })));
10230
10233
  }
10231
10234
 
10232
10235
  exports.CircleRC = Circle;
10233
10236
  exports.CrescentRC = Crescent;
10234
- exports.CustomPortFromJSXElement = CustomPortFromJSXElement;
10235
- exports.CustomPortFromShape = CustomPortFromShape;
10236
10237
  exports.CustomShapeRC = CustomShape;
10237
10238
  exports.EditorContext = EditorContext;
10238
10239
  exports.Element = Element$1;
@@ -20,7 +20,6 @@ interface PaperProps {
20
20
  onElementMoved?: (position: IPosition, element: IElement, index: number) => void;
21
21
  onElementResized?: (size: ISize, element: IElement, index: number) => void;
22
22
  onElementSelected?: (element: IElement) => void;
23
- onLinkValidation?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => boolean;
24
23
  onLinkSelected?: (link: IElementLink) => void;
25
24
  onTextSelected?: (text: IText) => void;
26
25
  onCreatingPortByLinking?: (sourceElement: IElement, sourcePort: IPort, targetElement: IElement, position: IPosition) => IPort | null;
@@ -0,0 +1,11 @@
1
+ import Element from "../models/implementations/Element";
2
+ import ISize from "../models/size";
3
+ import IResizability from "../models/IResizability";
4
+ import IPort from "../models/IPort";
5
+ import IText from "../models/IText";
6
+ export default class DiamondElement extends Element {
7
+ resizability: IResizability;
8
+ get size(): ISize;
9
+ set size(value: ISize);
10
+ constructor(x: number, y: number, width: number, height: number, cssClass?: string, texts?: IText[], ports?: IPort[]);
11
+ }
@@ -1,5 +1,5 @@
1
1
  import IText from "../models/IText";
2
- import { CustomPortFromShape } from '../models/implementations/CustomPortFromShape';
3
- export declare class CustomPort1 extends CustomPortFromShape {
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 { CustomPortFromJSXElement } from "../models/implementations/CustomPortFromJSXElement";
2
- export default class PortIn extends CustomPortFromJSXElement {
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
  }
@@ -0,0 +1,11 @@
1
+ import Element from "../models/implementations/Element";
2
+ import IResizability from "../models/IResizability";
3
+ import IPort from "../models/IPort";
4
+ import IText from "../models/IText";
5
+ import IFlexboxType from '../models/IFlexboxType';
6
+ import IPosition from '../models/position';
7
+ export default class RectangularFrameElement extends Element {
8
+ resizability: IResizability;
9
+ defaultPortSize?: number | undefined;
10
+ constructor(x: number, y: number, width: number, height: number, cssClass?: string, texts?: IText[], ports?: IPort[], textsPlaceHolderClassName?: string, textsPlaceHolderFlexStyle?: IFlexboxType, textsPlaceHolderFlexboxPosition?: IPosition);
11
+ }
@@ -0,0 +1,34 @@
1
+ /// <reference types="react" />
2
+ import IElement from "./IElement";
3
+ import IElementLink from "./IElementLink";
4
+ import IPort from "./IPort";
5
+ import IText, { IPaperText } from "./IText";
6
+ import IPosition from "./position";
7
+ import ISize from "./size";
8
+ export interface IEditorContext {
9
+ elements: IElement[];
10
+ links: IElementLink[];
11
+ texts: IPaperText[];
12
+ onPaperClicked?: () => void;
13
+ onPortMoved?: (position: IPosition, port: IPort, element: IElement) => void;
14
+ onPortSelected?: (port: IPort, element: IElement) => void;
15
+ onElementContextMenu?: (element: IElement, mouseEvent: React.MouseEvent<SVGElement>) => void;
16
+ onElementMoved?: (position: IPosition, element: IElement, index: number) => void;
17
+ onElementResized?: (size: ISize, element: IElement, index: number) => void;
18
+ onElementSelected?: (element: IElement) => void;
19
+ onCreatingPortByLinking?: (sourceElement: IElement, sourcePort: IPort, targetElement: IElement, position: IPosition) => IPort | null;
20
+ onCreatingLink?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => IElementLink | null;
21
+ onLinkSelected?: (link: IElementLink) => void;
22
+ onTextSelected?: (text: IText) => void;
23
+ getElement(elementId: string): IElement | undefined;
24
+ addElement(element: IElement): void;
25
+ removeElement(elementId: string): void;
26
+ getLink(linkId: string): IElementLink | undefined;
27
+ addLink(link: IElementLink): void;
28
+ removeLink(linkId: string): void;
29
+ getText(textId: string): IPaperText | undefined;
30
+ addText(text: IPaperText): void;
31
+ removeText(textId: string): void;
32
+ triggerRenderElement(elementId: string): void;
33
+ triggerRenderPort(portId: string, elementId: string): void;
34
+ }
@@ -26,10 +26,12 @@ export default interface IElement {
26
26
  defaultPortSize?: number;
27
27
  parentElement?: IElement;
28
28
  onParentChanged?: (callback: (oldParent?: IElement, newParent?: IElement) => void) => (() => void);
29
+ manuallyTriggerRender: () => void;
29
30
  addPort: (newPort: IPort) => void;
30
31
  onAddedPort: (callback: (newPort: IPort) => void) => (() => void);
31
32
  deletePort: (id: string) => void;
32
33
  onDeletedPort: (callback: (id: string) => void) => (() => void);
34
+ manuallyTriggerRenderPort: (portId: string) => void;
33
35
  textsPlaceHolderClassName?: string;
34
36
  textsPlaceHolderFlexStyle?: IFlexboxType;
35
37
  textsPlaceHolderFlexboxPosition?: IPosition;
@@ -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;
@@ -5,7 +5,8 @@ import IText, { IPaperText } from "../IText";
5
5
  import IPosition from "../position";
6
6
  import IPort from "../IPort";
7
7
  import ISize from "../size";
8
- export declare class EditorContext {
8
+ import { IEditorContext } from "../IEditorContext";
9
+ export declare class EditorContext implements IEditorContext {
9
10
  private _elements;
10
11
  private _links;
11
12
  private _texts;
@@ -16,7 +17,6 @@ export declare class EditorContext {
16
17
  onElementMoved?: (position: IPosition, element: IElement, index: number) => void;
17
18
  onElementResized?: (size: ISize, element: IElement, index: number) => void;
18
19
  onElementSelected?: (element: IElement) => void;
19
- validateLink?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => boolean;
20
20
  onCreatingPortByLinking?: (sourceElement: IElement, sourcePort: IPort, targetElement: IElement, position: IPosition) => IPort | null;
21
21
  onCreatingLink?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => IElementLink | null;
22
22
  onLinkSelected?: (link: IElementLink) => void;
@@ -34,4 +34,6 @@ export declare class EditorContext {
34
34
  getText(textId: string): IPaperText | undefined;
35
35
  addText(text: IPaperText): void;
36
36
  removeText(textId: string): void;
37
+ triggerRenderElement(elementId: string): void;
38
+ triggerRenderPort(portId: string, elementId: string): void;
37
39
  }
@@ -34,6 +34,8 @@ export default class Element implements IElement {
34
34
  textsPlaceHolderFlexboxPosition?: IPosition;
35
35
  _eventEmitter: EventEmitter;
36
36
  constructor(x: number, y: number, width: number, height: number, cssClass?: string, renderShape?: (props: IElementProps) => JSX.Element, texts?: IText[], ports?: IPort[], portMovealeAreas?: IPosition[][], portSlideRailSVGClassName?: string, portDirection?: SubObjectDirection, parentElement?: Element, textsPlaceHolderClassName?: string, textsPlaceHolderFlexStyle?: IFlexboxType, textsPlaceHolderFlexboxPosition?: IPosition);
37
+ manuallyTriggerRender(): void;
38
+ manuallyTriggerRenderPort(portId: string): void;
37
39
  get id(): string;
38
40
  get size(): ISize;
39
41
  set size(value: ISize);
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
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, renderShape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>, width?: number, height?: number);
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
  }
@@ -3,6 +3,4 @@ import Port from './Port';
3
3
  import ElementLink from './ElementLink';
4
4
  import Text from './Text';
5
5
  export * from './EditorContext';
6
- export * from './CustomPortFromJSXElement';
7
- export * from './CustomPortFromShape';
8
6
  export { Element, Port, ElementLink, Text };