orcasvn-react-diagrams 0.1.25 → 0.1.28

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 CHANGED
@@ -442,7 +442,6 @@ function generateUniqueId() {
442
442
  return v4();
443
443
  }
444
444
 
445
- var MANUALLY_TRIGGER_RENDER$1 = 'manuallyTriggerRender';
446
445
  var Element$2 = /** @class */ (function () {
447
446
  function Element(x, y, width, height, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection, parentElement, textsPlaceHolderClassName, textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition) {
448
447
  if (portMovealeAreas === void 0) { portMovealeAreas = []; }
@@ -467,27 +466,26 @@ var Element$2 = /** @class */ (function () {
467
466
  this.textsPlaceHolderFlexStyle = textsPlaceHolderFlexStyle;
468
467
  this.textsPlaceHolderFlexboxPosition = textsPlaceHolderFlexboxPosition;
469
468
  }
470
- Element.prototype.manuallyTriggerRender = function () {
471
- //TODO: Implement this
472
- this._eventEmitter.emit(MANUALLY_TRIGGER_RENDER$1);
473
- };
474
- Element.prototype.manuallyTriggerRenderHandler = function (callback) {
475
- var _this = this;
476
- //TODO: Implement this
477
- this._eventEmitter.on(MANUALLY_TRIGGER_RENDER$1, callback);
478
- var canceller = function () {
479
- _this._eventEmitter.off(MANUALLY_TRIGGER_RENDER$1, callback);
480
- };
481
- return canceller;
482
- };
483
- Element.prototype.manuallyTriggerRenderPort = function (portId) {
484
- //TODO: Implement this
485
- var port = this.getPort(portId);
486
- if (port) {
487
- port.manuallyTriggerRender();
488
- }
489
- };
490
469
  Object.defineProperty(Element.prototype, "id", {
470
+ // public manuallyTriggerRender() {
471
+ // //TODO: Implement this
472
+ // this._eventEmitter.emit(MANUALLY_TRIGGER_RENDER);
473
+ // }
474
+ // public manuallyTriggerRenderHandler(callback: () => void) {
475
+ // //TODO: Implement this
476
+ // this._eventEmitter.on(MANUALLY_TRIGGER_RENDER, callback);
477
+ // const canceller = () => {
478
+ // this._eventEmitter.off(MANUALLY_TRIGGER_RENDER, callback);
479
+ // }
480
+ // return canceller;
481
+ // }
482
+ // public manuallyTriggerRenderPort(portId: string) {
483
+ // //TODO: Implement this
484
+ // const port = this.getPort(portId);
485
+ // if (port) {
486
+ // port.manuallyTriggerRender();
487
+ // }
488
+ // }
491
489
  get: function () {
492
490
  return this._id;
493
491
  },
@@ -672,7 +670,6 @@ var CustomShape = React$1.forwardRef(function (props, ref) {
672
670
  return (React$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref }), props.children));
673
671
  });
674
672
 
675
- var MANUALLY_TRIGGER_RENDER = 'manuallyTriggerRender';
676
673
  var Port$1 = /** @class */ (function () {
677
674
  function Port(x, y, label, shapeRenderer, width, height) {
678
675
  var _this = this;
@@ -703,18 +700,6 @@ var Port$1 = /** @class */ (function () {
703
700
  enumerable: false,
704
701
  configurable: true
705
702
  });
706
- Port.prototype.manuallyTriggerRender = function () {
707
- //TODO: Implement this
708
- this._eventEmitter.emit(MANUALLY_TRIGGER_RENDER);
709
- };
710
- Port.prototype.manuallyTriggerRenderHandler = function (callback) {
711
- var _this = this;
712
- this._eventEmitter.on(MANUALLY_TRIGGER_RENDER, callback);
713
- var canceller = function () {
714
- _this._eventEmitter.off(MANUALLY_TRIGGER_RENDER, callback);
715
- };
716
- return canceller;
717
- };
718
703
  return Port;
719
704
  }());
720
705
 
@@ -779,6 +764,9 @@ var Text$2 = /** @class */ (function () {
779
764
  return Text;
780
765
  }());
781
766
 
767
+ var EVENT_MANUALLY_RENDER_ELEMENT = 'manuallyRenderElement';
768
+ var EVENT_MANUALLY_RENDER_PORT = 'manuallyRenderPort';
769
+ var EVENT_EDITOR_CONTEXT_UPDATED = 'editorContextUpdated';
782
770
  var EVENT_PAPER_CLICKED = 'paperClicked';
783
771
  var EVENT_PAPER_MOUSE_MOVED = 'paperMouseMoved';
784
772
  var EVENT_PAPER_MOUSE_DOWN = 'paperMouseDown';
@@ -793,11 +781,28 @@ var EVENT_LINK_SELECTED = 'linkSelected';
793
781
  var EVENT_TEXT_SELECTED = 'textSelected';
794
782
  var EditorContext = /** @class */ (function () {
795
783
  function EditorContext(elements, links, texts) {
784
+ var _this = this;
785
+ /** @internal */
786
+ this.onEditorContextUpdated = function (callback) {
787
+ _this._eventEmitter.on(EVENT_EDITOR_CONTEXT_UPDATED, callback);
788
+ var off = function () {
789
+ _this._eventEmitter.off(EVENT_EDITOR_CONTEXT_UPDATED, callback);
790
+ };
791
+ return off;
792
+ };
796
793
  this._elements = elements;
797
794
  this._links = links;
798
795
  this._texts = texts;
799
796
  this._eventEmitter = new EventEmitter();
800
797
  }
798
+ EditorContext.prototype.addEventListener = function (event, callback) {
799
+ var _this = this;
800
+ this._eventEmitter.on(event, callback);
801
+ var off = function () {
802
+ _this._eventEmitter.off(event, callback);
803
+ };
804
+ return off;
805
+ };
801
806
  Object.defineProperty(EditorContext.prototype, "elements", {
802
807
  get: function () {
803
808
  return this._elements;
@@ -824,189 +829,129 @@ var EditorContext = /** @class */ (function () {
824
829
  };
825
830
  EditorContext.prototype.addElement = function (element) {
826
831
  this._elements = __spreadArray(__spreadArray([], this._elements, true), [element], false);
832
+ this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
827
833
  };
828
834
  EditorContext.prototype.removeElement = function (elementId) {
829
835
  this._elements = this._elements.filter(function (e) { return e.id !== elementId; });
836
+ this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
830
837
  };
831
838
  EditorContext.prototype.getLink = function (linkId) {
832
839
  return this._links.find(function (l) { return l.id === linkId; });
833
840
  };
834
841
  EditorContext.prototype.addLink = function (link) {
835
842
  this._links = __spreadArray(__spreadArray([], this._links, true), [link], false);
843
+ this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
836
844
  };
837
845
  EditorContext.prototype.removeLink = function (linkId) {
838
846
  this._links = this._links.filter(function (l) { return l.id !== linkId; });
847
+ this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
839
848
  };
840
849
  EditorContext.prototype.getText = function (textId) {
841
850
  return this._texts.find(function (t) { return t.id === textId; });
842
851
  };
843
852
  EditorContext.prototype.addText = function (text) {
844
853
  this._texts = __spreadArray(__spreadArray([], this._texts, true), [text], false);
854
+ this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
845
855
  };
846
856
  EditorContext.prototype.removeText = function (textId) {
847
857
  this._texts = this._texts.filter(function (t) { return t.id !== textId; });
858
+ this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
848
859
  };
849
860
  EditorContext.prototype.onPaperClicked = function (callback) {
850
- var _this = this;
851
- this._eventEmitter.on(EVENT_PAPER_CLICKED, callback);
852
- var off = function () {
853
- _this._eventEmitter.off(EVENT_PAPER_CLICKED, callback);
854
- };
855
- return off;
861
+ return this.addEventListener(EVENT_PAPER_CLICKED, callback);
856
862
  };
857
863
  /** @internal */
858
864
  EditorContext.prototype.onPaperClickedHandler = function (position) {
859
865
  this._eventEmitter.emit(EVENT_PAPER_CLICKED, position);
860
866
  };
861
867
  EditorContext.prototype.onPaperMouseMoved = function (callback) {
862
- var _this = this;
863
- this._eventEmitter.on(EVENT_PAPER_CLICKED, callback);
864
- var off = function () {
865
- _this._eventEmitter.off(EVENT_PAPER_CLICKED, callback);
866
- };
867
- return off;
868
+ return this.addEventListener(EVENT_PAPER_MOUSE_MOVED, callback);
868
869
  };
869
870
  /** @internal */
870
871
  EditorContext.prototype.onPaperMouseMovedHandler = function (position) {
871
872
  this._eventEmitter.emit(EVENT_PAPER_MOUSE_MOVED, position);
872
873
  };
873
874
  EditorContext.prototype.onPaperMouseDown = function (callback) {
874
- var _this = this;
875
- this._eventEmitter.on(EVENT_PAPER_MOUSE_DOWN, callback);
876
- var off = function () {
877
- _this._eventEmitter.off(EVENT_PAPER_MOUSE_DOWN, callback);
878
- };
879
- return off;
875
+ return this.addEventListener(EVENT_PAPER_MOUSE_DOWN, callback);
880
876
  };
881
877
  /** @internal */
882
878
  EditorContext.prototype.onPaperMouseDownHandler = function (position) {
883
879
  this._eventEmitter.emit(EVENT_PAPER_MOUSE_DOWN, position);
884
880
  };
885
881
  EditorContext.prototype.onPaperMouseUp = function (callback) {
886
- var _this = this;
887
- this._eventEmitter.on(EVENT_PAPER_MOUSE_UP, callback);
888
- var off = function () {
889
- _this._eventEmitter.off(EVENT_PAPER_MOUSE_UP, callback);
890
- };
891
- return off;
882
+ return this.addEventListener(EVENT_PAPER_MOUSE_UP, callback);
892
883
  };
893
884
  /** @internal */
894
885
  EditorContext.prototype.onPaperMouseUpHandler = function (position) {
895
886
  this._eventEmitter.emit(EVENT_PAPER_MOUSE_UP, position);
896
887
  };
897
888
  EditorContext.prototype.onPortMoved = function (callback) {
898
- var _this = this;
899
- this._eventEmitter.on(EVENT_PORT_MOVED, callback);
900
- var off = function () {
901
- _this._eventEmitter.off(EVENT_PORT_MOVED, callback);
902
- };
903
- return off;
889
+ return this.addEventListener(EVENT_PORT_MOVED, callback);
904
890
  };
905
891
  /** @internal */
906
892
  EditorContext.prototype.onPortMovedHandler = function (position, port, element) {
907
893
  this._eventEmitter.emit(EVENT_PORT_MOVED, position, port, element);
908
894
  };
909
895
  EditorContext.prototype.onPortSelected = function (callback) {
910
- var _this = this;
911
- this._eventEmitter.on(EVENT_PORT_SELECTED, callback);
912
- var off = function () {
913
- _this._eventEmitter.off(EVENT_PORT_SELECTED, callback);
914
- };
915
- return off;
896
+ return this.addEventListener(EVENT_PORT_SELECTED, callback);
916
897
  };
917
898
  /** @internal */
918
899
  EditorContext.prototype.onPortSelectedHandler = function (port, element) {
919
900
  this._eventEmitter.emit(EVENT_PORT_SELECTED, port, element);
920
901
  };
921
902
  EditorContext.prototype.onElementContextMenu = function (callback) {
922
- var _this = this;
923
- this._eventEmitter.on(EVENT_ELEMENT_CONTEXT_MENU, callback);
924
- var off = function () {
925
- _this._eventEmitter.off(EVENT_ELEMENT_CONTEXT_MENU, callback);
926
- };
927
- return off;
903
+ return this.addEventListener(EVENT_ELEMENT_CONTEXT_MENU, callback);
928
904
  };
929
905
  /** @internal */
930
906
  EditorContext.prototype.onElementContextMenuHandler = function (element, mouseEvent) {
931
907
  this._eventEmitter.emit(EVENT_ELEMENT_CONTEXT_MENU, element, mouseEvent);
932
908
  };
933
909
  EditorContext.prototype.onElementMoved = function (callback) {
934
- var _this = this;
935
- this._eventEmitter.on(EVENT_ELEMENT_MOVED, callback);
936
- var off = function () {
937
- _this._eventEmitter.off(EVENT_ELEMENT_MOVED, callback);
938
- };
939
- return off;
910
+ return this.addEventListener(EVENT_ELEMENT_MOVED, callback);
940
911
  };
941
912
  /** @internal */
942
913
  EditorContext.prototype.onElementMovedHandler = function (position, element) {
943
914
  this._eventEmitter.emit(EVENT_ELEMENT_MOVED, position, element);
944
915
  };
945
916
  EditorContext.prototype.onElementResized = function (callback) {
946
- var _this = this;
947
- this._eventEmitter.on(EVENT_ELEMENT_RESIZED, callback);
948
- var off = function () {
949
- _this._eventEmitter.off(EVENT_ELEMENT_RESIZED, callback);
950
- };
951
- return off;
917
+ return this.addEventListener(EVENT_ELEMENT_RESIZED, callback);
952
918
  };
953
919
  /** @internal */
954
920
  EditorContext.prototype.onElementResizedHandler = function (size, element) {
955
921
  this._eventEmitter.emit(EVENT_ELEMENT_RESIZED, size, element);
956
922
  };
957
923
  EditorContext.prototype.onElementSelected = function (callback) {
958
- var _this = this;
959
- this._eventEmitter.on(EVENT_ELEMENT_SELECTED, callback);
960
- var off = function () {
961
- _this._eventEmitter.off(EVENT_ELEMENT_SELECTED, callback);
962
- };
963
- return off;
924
+ return this.addEventListener(EVENT_ELEMENT_SELECTED, callback);
964
925
  };
965
926
  /** @internal */
966
927
  EditorContext.prototype.onElementSelectedHandler = function (element) {
967
928
  this._eventEmitter.emit(EVENT_ELEMENT_SELECTED, element);
968
929
  };
969
930
  EditorContext.prototype.onLinkSelected = function (callback) {
970
- var _this = this;
971
- this._eventEmitter.on(EVENT_LINK_SELECTED, callback);
972
- var off = function () {
973
- _this._eventEmitter.off(EVENT_LINK_SELECTED, callback);
974
- };
975
- return off;
931
+ return this.addEventListener(EVENT_LINK_SELECTED, callback);
976
932
  };
977
933
  /** @internal */
978
934
  EditorContext.prototype.onLinkSelectedHandler = function (link) {
979
935
  this._eventEmitter.emit(EVENT_LINK_SELECTED, link);
980
936
  };
981
937
  EditorContext.prototype.onTextSelected = function (callback) {
982
- var _this = this;
983
- this._eventEmitter.on(EVENT_TEXT_SELECTED, callback);
984
- var off = function () {
985
- _this._eventEmitter.off(EVENT_TEXT_SELECTED, callback);
986
- };
987
- return off;
938
+ return this.addEventListener(EVENT_TEXT_SELECTED, callback);
988
939
  };
989
940
  /** @internal */
990
941
  EditorContext.prototype.onTextSelectedHandler = function (text) {
991
942
  this._eventEmitter.emit(EVENT_TEXT_SELECTED, text);
992
943
  };
993
944
  EditorContext.prototype.triggerRenderElement = function (elementId) {
994
- //TODO: to be implemented
995
- var element = this.getElement(elementId);
996
- if (element) {
997
- element.manuallyTriggerRender();
998
- }
945
+ this._eventEmitter.emit(EVENT_MANUALLY_RENDER_ELEMENT, elementId);
946
+ };
947
+ EditorContext.prototype.onManuallyTriggerRenderElement = function (callback) {
948
+ return this.addEventListener(EVENT_MANUALLY_RENDER_ELEMENT, callback);
999
949
  };
1000
950
  EditorContext.prototype.triggerRenderPort = function (portId, elementId) {
1001
- var _a;
1002
- //TODO: to be implemented
1003
- var element = this.getElement(elementId);
1004
- if (element) {
1005
- var port = (_a = element.ports) === null || _a === void 0 ? void 0 : _a.find(function (p) { return p.id === portId; });
1006
- if (port) {
1007
- port.manuallyTriggerRender();
1008
- }
1009
- }
951
+ this._eventEmitter.emit(EVENT_MANUALLY_RENDER_PORT, portId, elementId);
952
+ };
953
+ EditorContext.prototype.onManuallyTriggerRenderPort = function (callback) {
954
+ return this.addEventListener(EVENT_MANUALLY_RENDER_PORT, callback);
1010
955
  };
1011
956
  return EditorContext;
1012
957
  }());
@@ -1698,17 +1643,19 @@ var Text = React$1.forwardRef(function (_a, ref) {
1698
1643
  var Text$1 = React$1.memo(Text);
1699
1644
 
1700
1645
  var Port1 = React$1.forwardRef(function (props, ref) {
1701
- 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, onManuallyTriggerRenderHandler = props.onManuallyTriggerRenderHandler, renderShape = props.renderShape;
1702
- var _a = React$1.useState(false); _a[0]; var setUpdated = _a[1];
1646
+ 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,
1647
+ // onManuallyTriggerRenderHandler,
1648
+ renderShape = props.renderShape;
1649
+ var _a = React$1.useState(false); _a[0]; _a[1];
1703
1650
  var textRef = React$1.useRef(null);
1704
- React$1.useEffect(function () {
1705
- var off = onManuallyTriggerRenderHandler === null || onManuallyTriggerRenderHandler === void 0 ? void 0 : onManuallyTriggerRenderHandler(function () {
1706
- setUpdated(function (prev) { return !prev; });
1707
- });
1708
- return function () {
1709
- off === null || off === void 0 ? void 0 : off();
1710
- };
1711
- }, []);
1651
+ // useEffect(() => {
1652
+ // const off = onManuallyTriggerRenderHandler?.(() => {
1653
+ // setUpdated(prev => !prev);
1654
+ // });
1655
+ // return () => {
1656
+ // off?.();
1657
+ // }
1658
+ // }, [])
1712
1659
  var rotationAngle = React$1.useMemo(function () {
1713
1660
  if (!calculateRotationAngle)
1714
1661
  return 0;
@@ -7466,6 +7413,44 @@ var findNearestPosition = function (listPositions, targetPosition) {
7466
7413
  }
7467
7414
  return nearestPoint;
7468
7415
  };
7416
+ /**
7417
+ * From one point find projected Point on the line segment.
7418
+ * @param position
7419
+ * @param linePoints
7420
+ * @returns
7421
+ */
7422
+ var findNearestPointOnSegment = function (position, linePoints) {
7423
+ var beginPosition = linePoints[0], endPosition = linePoints[1];
7424
+ var point = Flatten$1.point(position.x, position.y);
7425
+ var segment = Flatten$1.segment(Flatten$1.point(beginPosition.x, beginPosition.y), Flatten$1.point(endPosition.x, endPosition.y));
7426
+ var _a = point.distanceTo(segment); _a[0]; var segmentFromPointToSegment = _a[1];
7427
+ return {
7428
+ x: segmentFromPointToSegment.pe.x,
7429
+ y: segmentFromPointToSegment.pe.y
7430
+ };
7431
+ };
7432
+ /**
7433
+ * From 1 point find projected Point on the line segments so that the distance between 2 points is shortest.
7434
+ * @param position
7435
+ * @param lines
7436
+ * @returns
7437
+ */
7438
+ var findNearestProjectedPoint = function (position, lines) {
7439
+ var possiblePoints = lines.map(function (p) { return findNearestPointOnSegment(position, p); });
7440
+ var nearestPoint = findNearestPosition(possiblePoints, position);
7441
+ return nearestPoint;
7442
+ };
7443
+ /**
7444
+ * Check if a point is inside a polygon
7445
+ * @param position
7446
+ * @param polygonPoints
7447
+ * @returns
7448
+ */
7449
+ var checkPointContainsPolygon = function (position, polygonPoints) {
7450
+ var polygon = new Flatten$1.Polygon();
7451
+ polygon.addFace(polygonPoints.map(function (p) { return Flatten$1.point(p.x, p.y); }));
7452
+ return polygon.contains(Flatten$1.point(position.x, position.y));
7453
+ };
7469
7454
  /**
7470
7455
  * @param ele : IElement
7471
7456
  * @returns Flatten.Polygon
@@ -9205,34 +9190,42 @@ var Flexbox$1 = /*@__PURE__*/getDefaultExportFromCjs(bundleExports);
9205
9190
 
9206
9191
  var Element = function (props) {
9207
9192
  var _a, _b, _c;
9208
- var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, cssClass = props.cssClass, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container, onManuallyTriggerRenderHandler = props.onManuallyTriggerRenderHandler, 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;
9193
+ var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, cssClass = props.cssClass, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container, 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;
9209
9194
  var _d = React$1.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
9210
9195
  var _e = React$1.useState(), hoveredPort = _e[0], setHoveredPort = _e[1];
9211
9196
  var _f = React$1.useState((_a = props.ports) !== null && _a !== void 0 ? _a : []), ports = _f[0], setPorts = _f[1];
9212
9197
  var _g = React$1.useState(false), someElementLinkStarted = _g[0], setSomeElementLinkStarted = _g[1];
9213
9198
  var _h = React$1.useState(), potentialPortPosition = _h[0], setPotentialPortPosition = _h[1];
9214
- var _j = React$1.useState(false); _j[0]; var setUpdated = _j[1];
9199
+ var _j = React$1.useState(false); _j[0]; _j[1];
9215
9200
  var _paperEventEmitterContext = React$1.useContext(paperEventEmitterContext);
9216
9201
  var elementRef = React$1.useRef(null);
9217
9202
  var elementLinkStarted = React$1.useRef();
9218
9203
  var portsRef = React$1.useRef(ports);
9204
+ React$1.useEffect(function () {
9205
+ return function () {
9206
+ var _a;
9207
+ console.log('un mount', (_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content);
9208
+ };
9209
+ }, []);
9219
9210
  //Listen to manually trigger render event
9220
9211
  React$1.useEffect(function () {
9221
- var off = onManuallyTriggerRenderHandler === null || onManuallyTriggerRenderHandler === void 0 ? void 0 : onManuallyTriggerRenderHandler(function () {
9222
- console.log('Manually trigger render element', id);
9223
- setUpdated(function (prev) { return !prev; });
9212
+ var off = props.onManuallyTriggerRenderPort(function (portId, elementId) {
9213
+ if (elementId !== id)
9214
+ return;
9215
+ console.log('onManuallyTriggerRenderPort', id);
9216
+ setPorts(function (prev) { return __spreadArray([], prev, true); });
9224
9217
  });
9225
9218
  return function () {
9226
- off === null || off === void 0 ? void 0 : off();
9219
+ off();
9227
9220
  };
9228
- }, []);
9221
+ }, [props.onManuallyTriggerRenderPort]);
9229
9222
  //Update portsRef when ports changed
9230
9223
  React$1.useEffect(function () {
9231
9224
  portsRef.current = ports;
9232
9225
  }, [ports]);
9233
9226
  React$1.useEffect(function () {
9234
9227
  var _a;
9235
- console.info('Rendering Element ' + id + ' with text ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content));
9228
+ console.info('Rendering Element ' + ((_a = texts === null || texts === void 0 ? void 0 : texts[0]) === null || _a === void 0 ? void 0 : _a.content) || id);
9236
9229
  });
9237
9230
  //Listen a new port is created, after add new port to ports state
9238
9231
  React$1.useEffect(function () {
@@ -9350,29 +9343,6 @@ var Element = function (props) {
9350
9343
  setSelectedPort(port);
9351
9344
  _paperEventEmitterContext.emitPortSelected(port, id);
9352
9345
  }, [_paperEventEmitterContext]);
9353
- //From one point find another point on the line segment so that the distance between the two points is the shortest.
9354
- var findNearestPointOnSegment = function (position, linePoints) {
9355
- var beginPosition = linePoints[0], endPosition = linePoints[1];
9356
- var point = Flatten$1.point(position.x, position.y);
9357
- var segment = Flatten$1.segment(Flatten$1.point(beginPosition.x, beginPosition.y), Flatten$1.point(endPosition.x, endPosition.y));
9358
- var _a = point.distanceTo(segment); _a[0]; var segmentFromPointToSegment = _a[1];
9359
- return {
9360
- x: segmentFromPointToSegment.pe.x,
9361
- y: segmentFromPointToSegment.pe.y
9362
- };
9363
- };
9364
- //From 1 point find another point on the line segment so that the distance between 2 points is shortest.
9365
- var findNearestProjectedPoint = function (position, linePositions) {
9366
- var possiblePoints = linePositions.map(function (p) { return findNearestPointOnSegment(position, p); });
9367
- var nearestPoint = findNearestPosition(possiblePoints, position);
9368
- return nearestPoint;
9369
- };
9370
- //Check if a point is inside a polygon
9371
- var checkPointContainsPolygon = function (position, polygonPoints) {
9372
- var polygon = new Flatten$1.Polygon();
9373
- polygon.addFace(polygonPoints.map(function (p) { return Flatten$1.point(p.x, p.y); }));
9374
- return polygon.contains(Flatten$1.point(position.x, position.y));
9375
- };
9376
9346
  //Normalize a point so that it can lie exactly on an area
9377
9347
  var normalizePortPositionOnMoveableAreas = function (moveableAreas, position) {
9378
9348
  var lines = moveableAreas.filter(function (area) { return area.length === 2; });
@@ -9677,14 +9647,16 @@ var Element = function (props) {
9677
9647
  ? React$1.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
9678
9648
  : React$1.createElement("rect", { x: potentialPortPosition.x - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, y: potentialPortPosition.y - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, width: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, height: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, rx: PORT_PLACEHOLDER_DEFAULT_SIZE, ry: PORT_PLACEHOLDER_DEFAULT_SIZE, stroke: PORT_PLACEHOLDER_DEFAULT_STROKE, fill: "none", strokeWidth: 3 })), ports === null || ports === void 0 ? void 0 :
9679
9649
  ports.map(function (p, index) {
9680
- var _a, _b, _c, _d, _e, _f, _g;
9650
+ var _a, _b, _c, _d, _e, _f;
9681
9651
  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,
9682
9652
  // rotation={rotatePort(p)}
9683
9653
  calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: handlePortLabelMoved, onPortLabelResized: handlePortLabelResized, onPortLabelContentChanged: handlePortLabelContentChanged, onSelected: handleSelectedPort, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, onMouseMove: handlePortMouseMove,
9684
9654
  // onMouseEnter={() => {
9685
9655
  // if (someElementLinkStarted) setHoveredPort(p)
9686
9656
  // }}
9687
- onMouseLeave: handlePortMouseLeave, onManuallyTriggerRenderHandler: (_g = p.manuallyTriggerRenderHandler) === null || _g === void 0 ? void 0 : _g.bind(p), renderShape: p.renderShape });
9657
+ onMouseLeave: handlePortMouseLeave,
9658
+ // onManuallyTriggerRenderHandler={p.manuallyTriggerRenderHandler?.bind(p)}
9659
+ renderShape: p.renderShape });
9688
9660
  }),
9689
9661
  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) {
9690
9662
  var _a, _b;
@@ -9922,17 +9894,16 @@ function convertElementsToTree(elements) {
9922
9894
  return parsedElementsInTree;
9923
9895
  }
9924
9896
  var Paper = function (props) {
9925
- var _a;
9926
- var _b = React$1.useState(props.elements), elements = _b[0], setElements = _b[1];
9927
- var _c = React$1.useState([]), elementsInTree = _c[0], setElementsInTree = _c[1];
9928
- var _d = React$1.useState(), selectedElement = _d[0], setSelectedElement = _d[1];
9929
- var _e = React$1.useState((_a = props.links) !== null && _a !== void 0 ? _a : []), links = _e[0], setLinks = _e[1];
9930
- var _f = React$1.useState(), selectedLink = _f[0], setSelectedLink = _f[1];
9931
- var _g = React$1.useState(null), tempLink = _g[0], setTempLink = _g[1];
9932
- var _h = React$1.useState(props.texts), texts = _h[0], setTexts = _h[1];
9933
- var _j = React$1.useState(), selectedText = _j[0], setSelectedText = _j[1];
9934
- var _k = React$1.useState(null), selectedElementSVG = _k[0], setSelectedElementSVG = _k[1];
9935
- var _l = React$1.useState(false), mouseDownedOnPaper = _l[0], setMouseDownedOnPaper = _l[1];
9897
+ var _a = React$1.useState([]), elements = _a[0], setElements = _a[1];
9898
+ var _b = React$1.useState([]), elementsInTree = _b[0], setElementsInTree = _b[1];
9899
+ var _c = React$1.useState(), selectedElement = _c[0], setSelectedElement = _c[1];
9900
+ var _d = React$1.useState([]), links = _d[0], setLinks = _d[1];
9901
+ var _e = React$1.useState(), selectedLink = _e[0], setSelectedLink = _e[1];
9902
+ var _f = React$1.useState(null), tempLink = _f[0], setTempLink = _f[1];
9903
+ var _g = React$1.useState([]), texts = _g[0], setTexts = _g[1];
9904
+ var _h = React$1.useState(), selectedText = _h[0], setSelectedText = _h[1];
9905
+ var _j = React$1.useState(null), selectedElementSVG = _j[0], setSelectedElementSVG = _j[1];
9906
+ var _k = React$1.useState(false), mouseDownedOnPaper = _k[0], setMouseDownedOnPaper = _k[1];
9936
9907
  var paperEventEmitter = React$1.useContext(paperEventEmitterContext);
9937
9908
  var paperContainerRef = React$1.useRef(null);
9938
9909
  var tempLinkRef = React$1.useRef(tempLink); //Cache tempLink to avoid re-render when tempLink changed
@@ -9941,6 +9912,24 @@ var Paper = function (props) {
9941
9912
  React$1.useEffect(function () {
9942
9913
  console.log('Render Paper');
9943
9914
  });
9915
+ React$1.useEffect(function () {
9916
+ setElements(props.elements);
9917
+ }, [props.elements]);
9918
+ React$1.useEffect(function () {
9919
+ setLinks(props.links || []);
9920
+ }, [props.links]);
9921
+ React$1.useEffect(function () {
9922
+ setTexts(props.texts);
9923
+ }, [props.texts]);
9924
+ React$1.useEffect(function () {
9925
+ var off = props.onManuallyTriggerRenderElement(function (elementId) {
9926
+ console.log('onManuallyTriggerRenderElement');
9927
+ setElements(function (prev) { return __spreadArray([], prev, true); });
9928
+ });
9929
+ return function () {
9930
+ off();
9931
+ };
9932
+ }, [props.onManuallyTriggerRenderElement]);
9944
9933
  //Cache elements to avoid re-render when elements changed
9945
9934
  React$1.useEffect(function () {
9946
9935
  elementsRef.current = elements;
@@ -10525,15 +10514,21 @@ var Paper = function (props) {
10525
10514
  }
10526
10515
  }, [props.onElementContextMenu, handleElementClicked]);
10527
10516
  var renderElementInTree = React$1.useCallback(function (element) {
10528
- var _a, _b, _c;
10517
+ var _a, _b;
10529
10518
  //use the defined react element or the default Element component
10530
10519
  var ReactElement = element.reactElement || Element$1;
10531
10520
  console.log("Render element ".concat(element.id));
10532
10521
  return (React$1.createElement("g", { key: element.id },
10533
10522
  React$1.createElement(ReactElement, { key: "element-".concat(element.id), id: element.id, height: element.size.height, width: element.size.width, x: (_a = element.relativePosition) === null || _a === void 0 ? void 0 : _a.x, y: (_b = element.relativePosition) === null || _b === void 0 ? void 0 : _b.y, onClick: handleElementClicked, onContextMenu: handleContextMenu, container: paperContainerRef.current, renderShape: element.renderShape, cssClass: element.cssClass, texts: element.texts, ports: element.ports, portMoveableAreas: element.portMoveableAreas, portSlideRailSVGClassName: element.portSlideRailSVGClassName, portDirection: element.portDirection, defaultPortSize: element.defaultPortSize, onPortMoved: handlePortMoved, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp,
10534
10523
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
10535
- onMouseUpAtLinkedPortPlaceholder: handleMouseUpAtLinkedPortPlaceholder, onTextUpdated: handleElementTextChange, onManuallyTriggerRenderHandler: (_c = element.manuallyTriggerRenderHandler) === null || _c === void 0 ? void 0 : _c.bind(element), textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition }, element.childrenElements && element.childrenElements.map(renderElementInTree))));
10524
+ onMouseUpAtLinkedPortPlaceholder: handleMouseUpAtLinkedPortPlaceholder, onTextUpdated: handleElementTextChange, onManuallyTriggerRenderPort: props.onManuallyTriggerRenderPort, textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition }, element.childrenElements && element.childrenElements.map(renderElementInTree))));
10536
10525
  }, [handleElementClicked, handleContextMenu, handlePortMoved, handlePortMouseDown, handlePortMouseUp, handleMouseUpAtLinkedPortPlaceholder, handleElementTextChange]);
10526
+ React$1.useEffect(function () {
10527
+ console.log('elementsInTree');
10528
+ }, [elementsInTree]);
10529
+ React$1.useEffect(function () {
10530
+ console.log('renderElementInTree');
10531
+ }, [renderElementInTree]);
10537
10532
  var ElementsInTree = React$1.useMemo(function () {
10538
10533
  return elementsInTree.map(function (element, index) {
10539
10534
  return renderElementInTree(element);
@@ -10565,14 +10560,39 @@ var Paper = function (props) {
10565
10560
  };
10566
10561
  var Paper$1 = React$1.memo(Paper);
10567
10562
 
10568
- function Editor(_a) {
10563
+ var Editor = function (_a) {
10569
10564
  var editorContext = _a.editorContext, width = _a.width, height = _a.height;
10565
+ var _b = React$1.useState([]), elements = _b[0], setElements = _b[1];
10566
+ var _c = React$1.useState([]), links = _c[0], setLinks = _c[1];
10567
+ var _d = React$1.useState([]), texts = _d[0], setTexts = _d[1];
10570
10568
  if (!width) {
10571
10569
  width = 3000;
10572
10570
  }
10573
10571
  if (!height) {
10574
10572
  height = 3000;
10575
10573
  }
10574
+ var setEditorStates = React$1.useCallback(function (ctx) {
10575
+ setElements(__spreadArray([], ctx.elements, true));
10576
+ setLinks(__spreadArray([], ctx.links, true));
10577
+ setTexts(__spreadArray([], ctx.texts, true));
10578
+ }, []);
10579
+ React$1.useEffect(function () {
10580
+ if (editorContext) {
10581
+ setEditorStates(editorContext);
10582
+ }
10583
+ }, [editorContext, setEditorStates]);
10584
+ React$1.useEffect(function () {
10585
+ var offs = [];
10586
+ if (editorContext) {
10587
+ offs.push(editorContext.onEditorContextUpdated(function () {
10588
+ console.log("onEditorContextUpdated");
10589
+ setEditorStates(editorContext);
10590
+ }));
10591
+ }
10592
+ return function () {
10593
+ offs.forEach(function (off) { return off(); });
10594
+ };
10595
+ }, [editorContext, setEditorStates]);
10576
10596
  var handlePaperClicked = React$1.useCallback(function (position) {
10577
10597
  editorContext.onPaperClickedHandler(position);
10578
10598
  }, [editorContext]);
@@ -10621,10 +10641,8 @@ function Editor(_a) {
10621
10641
  var handlePaperMouseUp = React$1.useCallback(function (position) {
10622
10642
  editorContext.onPaperMouseUpHandler(position);
10623
10643
  }, [editorContext]);
10624
- if (editorContext)
10625
- return (React$1.createElement(Paper$1, { size: { width: width, height: height }, elements: editorContext.elements, links: editorContext.links, texts: editorContext.texts, onPaperClicked: handlePaperClicked, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onTextSelected: handleTextSelected, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseDown, onPaperMouseDown: handlePaperMouseUp }));
10626
- return null;
10627
- }
10644
+ return (React$1.createElement(Paper$1, { key: "paper", size: { width: width, height: height }, elements: elements, links: links, texts: texts, onPaperClicked: handlePaperClicked, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onTextSelected: handleTextSelected, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseUp, onPaperMouseDown: handlePaperMouseDown, onManuallyTriggerRenderElement: editorContext.onManuallyTriggerRenderElement.bind(editorContext), onManuallyTriggerRenderPort: editorContext.onManuallyTriggerRenderPort.bind(editorContext) }));
10645
+ };
10628
10646
 
10629
10647
  exports.CircleRC = Circle;
10630
10648
  exports.CrescentRC = Crescent;
@@ -5,5 +5,5 @@ interface IEditorProps {
5
5
  width?: number;
6
6
  height?: number;
7
7
  }
8
- export default function Editor({ editorContext, width, height }: IEditorProps): React.JSX.Element | null;
9
- export {};
8
+ declare const Editor: React.FC<IEditorProps>;
9
+ export default Editor;