orcasvn-react-diagrams 0.1.39 → 0.1.41

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
@@ -7717,12 +7717,42 @@ var getFourVertexesOfBBoxFromElement = function (element) {
7717
7717
  //get absolute position of element
7718
7718
  var getAbsolutePosition = function (element) {
7719
7719
  var parentElement = element.parentElement;
7720
+ var elemenetPositionWithTopLeftAnchor = {
7721
+ x: element.position.x,
7722
+ y: element.position.y,
7723
+ };
7724
+ if (element.positionAnchor === exports.PositioningAnchor.Center) {
7725
+ elemenetPositionWithTopLeftAnchor.x -= element.size.width / 2;
7726
+ elemenetPositionWithTopLeftAnchor.y -= element.size.height / 2;
7727
+ }
7728
+ if (!parentElement) {
7729
+ return __assign({}, elemenetPositionWithTopLeftAnchor);
7730
+ }
7731
+ var absoluteParentElement = getAbsolutePosition(parentElement);
7732
+ var x = elemenetPositionWithTopLeftAnchor.x + absoluteParentElement.x;
7733
+ var y = elemenetPositionWithTopLeftAnchor.y + absoluteParentElement.y;
7734
+ return {
7735
+ x: x,
7736
+ y: y,
7737
+ };
7738
+ };
7739
+ //get absolute position of element
7740
+ var getAnchorAdjustedAbsolutePosition = function (element) {
7741
+ var parentElement = element.parentElement;
7742
+ var elemenetPositionWithTopLeftAnchor = {
7743
+ x: element.position.x,
7744
+ y: element.position.y,
7745
+ };
7746
+ if (element.positionAnchor === exports.PositioningAnchor.Center) {
7747
+ elemenetPositionWithTopLeftAnchor.x -= element.size.width / 2;
7748
+ elemenetPositionWithTopLeftAnchor.y -= element.size.height / 2;
7749
+ }
7720
7750
  if (!parentElement) {
7721
- return __assign({}, element.position);
7751
+ return __assign({}, elemenetPositionWithTopLeftAnchor);
7722
7752
  }
7723
7753
  var absoluteParentElement = getAbsolutePosition(parentElement);
7724
- var x = element.position.x + absoluteParentElement.x;
7725
- var y = element.position.y + absoluteParentElement.y;
7754
+ var x = elemenetPositionWithTopLeftAnchor.x + absoluteParentElement.x;
7755
+ var y = elemenetPositionWithTopLeftAnchor.y + absoluteParentElement.y;
7726
7756
  return {
7727
7757
  x: x,
7728
7758
  y: y,
@@ -9313,9 +9343,10 @@ var Paper = function (props) {
9313
9343
  var rect = currentTarget.getBoundingClientRect();
9314
9344
  var offsetX = ev.clientX - rect.left;
9315
9345
  var offsetY = ev.clientY - rect.top;
9346
+ var sourceElementAbsPosition = getAbsolutePosition(tempLink.sourceElement);
9316
9347
  var sourcePosition = {
9317
- x: tempLink.sourceElement.position.x + tempLink.sourcePort.position.x,
9318
- y: tempLink.sourceElement.position.y + tempLink.sourcePort.position.y
9348
+ x: sourceElementAbsPosition.x + tempLink.sourcePort.position.x,
9349
+ y: sourceElementAbsPosition.y + tempLink.sourcePort.position.y
9319
9350
  };
9320
9351
  //reduce the position of offset to the direction of the source point 1 unit to avoid the link to reach the current mouse position
9321
9352
  var tempTargetPosition_1 = {
@@ -9805,16 +9836,16 @@ var Paper = function (props) {
9805
9836
  if (!link.targetElement || !link.targetPort)
9806
9837
  return null;
9807
9838
  return (React.createElement(ElementLink, { key: link.id, id: link.id, path: link.path, sourcePosition: {
9808
- x: getAbsolutePosition(link.sourceElement).x + link.sourcePort.position.x,
9809
- y: getAbsolutePosition(link.sourceElement).y + link.sourcePort.position.y
9839
+ x: getAnchorAdjustedAbsolutePosition(link.sourceElement).x + link.sourcePort.position.x,
9840
+ y: getAnchorAdjustedAbsolutePosition(link.sourceElement).y + link.sourcePort.position.y
9810
9841
  }, targetPosition: {
9811
- x: getAbsolutePosition(link.targetElement).x + link.targetPort.position.x,
9812
- y: getAbsolutePosition(link.targetElement).y + link.targetPort.position.y
9842
+ x: getAnchorAdjustedAbsolutePosition(link.targetElement).x + link.targetPort.position.x,
9843
+ y: getAnchorAdjustedAbsolutePosition(link.targetElement).y + link.targetPort.position.y
9813
9844
  }, points: link.points, onPathChanged: handlePathChange, onClickDelete: handleClickLinkDelete(link, index), onSelected: function () { return handleSelectLink(link); }, onDeselected: function () { return handleDeselectLink(); }, container: paperContainerRef.current, markerStart: link.markerStart, markerEnd: link.markerEnd, markerDistanceFromPort: link.markerDistanceFromPort, markerSize: link.markerSize, label: link.label, sourceLabel: link.sourceLabel, targetLabel: link.targetLabel, onLabelMoved: onLabelMoved(index), onLabelResized: onLabelResized(index), onLabelContentChanged: onLabelContentChanged(index) }));
9814
9845
  }),
9815
9846
  (tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React.createElement(ElementLink, { id: tempLink.id, points: tempLink.points, sourcePosition: {
9816
- x: getAbsolutePosition(tempLink.sourceElement).x + tempLink.sourcePort.position.x,
9817
- y: getAbsolutePosition(tempLink.sourceElement).y + tempLink.sourcePort.position.y
9847
+ x: getAnchorAdjustedAbsolutePosition(tempLink.sourceElement).x + tempLink.sourcePort.position.x,
9848
+ y: getAnchorAdjustedAbsolutePosition(tempLink.sourceElement).y + tempLink.sourcePort.position.y
9818
9849
  }, targetPosition: tempLink.tempTargetPosition, container: paperContainerRef.current, markerStart: tempLink.markerStart, markerEnd: tempLink.markerEnd, markerDistanceFromPort: tempLink.markerDistanceFromPort, markerSize: tempLink.markerSize }),
9819
9850
  texts.map(function (text, index) { return (React.createElement(Text$1, { key: text.id, id: text.id, x: text.position.x, y: text.position.y, width: text.size.width, height: text.size.height, editable: text.editable, fontSize: text.fontSize, border: text.border, container: paperContainerRef.current, content: text.content, align: text.align, onSelected: function () {
9820
9851
  setSelectedText(text);
@@ -9964,6 +9995,7 @@ exports.findNearestProjectedPoint = findNearestProjectedPoint;
9964
9995
  exports.generateSubstitutePosition = generateSubstitutePosition;
9965
9996
  exports.generateUniqueId = generateUniqueId;
9966
9997
  exports.getAbsolutePosition = getAbsolutePosition;
9998
+ exports.getAnchorAdjustedAbsolutePosition = getAnchorAdjustedAbsolutePosition;
9967
9999
  exports.getCurvePathData = getCurvePathData;
9968
10000
  exports.getElementRotationInfo = getElementRotationInfo;
9969
10001
  exports.getFirstIntersection = getFirstIntersection;
@@ -48,6 +48,7 @@ export declare const generateSubstitutePosition: (intersectedPosition: IPosition
48
48
  export declare const getRelativePosition: (clientPosition: IPosition, relativeElement: Element) => IPosition;
49
49
  export declare const getFourVertexesOfBBoxFromElement: (element: IElement) => IPosition[];
50
50
  export declare const getAbsolutePosition: (element: IElement) => IPosition;
51
+ export declare const getAnchorAdjustedAbsolutePosition: (element: IElement) => IPosition;
51
52
  export declare const getPortAbsolutePosition: (port: IPort, element: IElement) => IPosition;
52
53
  export declare const transformAbsPositionToElementRelativePosition: (position: IPosition, element: IElement) => IPosition;
53
54
  export declare const transformAbsPositionToRelativePositionInsideElement: (absolutePosition: IPosition, parentAbsolutePosition?: IPosition) => IPosition;
package/dist/esm/index.js CHANGED
@@ -7713,12 +7713,42 @@ var getFourVertexesOfBBoxFromElement = function (element) {
7713
7713
  //get absolute position of element
7714
7714
  var getAbsolutePosition = function (element) {
7715
7715
  var parentElement = element.parentElement;
7716
+ var elemenetPositionWithTopLeftAnchor = {
7717
+ x: element.position.x,
7718
+ y: element.position.y,
7719
+ };
7720
+ if (element.positionAnchor === PositioningAnchor.Center) {
7721
+ elemenetPositionWithTopLeftAnchor.x -= element.size.width / 2;
7722
+ elemenetPositionWithTopLeftAnchor.y -= element.size.height / 2;
7723
+ }
7724
+ if (!parentElement) {
7725
+ return __assign({}, elemenetPositionWithTopLeftAnchor);
7726
+ }
7727
+ var absoluteParentElement = getAbsolutePosition(parentElement);
7728
+ var x = elemenetPositionWithTopLeftAnchor.x + absoluteParentElement.x;
7729
+ var y = elemenetPositionWithTopLeftAnchor.y + absoluteParentElement.y;
7730
+ return {
7731
+ x: x,
7732
+ y: y,
7733
+ };
7734
+ };
7735
+ //get absolute position of element
7736
+ var getAnchorAdjustedAbsolutePosition = function (element) {
7737
+ var parentElement = element.parentElement;
7738
+ var elemenetPositionWithTopLeftAnchor = {
7739
+ x: element.position.x,
7740
+ y: element.position.y,
7741
+ };
7742
+ if (element.positionAnchor === PositioningAnchor.Center) {
7743
+ elemenetPositionWithTopLeftAnchor.x -= element.size.width / 2;
7744
+ elemenetPositionWithTopLeftAnchor.y -= element.size.height / 2;
7745
+ }
7716
7746
  if (!parentElement) {
7717
- return __assign({}, element.position);
7747
+ return __assign({}, elemenetPositionWithTopLeftAnchor);
7718
7748
  }
7719
7749
  var absoluteParentElement = getAbsolutePosition(parentElement);
7720
- var x = element.position.x + absoluteParentElement.x;
7721
- var y = element.position.y + absoluteParentElement.y;
7750
+ var x = elemenetPositionWithTopLeftAnchor.x + absoluteParentElement.x;
7751
+ var y = elemenetPositionWithTopLeftAnchor.y + absoluteParentElement.y;
7722
7752
  return {
7723
7753
  x: x,
7724
7754
  y: y,
@@ -9309,9 +9339,10 @@ var Paper = function (props) {
9309
9339
  var rect = currentTarget.getBoundingClientRect();
9310
9340
  var offsetX = ev.clientX - rect.left;
9311
9341
  var offsetY = ev.clientY - rect.top;
9342
+ var sourceElementAbsPosition = getAbsolutePosition(tempLink.sourceElement);
9312
9343
  var sourcePosition = {
9313
- x: tempLink.sourceElement.position.x + tempLink.sourcePort.position.x,
9314
- y: tempLink.sourceElement.position.y + tempLink.sourcePort.position.y
9344
+ x: sourceElementAbsPosition.x + tempLink.sourcePort.position.x,
9345
+ y: sourceElementAbsPosition.y + tempLink.sourcePort.position.y
9315
9346
  };
9316
9347
  //reduce the position of offset to the direction of the source point 1 unit to avoid the link to reach the current mouse position
9317
9348
  var tempTargetPosition_1 = {
@@ -9801,16 +9832,16 @@ var Paper = function (props) {
9801
9832
  if (!link.targetElement || !link.targetPort)
9802
9833
  return null;
9803
9834
  return (React.createElement(ElementLink, { key: link.id, id: link.id, path: link.path, sourcePosition: {
9804
- x: getAbsolutePosition(link.sourceElement).x + link.sourcePort.position.x,
9805
- y: getAbsolutePosition(link.sourceElement).y + link.sourcePort.position.y
9835
+ x: getAnchorAdjustedAbsolutePosition(link.sourceElement).x + link.sourcePort.position.x,
9836
+ y: getAnchorAdjustedAbsolutePosition(link.sourceElement).y + link.sourcePort.position.y
9806
9837
  }, targetPosition: {
9807
- x: getAbsolutePosition(link.targetElement).x + link.targetPort.position.x,
9808
- y: getAbsolutePosition(link.targetElement).y + link.targetPort.position.y
9838
+ x: getAnchorAdjustedAbsolutePosition(link.targetElement).x + link.targetPort.position.x,
9839
+ y: getAnchorAdjustedAbsolutePosition(link.targetElement).y + link.targetPort.position.y
9809
9840
  }, points: link.points, onPathChanged: handlePathChange, onClickDelete: handleClickLinkDelete(link, index), onSelected: function () { return handleSelectLink(link); }, onDeselected: function () { return handleDeselectLink(); }, container: paperContainerRef.current, markerStart: link.markerStart, markerEnd: link.markerEnd, markerDistanceFromPort: link.markerDistanceFromPort, markerSize: link.markerSize, label: link.label, sourceLabel: link.sourceLabel, targetLabel: link.targetLabel, onLabelMoved: onLabelMoved(index), onLabelResized: onLabelResized(index), onLabelContentChanged: onLabelContentChanged(index) }));
9810
9841
  }),
9811
9842
  (tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React.createElement(ElementLink, { id: tempLink.id, points: tempLink.points, sourcePosition: {
9812
- x: getAbsolutePosition(tempLink.sourceElement).x + tempLink.sourcePort.position.x,
9813
- y: getAbsolutePosition(tempLink.sourceElement).y + tempLink.sourcePort.position.y
9843
+ x: getAnchorAdjustedAbsolutePosition(tempLink.sourceElement).x + tempLink.sourcePort.position.x,
9844
+ y: getAnchorAdjustedAbsolutePosition(tempLink.sourceElement).y + tempLink.sourcePort.position.y
9814
9845
  }, targetPosition: tempLink.tempTargetPosition, container: paperContainerRef.current, markerStart: tempLink.markerStart, markerEnd: tempLink.markerEnd, markerDistanceFromPort: tempLink.markerDistanceFromPort, markerSize: tempLink.markerSize }),
9815
9846
  texts.map(function (text, index) { return (React.createElement(Text$1, { key: text.id, id: text.id, x: text.position.x, y: text.position.y, width: text.size.width, height: text.size.height, editable: text.editable, fontSize: text.fontSize, border: text.border, container: paperContainerRef.current, content: text.content, align: text.align, onSelected: function () {
9816
9847
  setSelectedText(text);
@@ -9928,5 +9959,5 @@ var Editor = function (_a) {
9928
9959
  return (React.createElement(Paper$1, { key: "paper", size: { width: width, height: height }, elements: elements, links: links, texts: texts, onPaperClicked: handlePaperClicked, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onElementMouseLeave: handleElementMouseLeave, onElementMouseMove: handleElementMouseMove, onElementMouseUp: handleElementMouseUp, onElementsChanged: handleElementsChanged, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onLinksChanged: handleLinksChanged, onTextSelected: handleTextSelected, onTextsChanged: handleTextsChanged, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseUp, onPaperMouseDown: handlePaperMouseDown, onManuallyTriggerRenderElement: editorContext.onManuallyTriggerRenderElement.bind(editorContext), onManuallyTriggerRenderPort: editorContext.onManuallyTriggerRenderPort.bind(editorContext) }));
9929
9960
  };
9930
9961
 
9931
- export { Circle as CircleRC, Crescent as CrescentRC, CustomShape as CustomShapeRC, EditorContext, Element$2 as Element, ElementLink$1 as ElementLink, ElementLink as ElementLinkRC, Port$1 as Port, Port as PortRC, PositioningAnchor, Rectangle as RectangleRC, RectangularFrame as RectangularFrameRC, ResizingDirection, ShapeWrapper as ShapeWrapperRC, SubObjectDirection, Text$2 as Text, TextAlign, Text$1 as TextRC, addPointToList, calculateAngleWithOx, checkPointContainsPolygon, checkPositionOnLine, checkSamePosition, configureLogger, correctPortPositionInElement, createSmoothPathString, Editor as default, degreeToRadian, diamondEdgeInsideSquare, dist, findNearestPointOnSegment, findNearestPosition, findNearestProjectedPoint, generateSubstitutePosition, generateUniqueId, getAbsolutePosition, getCurvePathData, getElementRotationInfo, getFirstIntersection, getFourVertexesOfBBoxFromElement, getIntersectionPositions, getPortAbsolutePosition, getRectangleCorners, getRelativePosition, getRotatedRectangleCoordinates, getRotatedSVGBBox, getSVGBBoxOutsideTransformedParent, makePolygonOfElement, pathDataToD, removeDuplicatePosition, transformAbsPositionToElementRelativePosition, transformAbsPositionToRelativePositionInsideElement };
9962
+ export { Circle as CircleRC, Crescent as CrescentRC, CustomShape as CustomShapeRC, EditorContext, Element$2 as Element, ElementLink$1 as ElementLink, ElementLink as ElementLinkRC, Port$1 as Port, Port as PortRC, PositioningAnchor, Rectangle as RectangleRC, RectangularFrame as RectangularFrameRC, ResizingDirection, ShapeWrapper as ShapeWrapperRC, SubObjectDirection, Text$2 as Text, TextAlign, Text$1 as TextRC, addPointToList, calculateAngleWithOx, checkPointContainsPolygon, checkPositionOnLine, checkSamePosition, configureLogger, correctPortPositionInElement, createSmoothPathString, Editor as default, degreeToRadian, diamondEdgeInsideSquare, dist, findNearestPointOnSegment, findNearestPosition, findNearestProjectedPoint, generateSubstitutePosition, generateUniqueId, getAbsolutePosition, getAnchorAdjustedAbsolutePosition, getCurvePathData, getElementRotationInfo, getFirstIntersection, getFourVertexesOfBBoxFromElement, getIntersectionPositions, getPortAbsolutePosition, getRectangleCorners, getRelativePosition, getRotatedRectangleCoordinates, getRotatedSVGBBox, getSVGBBoxOutsideTransformedParent, makePolygonOfElement, pathDataToD, removeDuplicatePosition, transformAbsPositionToElementRelativePosition, transformAbsPositionToRelativePositionInsideElement };
9932
9963
  //# sourceMappingURL=index.js.map