orcasvn-react-diagrams 0.1.7 → 0.1.9

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 (31) hide show
  1. package/dist/cjs/index.js +37 -20
  2. package/dist/cjs/types/components/ports/port.d.ts +1 -1
  3. package/dist/cjs/types/index.d.ts +1 -6
  4. package/dist/cjs/types/mocks/portIn.d.ts +4 -0
  5. package/dist/cjs/types/mocks/textsWithFlexBox.d.ts +2 -0
  6. package/dist/cjs/types/models/IElement.d.ts +4 -0
  7. package/dist/cjs/types/models/IElementProps.d.ts +4 -0
  8. package/dist/cjs/types/models/IFlexboxType.d.ts +20 -0
  9. package/dist/cjs/types/models/IPortProps.d.ts +1 -0
  10. package/dist/cjs/types/models/IText.d.ts +2 -0
  11. package/dist/cjs/types/models/ITextProps.d.ts +2 -0
  12. package/dist/cjs/types/models/implementations/Element.d.ts +5 -1
  13. package/dist/cjs/types/models/implementations/Text.d.ts +3 -1
  14. package/dist/cjs/types/models/implementations/rectangularFrameElement.d.ts +3 -1
  15. package/dist/esm/index.js +37 -20
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/types/components/ports/port.d.ts +1 -1
  18. package/dist/esm/types/index.d.ts +1 -6
  19. package/dist/esm/types/mocks/portIn.d.ts +4 -0
  20. package/dist/esm/types/mocks/textsWithFlexBox.d.ts +2 -0
  21. package/dist/esm/types/models/IElement.d.ts +4 -0
  22. package/dist/esm/types/models/IElementProps.d.ts +4 -0
  23. package/dist/esm/types/models/IFlexboxType.d.ts +20 -0
  24. package/dist/esm/types/models/IPortProps.d.ts +1 -0
  25. package/dist/esm/types/models/IText.d.ts +2 -0
  26. package/dist/esm/types/models/ITextProps.d.ts +2 -0
  27. package/dist/esm/types/models/implementations/Element.d.ts +5 -1
  28. package/dist/esm/types/models/implementations/Text.d.ts +3 -1
  29. package/dist/esm/types/models/implementations/rectangularFrameElement.d.ts +3 -1
  30. package/dist/index.d.ts +37 -3
  31. package/package.json +3 -2
package/dist/cjs/index.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var require$$0 = require('react-dom');
7
+ var Flexbox = require('react-svg-flexbox');
7
8
 
8
9
  exports.PositioningAnchor = void 0;
