orcasvn-react-diagrams 0.1.8 → 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.
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, parentElement) {
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,
@@ -460,6 +461,9 @@ var Element$1 = /** @class */ (function () {
460
461
  this.portSlideRailSVGClassName = portSlideRailSVGClassName;
461
462
  this.portDirection = portDirection;
462
463
  this.parentElement = parentElement;
464
+ this.textsPlaceHolderClassName = textsPlaceHolderClassName;
465
+ this.textsPlaceHolderFlexStyle = textsPlaceHolderFlexStyle;
466
+ this.textsPlaceHolderFlexboxPosition = textsPlaceHolderFlexboxPosition;
463
467
  }
464
468
  Object.defineProperty(Element.prototype, "id", {
465
469
  get: function () {
@@ -612,13 +616,14 @@ var ElementLink$1 = /** @class */ (function () {
612
616
  }());
613
617
 
614
618
  var Text$2 = /** @class */ (function () {
615
- function Text(content, width, height, x, y, align, fontSize, border) {
619
+ function Text(content, width, height, x, y, align, fontSize, border, style) {
616
620
  this._id = generateUniqueId();
617
621
  this.content = content;
618
622
  this.align = align;
619
623
  this.fontSize = fontSize;
620
624
  this.border = border;
621
625
  this.size = { width: width, height: height };
626
+ this.style = style;
622
627
  if (x && y) {
623
628
  this.position = { x: x, y: y };
624
629
  }
@@ -838,7 +843,7 @@ var Crescent = function (props) {
838
843
  }
839
844
  var sw = props.stroke ? (props.strokeWidth || 1) : 0;
840
845
  return (React.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height }),
841
- 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 })));
842
847
  };
843
848
 
844
849
  var Rectangle = function (props) {
@@ -1396,9 +1401,14 @@ var Text = React.forwardRef(function (_a, ref) {
1396
1401
  });
1397
1402
  var Text$1 = React.memo(Text);
1398
1403
 
1399
- var Port = React.forwardRef(function (props, ref) {
1400
- 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;
1401
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]);
1402
1412
  var renderLabel = function (label) {
1403
1413
  var content = label.content, size = label.size;
1404
1414
  var position = label.position || PORT_LABEL_POSITION;
@@ -1407,7 +1417,7 @@ var Port = React.forwardRef(function (props, ref) {
1407
1417
  var renderedShape = React.useMemo(function () {
1408
1418
  if (renderShape) {
1409
1419
  var RenderShape = renderShape;
1410
- return (React.createElement(RenderShape, __assign({ ref: ref }, props)));
1420
+ return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1411
1421
  }
1412
1422
  else {
1413
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" });
@@ -1416,7 +1426,8 @@ var Port = React.forwardRef(function (props, ref) {
1416
1426
  return (React.createElement(React.Fragment, null,
1417
1427
  renderedShape,
1418
1428
  label && renderLabel(label)));
1419
- });
1429
+ });
1430
+ var Port = React.memo(Port1);
1420
1431
 
1421
1432
  // Render the svg <path> element
1422
1433
  function getCurvePathData(points, smoothing, closed) {
@@ -7642,7 +7653,7 @@ var checkPositionOnLine = function (position, line) {
7642
7653
 
7643
7654
  var Element = function (props) {
7644
7655
  var _a, _b, _c;
7645
- 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;
7646
7657
  var _d = React.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
7647
7658
  var _e = React.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
7648
7659
  return __assign(__assign({}, p), { id: p.id, ref: React.createRef() });
@@ -7770,11 +7781,11 @@ var Element = function (props) {
7770
7781
  }
7771
7782
  return coordinates;
7772
7783
  };
7773
- var getSlideRailSVG = function (portSlideRailSVGClassName) {
7784
+ var getSlideRailSVG = React.useCallback(function (portSlideRailSVGClassName) {
7774
7785
  var _a;
7775
7786
  var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
7776
7787
  return slideRailSVG;
7777
- };
7788
+ }, [elementRef.current]);
7778
7789
  var normalizePortPositionOnSlideRailSVG = function (portSlideRailSVGClassName, position) {
7779
7790
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
7780
7791
  if (!slideRailSVG)
@@ -7937,17 +7948,16 @@ var Element = function (props) {
7937
7948
  }
7938
7949
  };
7939
7950
  //Get rotate angle of port by port direction is defined.
7940
- var rotatePort = React.useCallback(function (port) {
7941
- console.info('calculating port rotation', port);
7951
+ var rotatePort = React.useCallback(function (x, y) {
7952
+ console.info('calculating port rotation', x, y);
7942
7953
  if (!portSlideRailSVGClassName)
7943
7954
  return 0;
7944
7955
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
7945
7956
  if (!slideRailSVG)
7946
7957
  return 0;
7947
7958
  var rotationAngle = 0;
7948
- port.id; var position = port.position; port.size;
7949
7959
  //Standardize the port position to be in the correct position
7950
- var normalizedPosition = normalizePortPosition(position);
7960
+ var normalizedPosition = normalizePortPosition({ x: x, y: y });
7951
7961
  switch (portDirection) {
7952
7962
  case exports.SubObjectDirection.Radial:
7953
7963
  var center = {
@@ -7977,7 +7987,7 @@ var Element = function (props) {
7977
7987
  break;
7978
7988
  }
7979
7989
  return rotationAngle;
7980
- }, [portSlideRailSVGClassName, portDirection]);
7990
+ }, [portSlideRailSVGClassName, portDirection, getSlideRailSVG]);
7981
7991
  var renderedShape = React.useMemo(function () {
7982
7992
  if (renderShape)
7983
7993
  return renderShape(props);
@@ -7999,6 +8009,8 @@ var Element = function (props) {
7999
8009
  enabled: false,
8000
8010
  keepRatio: false
8001
8011
  },
8012
+ // width: selectedPort?.size.width,
8013
+ // height: selectedPort?.size.height,
8002
8014
  movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
8003
8015
  onMove: handlePortMove
8004
8016
  });
@@ -8008,12 +8020,14 @@ var Element = function (props) {
8008
8020
  ? React.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
8009
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 :
8010
8022
  ports.map(function (p, index) {
8011
- 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 });
8012
- }), texts === null || texts === void 0 ? void 0 :
8013
- texts.map(function (t, index) {
8014
- var _a, _b;
8015
- 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 });
8016
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
+ })),
8017
8031
  children));
8018
8032
  };
8019
8033
 
@@ -8740,7 +8754,7 @@ var Paper = function (props) {
8740
8754
  setMouseDownedOnPaper(false);
8741
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,
8742
8756
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
8743
- 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))));
8744
8758
  };
8745
8759
  return (React.createElement("div", { style: { position: "relative" } },
8746
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>>>;
@@ -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, parentElement?: Element);
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, parentElement) {
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,
@@ -456,6 +457,9 @@ var Element$1 = /** @class */ (function () {
456
457
  this.portSlideRailSVGClassName = portSlideRailSVGClassName;
457
458
  this.portDirection = portDirection;
458
459
  this.parentElement = parentElement;
460
+ this.textsPlaceHolderClassName = textsPlaceHolderClassName;
461
+ this.textsPlaceHolderFlexStyle = textsPlaceHolderFlexStyle;
462
+ this.textsPlaceHolderFlexboxPosition = textsPlaceHolderFlexboxPosition;
459
463
  }
460
464
  Object.defineProperty(Element.prototype, "id", {
461
465
  get: function () {
@@ -608,13 +612,14 @@ var ElementLink$1 = /** @class */ (function () {
608
612
  }());
609
613
 
610
614
  var Text$2 = /** @class */ (function () {
611
- function Text(content, width, height, x, y, align, fontSize, border) {
615
+ function Text(content, width, height, x, y, align, fontSize, border, style) {
612
616
  this._id = generateUniqueId();
613
617
  this.content = content;
614
618
  this.align = align;
615
619
  this.fontSize = fontSize;
616
620
  this.border = border;
617
621
  this.size = { width: width, height: height };
622
+ this.style = style;
618
623
  if (x && y) {
619
624
  this.position = { x: x, y: y };
620
625
  }
@@ -834,7 +839,7 @@ var Crescent = function (props) {
834
839
  }
835
840
  var sw = props.stroke ? (props.strokeWidth || 1) : 0;
836
841
  return (React.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height }),
837
- 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 })));
838
843
  };
839
844
 
840
845
  var Rectangle = function (props) {
@@ -1392,9 +1397,14 @@ var Text = forwardRef(function (_a, ref) {
1392
1397
  });
1393
1398
  var Text$1 = memo(Text);
1394
1399
 
1395
- var Port = forwardRef(function (props, ref) {
1396
- 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;
1397
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]);
1398
1408
  var renderLabel = function (label) {
1399
1409
  var content = label.content, size = label.size;
1400
1410
  var position = label.position || PORT_LABEL_POSITION;
@@ -1403,7 +1413,7 @@ var Port = forwardRef(function (props, ref) {
1403
1413
  var renderedShape = useMemo(function () {
1404
1414
  if (renderShape) {
1405
1415
  var RenderShape = renderShape;
1406
- return (React.createElement(RenderShape, __assign({ ref: ref }, props)));
1416
+ return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1407
1417
  }
1408
1418
  else {
1409
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" });
@@ -1412,7 +1422,8 @@ var Port = forwardRef(function (props, ref) {
1412
1422
  return (React.createElement(React.Fragment, null,
1413
1423
  renderedShape,
1414
1424
  label && renderLabel(label)));
1415
- });
1425
+ });
1426
+ var Port = memo(Port1);
1416
1427
 
1417
1428
  // Render the svg <path> element
1418
1429
  function getCurvePathData(points, smoothing, closed) {
@@ -7638,7 +7649,7 @@ var checkPositionOnLine = function (position, line) {
7638
7649
 
7639
7650
  var Element = function (props) {
7640
7651
  var _a, _b, _c;
7641
- 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;
7642
7653
  var _d = useState(), selectedPort = _d[0], setSelectedPort = _d[1];
7643
7654
  var _e = useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
7644
7655
  return __assign(__assign({}, p), { id: p.id, ref: React.createRef() });
@@ -7766,11 +7777,11 @@ var Element = function (props) {
7766
7777
  }
7767
7778
  return coordinates;
7768
7779
  };
7769
- var getSlideRailSVG = function (portSlideRailSVGClassName) {
7780
+ var getSlideRailSVG = useCallback(function (portSlideRailSVGClassName) {
7770
7781
  var _a;
7771
7782
  var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
7772
7783
  return slideRailSVG;
7773
- };
7784
+ }, [elementRef.current]);
7774
7785
  var normalizePortPositionOnSlideRailSVG = function (portSlideRailSVGClassName, position) {
7775
7786
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
7776
7787
  if (!slideRailSVG)
@@ -7933,17 +7944,16 @@ var Element = function (props) {
7933
7944
  }
7934
7945
  };
7935
7946
  //Get rotate angle of port by port direction is defined.
7936
- var rotatePort = useCallback(function (port) {
7937
- console.info('calculating port rotation', port);
7947
+ var rotatePort = useCallback(function (x, y) {
7948
+ console.info('calculating port rotation', x, y);
7938
7949
  if (!portSlideRailSVGClassName)
7939
7950
  return 0;
7940
7951
  var slideRailSVG = getSlideRailSVG(portSlideRailSVGClassName);
7941
7952
  if (!slideRailSVG)
7942
7953
  return 0;
7943
7954
  var rotationAngle = 0;
7944
- port.id; var position = port.position; port.size;
7945
7955
  //Standardize the port position to be in the correct position
7946
- var normalizedPosition = normalizePortPosition(position);
7956
+ var normalizedPosition = normalizePortPosition({ x: x, y: y });
7947
7957
  switch (portDirection) {
7948
7958
  case SubObjectDirection.Radial:
7949
7959
  var center = {
@@ -7973,7 +7983,7 @@ var Element = function (props) {
7973
7983
  break;
7974
7984
  }
7975
7985
  return rotationAngle;
7976
- }, [portSlideRailSVGClassName, portDirection]);
7986
+ }, [portSlideRailSVGClassName, portDirection, getSlideRailSVG]);
7977
7987
  var renderedShape = useMemo(function () {
7978
7988
  if (renderShape)
7979
7989
  return renderShape(props);
@@ -7995,6 +8005,8 @@ var Element = function (props) {
7995
8005
  enabled: false,
7996
8006
  keepRatio: false
7997
8007
  },
8008
+ // width: selectedPort?.size.width,
8009
+ // height: selectedPort?.size.height,
7998
8010
  movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
7999
8011
  onMove: handlePortMove
8000
8012
  });
@@ -8004,12 +8016,14 @@ var Element = function (props) {
8004
8016
  ? React.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
8005
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 :
8006
8018
  ports.map(function (p, index) {
8007
- 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 });
8008
- }), texts === null || texts === void 0 ? void 0 :
8009
- texts.map(function (t, index) {
8010
- var _a, _b;
8011
- 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 });
8012
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
+ })),
8013
8027
  children));
8014
8028
  };
8015
8029
 
@@ -8736,7 +8750,7 @@ var Paper = function (props) {
8736
8750
  setMouseDownedOnPaper(false);
8737
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,
8738
8752
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
8739
- 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))));
8740
8754
  };
8741
8755
  return (React.createElement("div", { style: { position: "relative" } },
8742
8756
  React.createElement(Ruler, { squareSize: 100, border: '1px dashed grey' }),