9
10
  (function (PositioningAnchor) {
@@ -441,7 +442,7 @@ function generateUniqueId() {
441
442
  }
442
443
 
443
444
  var Element$1 = /** @class */ (function () {
444
- function Element(x, y, width, height, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection) {
445
+ function Element(x, y, width, height, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection, parentElement, textsPlaceHolderClassName, textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition) {
445
446
  if (portMovealeAreas === void 0) { portMovealeAreas = []; }
446
447
  this.resizability = {
447
448
  enabled: true,
@@ -459,6 +460,10 @@ var Element$1 = /** @class */ (function () {
459
460
  this.portMoveableAreas = portMovealeAreas;
460
461
  this.portSlideRailSVGClassName = portSlideRailSVGClassName;
461
462
  this.portDirection = portDirection;
463
+ this.parentElement = parentElement;
464
+ this.textsPlaceHolderClassName = textsPlaceHolderClassName;
465
+ this.textsPlaceHolderFlexStyle = textsPlaceHolderFlexStyle;
466
+ this.textsPlaceHolderFlexboxPosition = textsPlaceHolderFlexboxPosition;
462
467
  }
463
468
  Object.defineProperty(Element.prototype, "id", {
464
469
  get: function () {
@@ -611,13 +616,14 @@ var ElementLink$1 = /** @class */ (function () {
611
616
  }());
612
617
 
613
618
  var Text$2 = /** @class */ (function () {
614
- function Text(content, width, height, x, y, align, fontSize, border) {
619
+ function Text(content, width, height, x, y, align, fontSize, border, style) {
615
620
  this._id = generateUniqueId();
616
621
  this.content = content;
617
622
  this.align = align;
618
623
  this.fontSize = fontSize;
619
624
  this.border = border;
620
625
  this.size = { width: width, height: height };
626
+ this.style = style;
621
627
  if (x && y) {
622
628
  this.position = { x: x, y: y };
623
629
  }
@@ -837,7 +843,7 @@ var Crescent = function (props) {
837
843
  }
838
844
  var sw = props.stroke ? (props.strokeWidth || 1) : 0;
839
845
  return (React.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height }),
840
- React.createElement("path", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", d: "M0,75 A50,50 0 1,1 100,75 Z", fill: props.fill || 'none', stroke: props.stroke || 'none', strokeWidth: sw })));
846
+ React.createElement("path", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", d: "M0,50 A50,50 0 1,1 100,50 Z", fill: props.fill || 'none', stroke: props.stroke || 'none', strokeWidth: sw })));
841
847
  };
842
848
 
843
849
  var Rectangle = function (props) {
@@ -1395,9 +1401,14 @@ var Text = React.forwardRef(function (_a, ref) {
1395
1401
  });
1396
1402
  var Text$1 = React.memo(Text);
1397
1403
 
1398
- var Port = React.forwardRef(function (props, ref) {
1399
- 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, renderShape = props.renderShape;
1404
+ var Port1 = React.forwardRef(function (props, ref) {
1405
+ 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;
1400
1406
  var textRef = React.useRef(null);
1407
+ var rotationAngle = React.useMemo(function () {
1408
+ if (!calculateRotationAngle)
1409
+ return 0;
1410
+ return calculateRotationAngle(x, y);
1411
+ }, [calculateRotationAngle, x, y]);
1401
1412
  var renderLabel = function (label) {
1402
1413
  var content = label.content, size = label.size;
1403
1414
  var position = label.position || PORT_LABEL_POSITION;
@@ -1406,7 +1417,7 @@ var Port = React.forwardRef(function (props, ref) {
1406
1417
  var renderedShape = React.useMemo(function () {
1407
1418
  if (renderShape) {
1408
1419
  var RenderShape = renderShape;
1409
- return (React.createElement(RenderShape, __assign({ ref: ref }, props)));
1420
+ return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1410
1421
  }
1411
1422
  else {
1412
1423
  return React.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" });
@@ -1415,7 +1426,8 @@ var Port = React.forwardRef(function (props, ref) {
1415
1426
  return (React.createElement(React.Fragment, null,
1416
1427
  renderedShape,
1417
1428
  label && renderLabel(label)));
1418
- });
1429
+ });
1430
+ var Port = React.memo(Port1);
1419
1431
 
1420
1432
  // Render the svg <path> element
1421
1433
  function getCurvePathData(points, smoothing, closed) {
@@ -7641,7 +7653,7 @@ var checkPositionOnLine = function (position, line) {
7641
7653
 
7642
7654
  var Element = function (props) {
7643
7655
  var _a, _b, _c;
7644
- 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, texts = props.texts, portSlideRailSVGClassName = props.portSlideRailSVGClassName, portMoveableAreas = props.portMoveableAreas, portDirection = props.portDirection, onClick = props.onClick, 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;
7656
+ 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, onClick = props.onClick, 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;
7645
7657
  var _d = React.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
7646
7658
  var _e = React.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
7647
7659
  return __assign(__assign({}, p), { id: p.id, ref: React.createRef() });
@@ -7769,11 +7781,11 @@ var Element = function (props) {
7769
7781
  }
7770
7782
  return coordinates;
7771
7783
  };
7772
- var getSlideRailSVG = function (portSlideRailSVGClassName) {
7784
+ var getSlideRailSVG = React.useCallback(function (portSlideRailSVGClassName) {
7773
7785
  var _a;
7774
7786
  var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
7775
7787
  return slideRailSVG;
7776
- };
7788
+ }, [elementRef.current]);
7777
7789
  var normalizePortPositionOnSlideRailSVG = function (portSlideRailSVGClassName, position) {
7778
7790
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
7779
7791
  if (!slideRailSVG)
@@ -7810,6 +7822,7 @@ var Element = function (props) {
7810
7822
  };
7811
7823
  //Normalize port position
7812
7824
  var normalizePortPosition = function (tempNewPosition) {
7825
+ console.info('normalizePortPosition', tempNewPosition);
7813
7826
  var newPosition;
7814
7827
  if (portMoveableAreas && portMoveableAreas.length > 0) { //If moveable areas is defined
7815
7828
  newPosition = normalizePortPositionOnMoveableAreas(portMoveableAreas, tempNewPosition);
@@ -7935,16 +7948,16 @@ var Element = function (props) {
7935
7948
  }
7936
7949
  };
7937
7950
  //Get rotate angle of port by port direction is defined.
7938
- var rotatePort = React.useCallback(function (port) {
7951
+ var rotatePort = React.useCallback(function (x, y) {
7952
+ console.info('calculating port rotation', x, y);
7939
7953
  if (!portSlideRailSVGClassName)
7940
7954
  return 0;
7941
7955
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
7942
7956
  if (!slideRailSVG)
7943
7957
  return 0;
7944
7958
  var rotationAngle = 0;
7945
- port.id; var position = port.position; port.size;
7946
7959
  //Standardize the port position to be in the correct position
7947
- var normalizedPosition = normalizePortPosition(position);
7960
+ var normalizedPosition = normalizePortPosition({ x: x, y: y });
7948
7961
  switch (portDirection) {
7949
7962
  case exports.SubObjectDirection.Radial:
7950
7963
  var center = {
@@ -7974,7 +7987,7 @@ var Element = function (props) {
7974
7987
  break;
7975
7988
  }
7976
7989
  return rotationAngle;
7977
- }, [portSlideRailSVGClassName, portDirection]);
7990
+ }, [portSlideRailSVGClassName, portDirection, getSlideRailSVG]);
7978
7991
  var renderedShape = React.useMemo(function () {
7979
7992
  if (renderShape)
7980
7993
  return renderShape(props);
@@ -7996,6 +8009,8 @@ var Element = function (props) {
7996
8009
  enabled: false,
7997
8010
  keepRatio: false
7998
8011
  },
8012
+ // width: selectedPort?.size.width,
8013
+ // height: selectedPort?.size.height,
7999
8014
  movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
8000
8015
  onMove: handlePortMove
8001
8016
  });
@@ -8005,12 +8020,14 @@ var Element = function (props) {
8005
8020
  ? React.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
8006
8021
  : React.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 :
8007
8022
  ports.map(function (p, index) {
8008
- return React.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: p.size.width, height: p.size.height, container: container, rotation: rotatePort(p), 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 });
8009
- }), texts === null || texts === void 0 ? void 0 :
8010
- texts.map(function (t, index) {
8011
- var _a, _b;
8012
- return React.createElement(Text$1, { id: t.id, key: index, content: t.content, x: (_a = t.position) === null || _a === void 0 ? void 0 : _a.x, y: (_b = t.position) === null || _b === void 0 ? void 0 : _b.y, width: t.size.width, height: t.size.height, align: t.align, fontSize: t.fontSize, border: t.border, container: container, onContentChanged: function (ev, newContent) { return onTextUpdated === null || onTextUpdated === void 0 ? void 0 : onTextUpdated(t.id, newContent); } });
8023
+ return React.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: p.size.width, height: p.size.height, container: container,
8024
+ // rotation={rotatePort(p)}
8025
+ 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 });
8013
8026
  }),
8027
+ React.createElement(Flexbox, { 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) {
8028
+ var _a, _b;
8029
+ return React.createElement(Text$1, { id: t.id, key: index, content: t.content, x: (_a = t.position) === null || _a === void 0 ? void 0 : _a.x, y: (_b = t.position) === null || _b === void 0 ? void 0 : _b.y, width: t.size.width, height: t.size.height, align: t.align, fontSize: t.fontSize, border: t.border, container: container, style: t.style, onContentChanged: function (ev, newContent) { return onTextUpdated === null || onTextUpdated === void 0 ? void 0 : onTextUpdated(t.id, newContent); } });
8030
+ })),
8014
8031
  children));
8015
8032
  };
8016
8033
 
@@ -8737,7 +8754,7 @@ var Paper = function (props) {
8737
8754
  setMouseDownedOnPaper(false);
8738
8755
  }, container: paperContainerRef.current, renderShape: element.renderShape, cssClass: element.cssClass, texts: element.texts, ports: element.ports, portMoveableAreas: element.portMoveableAreas, portSlideRailSVGClassName: element.portSlideRailSVGClassName, portDirection: element.portDirection, onPortMoved: handlePortMoved, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp,
8739
8756
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
8740
- onMouseUpAtLinkedPortPlaceholder: function (elementLink, position) { return handleMouseUpAtLinkedPortPlaceholder(elementLink, position, element); }, onTextUpdated: function (textId, newContent) { return handleElementTextChange(element, textId, newContent); } }, element.childrenElements && element.childrenElements.map(renderElementInTree))));
8757
+ onMouseUpAtLinkedPortPlaceholder: function (elementLink, position) { return handleMouseUpAtLinkedPortPlaceholder(elementLink, position, element); }, onTextUpdated: function (textId, newContent) { return handleElementTextChange(element, textId, newContent); }, textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition }, element.childrenElements && element.childrenElements.map(renderElementInTree))));
8741
8758
  };
8742
8759
  return (React.createElement("div", { style: { position: "relative" } },
8743
8760
  React.createElement(Ruler, { squareSize: 100, border: '1px dashed grey' }),
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import { IPortProps } from "../../models/IPortProps";
3
- export declare const Port: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>;
3
+ export declare const Port: React.MemoExoticComponent<React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>>;
@@ -1,6 +1 @@
1
- export * from './models';
2
- export * from './components/shapes';
3
- export * from './components/ports';
4
- export * from './components/links';
5
- export * from './components/texts';
6
- export { default } from './components/editor';
1
+ import './index.css';
@@ -0,0 +1,4 @@
1
+ import { CustomPort } from "../models/implementations/CustomPort";
2
+ export default class PortIn extends CustomPort {
3
+ constructor(x: number, y: number, width: number, height: number);
4
+ }
@@ -0,0 +1,2 @@
1
+ import { EditorContext } from "../models";
2
+ export declare const editorContextOfTextWithFlexBox: EditorContext;
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { SubObjectDirection } from "./enums/SubObjectDirection";
3
3
  import IElementProps from "./IElementProps";
4
+ import IFlexboxType from "./IFlexboxType";
4
5
  import IPort from "./IPort";
5
6
  import IResizability from "./IResizability";
6
7
  import IText from "./IText";
@@ -28,4 +29,7 @@ export default interface IElement {
28
29
  onAddedPort: (callback: (newPort: IPort) => void) => (() => void);
29
30
  deletePort: (id: string) => void;
30
31
  onDeletedPort: (callback: (id: string) => void) => (() => void);
32
+ textsPlaceHolderClassName?: string;
33
+ textsPlaceHolderFlexStyle?: IFlexboxType;
34
+ textsPlaceHolderFlexboxPosition?: IPosition;
31
35
  }
@@ -2,6 +2,7 @@
2
2
  import { onElementMovedHandler, onElementResizedHandler, onPortMouseDownHandler, onPortMouseUpHandler, onPortMovedHandler } from "./callbackTypes";
3
3
  import { SubObjectDirection } from "./enums/SubObjectDirection";
4
4
  import IElementLink from "./IElementLink";
5
+ import IFlexboxType from "./IFlexboxType";
5
6
  import IPort from "./IPort";
6
7
  import IText from "./IText";
7
8
  import IPosition from "./position";
@@ -32,5 +33,8 @@ interface IElementProps {
32
33
  onMouseUp?: (event: React.MouseEvent) => void;
33
34
  onMouseUpAtLinkedPortPlaceholder?: (link: IElementLink, position: IPosition) => void;
34
35
  onTextUpdated?: (textId: string, newTextContent: string) => void;
36
+ textsPlaceHolderClassName?: string;
37
+ textsPlaceHolderFlexStyle?: IFlexboxType;
38
+ textsPlaceHolderFlexboxPosition?: IPosition;
35
39
  }
36
40
  export default IElementProps;
@@ -0,0 +1,20 @@
1
+ export default interface IFlexboxType {
2
+ width?: number;
3
+ height?: number;
4
+ flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse';
5
+ flexWrap?: 'no-wrap' | 'wrap';
6
+ justifyContent?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
7
+ alignItems?: 'flex-start' | 'flex-end' | 'center';
8
+ alignSelf?: 'flex-start' | 'flex-end' | 'center';
9
+ alignContent?: 'flex-start' | 'flex-end' | 'center' | 'stretch';
10
+ padding?: number;
11
+ paddingLeft?: number;
12
+ paddingRight?: number;
13
+ paddingTop?: number;
14
+ paddingBottom?: number;
15
+ margin?: number;
16
+ marginLeft?: number;
17
+ marginRight?: number;
18
+ marginTop?: number;
19
+ marginBottom?: number;
20
+ }
@@ -21,4 +21,5 @@ export interface IPortProps {
21
21
  onPortLabelResized?: (width: number, height: number) => void;
22
22
  onPortLabelContentChanged?: (ev: React.ChangeEvent, newValue: string) => void;
23
23
  renderShape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>;
24
+ calculateRotationAngle?: (x: number, y: number) => number;
24
25
  }
@@ -1,4 +1,5 @@
1
1
  import { TextAlign } from "./enums/TextAlign";
2
+ import IFlexboxType from "./IFlexboxType";
2
3
  import IPosition from "./position";
3
4
  import ISize from "./size";
4
5
  export default interface IText {
@@ -9,6 +10,7 @@ export default interface IText {
9
10
  align?: TextAlign;
10
11
  fontSize?: number;
11
12
  border?: string;
13
+ style?: IFlexboxType;
12
14
  }
13
15
  export interface IPaperText extends IText {
14
16
  position: IPosition;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { TextAlign } from "./enums/TextAlign";
3
+ import IFlexboxType from "./IFlexboxType";
3
4
  import IText from "./IText";
4
5
  export default interface ITextProps {
5
6
  id: string;
@@ -11,6 +12,7 @@ export default interface ITextProps {
11
12
  align?: TextAlign;
12
13
  fontSize?: number;
13
14
  border?: string;
15
+ style?: IFlexboxType;
14
16
  container: Element;
15
17
  onSelected?: (text: IText) => void;
16
18
  onMoved?: (x: number, y: number) => void;
@@ -8,6 +8,7 @@ import IPort from "../IPort";
8
8
  import IText from "../IText";
9
9
  import { SubObjectDirection } from "../enums/SubObjectDirection";
10
10
  import EventEmitter from "eventemitter3";
11
+ import IFlexboxType from "../IFlexboxType";
11
12
  export default class Element implements IElement {
12
13
  private readonly _id;
13
14
  protected _position: IPosition;
@@ -27,8 +28,11 @@ export default class Element implements IElement {
27
28
  portDirection?: SubObjectDirection;
28
29
  onResized?: ((width: number, height: number) => void) | undefined;
29
30
  onMoved?: ((x: number, y: number) => void) | undefined;
31
+ textsPlaceHolderClassName?: string;
32
+ textsPlaceHolderFlexStyle?: IFlexboxType;
33
+ textsPlaceHolderFlexboxPosition?: IPosition;
30
34
  _eventEmitter: EventEmitter;
31
- 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);
35
+ 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);
32
36
  get id(): string;
33
37
  get size(): ISize;
34
38
  set size(value: ISize);
@@ -1,4 +1,5 @@
1
1
  import { TextAlign } from "../enums";
2
+ import IFlexboxType from "../IFlexboxType";
2
3
  import IText from "../IText";
3
4
  import IPosition from "../position";
4
5
  import ISize from "../size";
@@ -10,6 +11,7 @@ export default class Text implements IText {
10
11
  align?: TextAlign;
11
12
  fontSize?: number;
12
13
  border?: string;
13
- constructor(content: string, width: number, height: number, x?: number, y?: number, align?: TextAlign, fontSize?: number, border?: string);
14
+ style?: IFlexboxType;
15
+ constructor(content: string, width: number, height: number, x?: number, y?: number, align?: TextAlign, fontSize?: number, border?: string, style?: IFlexboxType);
14
16
  get id(): string;
15
17
  }
@@ -2,7 +2,9 @@ import Element from "./Element";
2
2
  import IResizability from "../IResizability";
3
3
  import IPort from "../IPort";
4
4
  import IText from "../IText";
5
+ import IFlexboxType from '../IFlexboxType';
6
+ import IPosition from '../position';
5
7
  export default class RectangularFrameElement extends Element {
6
8
  resizability: IResizability;
7
- constructor(x: number, y: number, width: number, height: number, cssClass?: string, texts?: IText[], ports?: IPort[]);
9
+ constructor(x: number, y: number, width: number, height: number, cssClass?: string, texts?: IText[], ports?: IPort[], textsPlaceHolderClassName?: string, textsPlaceHolderFlexStyle?: IFlexboxType, textsPlaceHolderFlexboxPosition?: IPosition);
8
10
  }
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import React, { forwardRef, useMemo, useCallback, useEffect, createContext, useState, useRef, useContext, memo, useLayoutEffect } from 'react';
2
2
  import require$$0 from 'react-dom';
3
+ import Flexbox from 'react-svg-flexbox';
3
4
 
4
5
  var PositioningAnchor;
5
6
  (function (PositioningAnchor) {
@@ -437,7 +438,7 @@ function generateUniqueId() {
437
438
  }
438
439
 
439
440
  var Element$1 = /** @class */ (function () {
440
- function Element(x, y, width, height, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection) {
441
+ function Element(x, y, width, height, cssClass, renderShape, texts, ports, portMovealeAreas, portSlideRailSVGClassName, portDirection, parentElement, textsPlaceHolderClassName, textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition) {
441
442
  if (portMovealeAreas === void 0) { portMovealeAreas = []; }
442
443
  this.resizability = {
443
444
  enabled: true,
@@ -455,6 +456,10 @@ var Element$1 = /** @class */ (function () {
455
456
  this.portMoveableAreas = portMovealeAreas;
456
457
  this.portSlideRailSVGClassName = portSlideRailSVGClassName;
457
458
  this.portDirection = portDirection;
459
+ this.parentElement = parentElement;
460
+ this.textsPlaceHolderClassName = textsPlaceHolderClassName;
461
+ this.textsPlaceHolderFlexStyle = textsPlaceHolderFlexStyle;
462
+ this.textsPlaceHolderFlexboxPosition = textsPlaceHolderFlexboxPosition;
458
463
  }
459
464
  Object.defineProperty(Element.prototype, "id", {
460
465
  get: function () {
@@ -607,13 +612,14 @@ var ElementLink$1 = /** @class */ (function () {
607
612
  }());
608
613
 
609
614
  var Text$2 = /** @class */ (function () {
610
- function Text(content, width, height, x, y, align, fontSize, border) {
615
+ function Text(content, width, height, x, y, align, fontSize, border, style) {
611
616
  this._id = generateUniqueId();
612
617
  this.content = content;
613
618
  this.align = align;
614
619
  this.fontSize = fontSize;
615
620
  this.border = border;
616
621
  this.size = { width: width, height: height };
622
+ this.style = style;
617
623
  if (x && y) {
618
624
  this.position = { x: x, y: y };
619
625
  }
@@ -833,7 +839,7 @@ var Crescent = function (props) {
833
839
  }
834
840
  var sw = props.stroke ? (props.strokeWidth || 1) : 0;
835
841
  return (React.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height }),
836
- React.createElement("path", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", d: "M0,75 A50,50 0 1,1 100,75 Z", fill: props.fill || 'none', stroke: props.stroke || 'none', strokeWidth: sw })));
842
+ React.createElement("path", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", d: "M0,50 A50,50 0 1,1 100,50 Z", fill: props.fill || 'none', stroke: props.stroke || 'none', strokeWidth: sw })));
837
843
  };
838
844
 
839
845
  var Rectangle = function (props) {
@@ -1391,9 +1397,14 @@ var Text = forwardRef(function (_a, ref) {
1391
1397
  });
1392
1398
  var Text$1 = memo(Text);
1393
1399
 
1394
- var Port = forwardRef(function (props, ref) {
1395
- 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, renderShape = props.renderShape;
1400
+ var Port1 = forwardRef(function (props, ref) {
1401
+ 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;
1396
1402
  var textRef = useRef(null);
1403
+ var rotationAngle = useMemo(function () {
1404
+ if (!calculateRotationAngle)
1405
+ return 0;
1406
+ return calculateRotationAngle(x, y);
1407
+ }, [calculateRotationAngle, x, y]);
1397
1408
  var renderLabel = function (label) {
1398
1409
  var content = label.content, size = label.size;
1399
1410
  var position = label.position || PORT_LABEL_POSITION;
@@ -1402,7 +1413,7 @@ var Port = forwardRef(function (props, ref) {
1402
1413
  var renderedShape = useMemo(function () {
1403
1414
  if (renderShape) {
1404
1415
  var RenderShape = renderShape;
1405
- return (React.createElement(RenderShape, __assign({ ref: ref }, props)));
1416
+ return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1406
1417
  }
1407
1418
  else {
1408
1419
  return React.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: PositioningAnchor.Center, height: height, width: width, stroke: "black", fill: "black" });
@@ -1411,7 +1422,8 @@ var Port = forwardRef(function (props, ref) {
1411
1422
  return (React.createElement(React.Fragment, null,
1412
1423
  renderedShape,
1413
1424
  label && renderLabel(label)));
1414
- });
1425
+ });
1426
+ var Port = memo(Port1);
1415
1427
 
1416
1428
  // Render the svg <path> element
1417
1429
  function getCurvePathData(points, smoothing, closed) {
@@ -7637,7 +7649,7 @@ var checkPositionOnLine = function (position, line) {
7637
7649
 
7638
7650
  var Element = function (props) {
7639
7651
  var _a, _b, _c;
7640
- 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, texts = props.texts, portSlideRailSVGClassName = props.portSlideRailSVGClassName, portMoveableAreas = props.portMoveableAreas, portDirection = props.portDirection, onClick = props.onClick, 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;
7652
+ 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, onClick = props.onClick, 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;
7641
7653
  var _d = useState(), selectedPort = _d[0], setSelectedPort = _d[1];
7642
7654
  var _e = useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
7643
7655
  return __assign(__assign({}, p), { id: p.id, ref: React.createRef() });
@@ -7765,11 +7777,11 @@ var Element = function (props) {
7765
7777
  }
7766
7778
  return coordinates;
7767
7779
  };
7768
- var getSlideRailSVG = function (portSlideRailSVGClassName) {
7780
+ var getSlideRailSVG = useCallback(function (portSlideRailSVGClassName) {
7769
7781
  var _a;
7770
7782
  var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
7771
7783
  return slideRailSVG;
7772
- };
7784
+ }, [elementRef.current]);
7773
7785
  var normalizePortPositionOnSlideRailSVG = function (portSlideRailSVGClassName, position) {
7774
7786
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
7775
7787
  if (!slideRailSVG)
@@ -7806,6 +7818,7 @@ var Element = function (props) {
7806
7818
  };
7807
7819
  //Normalize port position
7808
7820
  var normalizePortPosition = function (tempNewPosition) {
7821
+ console.info('normalizePortPosition', tempNewPosition);
7809
7822
  var newPosition;
7810
7823
  if (portMoveableAreas && portMoveableAreas.length > 0) { //If moveable areas is defined
7811
7824
  newPosition = normalizePortPositionOnMoveableAreas(portMoveableAreas, tempNewPosition);
@@ -7931,16 +7944,16 @@ var Element = function (props) {
7931
7944
  }
7932
7945
  };
7933
7946
  //Get rotate angle of port by port direction is defined.
7934
- var rotatePort = useCallback(function (port) {
7947
+ var rotatePort = useCallback(function (x, y) {
7948
+ console.info('calculating port rotation', x, y);
7935
7949
  if (!portSlideRailSVGClassName)
7936
7950
  return 0;
7937
7951
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
7938
7952
  if (!slideRailSVG)
7939
7953
  return 0;
7940
7954
  var rotationAngle = 0;
7941
- port.id; var position = port.position; port.size;
7942
7955
  //Standardize the port position to be in the correct position
7943
- var normalizedPosition = normalizePortPosition(position);
7956
+ var normalizedPosition = normalizePortPosition({ x: x, y: y });
7944
7957
  switch (portDirection) {
7945
7958
  case SubObjectDirection.Radial:
7946
7959
  var center = {
@@ -7970,7 +7983,7 @@ var Element = function (props) {
7970
7983
  break;
7971
7984
  }
7972
7985
  return rotationAngle;
7973
- }, [portSlideRailSVGClassName, portDirection]);
7986
+ }, [portSlideRailSVGClassName, portDirection, getSlideRailSVG]);
7974
7987
  var renderedShape = useMemo(function () {
7975
7988
  if (renderShape)
7976
7989
  return renderShape(props);
@@ -7992,6 +8005,8 @@ var Element = function (props) {
7992
8005
  enabled: false,
7993
8006
  keepRatio: false
7994
8007
  },
8008
+ // width: selectedPort?.size.width,
8009
+ // height: selectedPort?.size.height,
7995
8010
  movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
7996
8011
  onMove: handlePortMove
7997
8012
  });
@@ -8001,12 +8016,14 @@ var Element = function (props) {
8001
8016
  ? React.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
8002
8017
  : React.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 :
8003
8018
  ports.map(function (p, index) {
8004
- return React.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: p.size.width, height: p.size.height, container: container, rotation: rotatePort(p), 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 });
8005
- }), texts === null || texts === void 0 ? void 0 :
8006
- texts.map(function (t, index) {
8007
- var _a, _b;
8008
- return React.createElement(Text$1, { id: t.id, key: index, content: t.content, x: (_a = t.position) === null || _a === void 0 ? void 0 : _a.x, y: (_b = t.position) === null || _b === void 0 ? void 0 : _b.y, width: t.size.width, height: t.size.height, align: t.align, fontSize: t.fontSize, border: t.border, container: container, onContentChanged: function (ev, newContent) { return onTextUpdated === null || onTextUpdated === void 0 ? void 0 : onTextUpdated(t.id, newContent); } });
8019
+ return React.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: p.size.width, height: p.size.height, container: container,
8020
+ // rotation={rotatePort(p)}
8021
+ 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 });
8009
8022
  }),
8023
+ React.createElement(Flexbox, { 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) {
8024
+ var _a, _b;
8025
+ return React.createElement(Text$1, { id: t.id, key: index, content: t.content, x: (_a = t.position) === null || _a === void 0 ? void 0 : _a.x, y: (_b = t.position) === null || _b === void 0 ? void 0 : _b.y, width: t.size.width, height: t.size.height, align: t.align, fontSize: t.fontSize, border: t.border, container: container, style: t.style, onContentChanged: function (ev, newContent) { return onTextUpdated === null || onTextUpdated === void 0 ? void 0 : onTextUpdated(t.id, newContent); } });
8026
+ })),
8010
8027
  children));
8011
8028
  };
8012
8029
 
@@ -8733,7 +8750,7 @@ var Paper = function (props) {
8733
8750
  setMouseDownedOnPaper(false);
8734
8751
  }, container: paperContainerRef.current, renderShape: element.renderShape, cssClass: element.cssClass, texts: element.texts, ports: element.ports, portMoveableAreas: element.portMoveableAreas, portSlideRailSVGClassName: element.portSlideRailSVGClassName, portDirection: element.portDirection, onPortMoved: handlePortMoved, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp,
8735
8752
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
8736
- onMouseUpAtLinkedPortPlaceholder: function (elementLink, position) { return handleMouseUpAtLinkedPortPlaceholder(elementLink, position, element); }, onTextUpdated: function (textId, newContent) { return handleElementTextChange(element, textId, newContent); } }, element.childrenElements && element.childrenElements.map(renderElementInTree))));
8753
+ onMouseUpAtLinkedPortPlaceholder: function (elementLink, position) { return handleMouseUpAtLinkedPortPlaceholder(elementLink, position, element); }, onTextUpdated: function (textId, newContent) { return handleElementTextChange(element, textId, newContent); }, textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition }, element.childrenElements && element.childrenElements.map(renderElementInTree))));
8737
8754
  };
8738
8755
  return (React.createElement("div", { style: { position: "relative" } },
8739
8756
  React.createElement(Ruler, { squareSize: 100, border: '1px dashed grey' }),