orcasvn-react-diagrams 0.1.11 → 0.1.12

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 +70 -11
  2. package/dist/cjs/types/contexts/paperEventEmitterContext.d.ts +5 -1
  3. package/dist/cjs/types/mocks/port1.d.ts +1 -1
  4. package/dist/cjs/types/mocks/portIn.d.ts +1 -1
  5. package/dist/cjs/types/models/IElement.d.ts +1 -0
  6. package/dist/cjs/types/models/IElementProps.d.ts +1 -0
  7. package/dist/cjs/types/models/IPort.d.ts +1 -1
  8. package/dist/cjs/types/models/callbackTypes.d.ts +2 -0
  9. package/dist/cjs/types/models/implementations/CustomPortFromJSXElement.d.ts +1 -1
  10. package/dist/cjs/types/models/implementations/CustomPortFromShape.d.ts +1 -1
  11. package/dist/cjs/types/models/implementations/Element.d.ts +1 -0
  12. package/dist/cjs/types/models/implementations/Port.d.ts +2 -2
  13. package/dist/cjs/types/models/implementations/rectangularFrameElement.d.ts +1 -0
  14. package/dist/cjs/types/utils/constants.d.ts +3 -0
  15. package/dist/esm/index.js +70 -11
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/types/contexts/paperEventEmitterContext.d.ts +5 -1
  18. package/dist/esm/types/mocks/port1.d.ts +1 -1
  19. package/dist/esm/types/mocks/portIn.d.ts +1 -1
  20. package/dist/esm/types/models/IElement.d.ts +1 -0
  21. package/dist/esm/types/models/IElementProps.d.ts +1 -0
  22. package/dist/esm/types/models/IPort.d.ts +1 -1
  23. package/dist/esm/types/models/callbackTypes.d.ts +2 -0
  24. package/dist/esm/types/models/implementations/CustomPortFromJSXElement.d.ts +1 -1
  25. package/dist/esm/types/models/implementations/CustomPortFromShape.d.ts +1 -1
  26. package/dist/esm/types/models/implementations/Element.d.ts +1 -0
  27. package/dist/esm/types/models/implementations/Port.d.ts +2 -2
  28. package/dist/esm/types/models/implementations/rectangularFrameElement.d.ts +1 -0
  29. package/dist/esm/types/utils/constants.d.ts +3 -0
  30. package/dist/index.d.ts +12 -7
  31. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -561,10 +561,15 @@ var Element$1 = /** @class */ (function () {
561
561
  }());
562
562
 
563
563
  var Port$1 = /** @class */ (function () {
564
- function Port(x, y, width, height, label, renderShape) {
564
+ function Port(x, y, label, renderShape, width, height) {
565
565
  this._id = generateUniqueId();
566
566
  this.position = { x: x, y: y };
567
- this.size = { width: width, height: height };
567
+ if (!height) {
568
+ height = width;
569
+ }
570
+ if (width && height) {
571
+ this.size = { width: width, height: height };
572
+ }
568
573
  this.label = label;
569
574
  this.renderShape = renderShape;
570
575
  }
@@ -803,10 +808,10 @@ var CustomShape = React$1.forwardRef(function (props, ref) {
803
808
 
804
809
  var CustomPortFromJSXElement = /** @class */ (function (_super) {
805
810
  __extends(CustomPortFromJSXElement, _super);
806
- function CustomPortFromJSXElement(x, y, width, height, renderCustomShape, label, shapePositioningAnchor) {
807
- var _this = _super.call(this, x, y, width, height, label, React$1.forwardRef(function (props, ref) {
811
+ function CustomPortFromJSXElement(x, y, renderCustomShape, label, shapePositioningAnchor, width, height) {
812
+ var _this = _super.call(this, x, y, label, React$1.forwardRef(function (props, ref) {
808
813
  return (React$1.createElement(CustomShape, { ref: ref, x: props.x, y: props.y, width: props.width, height: props.height, rotation: props.rotation, positioningAnchor: shapePositioningAnchor, onClick: function (e) { var _a; return (_a = props.onSelected) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseDown: function (e) { var _a; return (_a = props.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseUp: function (e) { var _a; return (_a = props.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); } }, renderCustomShape));
809
- })) || this;
814
+ }), width, height) || this;
810
815
  return _this;
811
816
  }
812
817
  return CustomPortFromJSXElement;
@@ -814,8 +819,8 @@ var CustomPortFromJSXElement = /** @class */ (function (_super) {
814
819
 
815
820
  var CustomPortFromShape = /** @class */ (function (_super) {
816
821
  __extends(CustomPortFromShape, _super);
817
- function CustomPortFromShape(x, y, width, height, shape, label) {
818
- return _super.call(this, x, y, width, height, label, shape) || this;
822
+ function CustomPortFromShape(x, y, shape, label, width, height) {
823
+ return _super.call(this, x, y, label, shape, width, height) || this;
819
824
  }
820
825
  return CustomPortFromShape;
821
826
  }(Port$1));
@@ -935,10 +940,12 @@ var EVENT_NAME = {
935
940
  ELEMENT_DRAGGED: 'element_dragged',
936
941
  ELEMENT_RESIZED: 'element_resized',
937
942
  ELEMENT_DELETED: 'element_deleted',
943
+ ELEMENT_SELECTED: 'element_selected',
938
944
  //PORT
939
945
  PORT_MOUSE_DOWN: 'port_mouse_down',
940
946
  PORT_MOUSE_UP: 'port_mouse_up',
941
947
  PORT_MOVED: 'port_moved',
948
+ PORT_SELECTED: 'port_selected',
942
949
  //COMMAND
943
950
  COMMAND_DELETE_SELECTED_PORT: 'command_delete_selected_port',
944
951
  COMMAND_DELETE_SELECTED_LINK: 'command_delete_selected_link',
@@ -969,7 +976,8 @@ var TEXT_MOVING_OFFSET_THRESHOLD = 10;
969
976
  var PORT_PLACEHOLDER_DEFAULT_SIZE = 8;
970
977
  var PORT_PLACEHOLDER_DEFAULT_STROKE = 'green';
971
978
  var PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH = 20;
972
- var PORT_MOVING_OFFSET_THRESHOLD = 15;
979
+ var PORT_MOVING_OFFSET_THRESHOLD = 15;
980
+ var PORT_DEFAULT_SIZE = 20;
973
981
 
974
982
  var SelectionFrame = function (props) {
975
983
  var _a;
@@ -1272,6 +1280,30 @@ var onElementLinkEnded = function (callback) {
1272
1280
  off: off
1273
1281
  };
1274
1282
  };
1283
+ var emitElementSelected = function (element) {
1284
+ eventEmitter.emit(EVENT_NAME.ELEMENT_SELECTED, element);
1285
+ };
1286
+ var onElementSelected = function (callback) {
1287
+ eventEmitter.on(EVENT_NAME.ELEMENT_SELECTED, callback);
1288
+ var off = function () {
1289
+ eventEmitter.off(EVENT_NAME.ELEMENT_SELECTED, callback);
1290
+ };
1291
+ return {
1292
+ off: off
1293
+ };
1294
+ };
1295
+ var emitPortSelected = function (port, elementId) {
1296
+ eventEmitter.emit(EVENT_NAME.PORT_SELECTED, port, elementId);
1297
+ };
1298
+ var onPortSelected = function (callback) {
1299
+ eventEmitter.on(EVENT_NAME.PORT_SELECTED, callback);
1300
+ var off = function () {
1301
+ eventEmitter.off(EVENT_NAME.PORT_SELECTED, callback);
1302
+ };
1303
+ return {
1304
+ off: off
1305
+ };
1306
+ };
1275
1307
  var paperEventEmitterContext = React$1.createContext({
1276
1308
  emitter: eventEmitter,
1277
1309
  emitPaperClicked: emitPaperClicked,
@@ -1282,10 +1314,14 @@ var paperEventEmitterContext = React$1.createContext({
1282
1314
  onPortMouseDown: onPortMouseDown,
1283
1315
  emitPortMoved: emitPortMoved,
1284
1316
  onPortMoved: onPortMoved,
1317
+ emitPortSelected: emitPortSelected,
1318
+ onPortSelected: onPortSelected,
1285
1319
  emitElementMoved: emitElementMoved,
1286
1320
  onElementMoved: onElementMoved,
1287
1321
  emitElementResized: emitElementResized,
1288
1322
  onElementResized: onElementResized,
1323
+ emitElementSelected: emitElementSelected,
1324
+ onElementSelected: onElementSelected,
1289
1325
  emitCommandDeleteSelectedPort: emitCommandDeleteSelectedPort,
1290
1326
  onCommandDeleteSelectedPort: onCommandDeleteSelectedPort,
1291
1327
  emitCommandDeleteSelectedElement: emitCommandDeleteSelectedElement,
@@ -8885,7 +8921,7 @@ var Flexbox$1 = /*@__PURE__*/getDefaultExportFromCjs(bundleExports);
8885
8921
 
8886
8922
  var Element = function (props) {
8887
8923
  var _a, _b;
8888
- 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;
8924
+ var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container, textsPlaceHolderFlexStyle = props.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition = props.textsPlaceHolderFlexboxPosition, textsPlaceHolderClassName = props.textsPlaceHolderClassName, texts = props.texts, portSlideRailSVGClassName = props.portSlideRailSVGClassName, portMoveableAreas = props.portMoveableAreas, portDirection = props.portDirection, defaultPortSize = props.defaultPortSize, onClick = props.onClick, 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;
8889
8925
  var _c = React$1.useState(), selectedPort = _c[0], setSelectedPort = _c[1];
8890
8926
  var _d = React$1.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
8891
8927
  return __assign(__assign({}, p), { id: p.id, ref: React$1.createRef() });
@@ -8952,9 +8988,30 @@ var Element = function (props) {
8952
8988
  elementEndedListener.off();
8953
8989
  };
8954
8990
  }, []);
8991
+ //Listen another port is selected
8992
+ React$1.useEffect(function () {
8993
+ var portSelectedListener = _paperEventEmitterContext.onPortSelected(function (port, elementId) {
8994
+ if (elementId !== id) {
8995
+ setSelectedPort(undefined);
8996
+ }
8997
+ });
8998
+ return function () {
8999
+ portSelectedListener.off();
9000
+ };
9001
+ }, []);
9002
+ //Listen another element is selected
9003
+ React$1.useEffect(function () {
9004
+ var portSelectedListener = _paperEventEmitterContext.onElementSelected(function (element) {
9005
+ setSelectedPort(undefined);
9006
+ });
9007
+ return function () {
9008
+ portSelectedListener.off();
9009
+ };
9010
+ }, []);
8955
9011
  var handleSelectedPort = function (port, e) {
8956
9012
  e.stopPropagation();
8957
9013
  setSelectedPort(port);
9014
+ _paperEventEmitterContext.emitPortSelected(port, id);
8958
9015
  };
8959
9016
  //From one point find another point on the line segment so that the distance between the two points is the shortest.
8960
9017
  var findNearestPointOnSegment = function (position, linePoints) {
@@ -9252,7 +9309,8 @@ var Element = function (props) {
9252
9309
  ? React$1.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
9253
9310
  : React$1.createElement("rect", { x: potentialPortPosition.x - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, y: potentialPortPosition.y - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, width: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, height: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, rx: PORT_PLACEHOLDER_DEFAULT_SIZE, ry: PORT_PLACEHOLDER_DEFAULT_SIZE, stroke: PORT_PLACEHOLDER_DEFAULT_STROKE, fill: "none", strokeWidth: 3 })), ports === null || ports === void 0 ? void 0 :
9254
9311
  ports.map(function (p, index) {
9255
- return React$1.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,
9312
+ var _a, _b, _c, _d, _e, _f;
9313
+ return React$1.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: (_c = (_b = (_a = p.size) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : defaultPortSize) !== null && _c !== void 0 ? _c : PORT_DEFAULT_SIZE, height: (_f = (_e = (_d = p.size) === null || _d === void 0 ? void 0 : _d.height) !== null && _e !== void 0 ? _e : defaultPortSize) !== null && _f !== void 0 ? _f : PORT_DEFAULT_SIZE, container: container,
9256
9314
  // rotation={rotatePort(p)}
9257
9315
  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 });
9258
9316
  }),
@@ -9984,7 +10042,8 @@ var Paper = function (props) {
9984
10042
  setSelectedElementSVG(ref);
9985
10043
  setSelectedElement(element);
9986
10044
  setMouseDownedOnPaper(false);
9987
- }, 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,
10045
+ paperEventEmitter.emitElementSelected(element);
10046
+ }, container: paperContainerRef.current, renderShape: element.renderShape, cssClass: element.cssClass, texts: element.texts, ports: element.ports, portMoveableAreas: element.portMoveableAreas, portSlideRailSVGClassName: element.portSlideRailSVGClassName, portDirection: element.portDirection, defaultPortSize: element.defaultPortSize, onPortMoved: handlePortMoved, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp,
9988
10047
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
9989
10048
  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))));
9990
10049
  };
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import EventEmitter from "eventemitter3";
3
- import { onCommandDeleteSelectedHandler, OnElementLinkEnded, OnElementLinkStarted, onElementMovedHandler, onElementResizedHandler, onPortMouseDownHandler, onPortMouseUpHandler, onPortMovedHandler } from "../models/callbackTypes";
3
+ import { onCommandDeleteSelectedHandler, OnElementLinkEnded, OnElementLinkStarted, onElementMovedHandler, onElementResizedHandler, OnElementSelected, onPortMouseDownHandler, onPortMouseUpHandler, onPortMovedHandler, OnPortSelected } from "../models/callbackTypes";
4
4
  interface IEventListenerReturn {
5
5
  off: () => void;
6
6
  }
@@ -14,10 +14,14 @@ interface IPaperEventContext {
14
14
  onPortMouseDown: (callback: onPortMouseDownHandler) => IEventListenerReturn;
15
15
  emitPortMoved: onPortMovedHandler;
16
16
  onPortMoved: (callback: onPortMovedHandler) => IEventListenerReturn;
17
+ emitPortSelected: OnPortSelected;
18
+ onPortSelected: (callback: OnPortSelected) => IEventListenerReturn;
17
19
  emitElementMoved: onElementMovedHandler;
18
20
  onElementMoved: (elementId: string, callback: onElementMovedHandler) => IEventListenerReturn;
19
21
  emitElementResized: onElementResizedHandler;
20
22
  onElementResized: (elementId: string, callback: onElementResizedHandler) => IEventListenerReturn;
23
+ emitElementSelected: OnElementSelected;
24
+ onElementSelected: (callback: OnElementSelected) => IEventListenerReturn;
21
25
  emitCommandDeleteSelectedPort: onCommandDeleteSelectedHandler;
22
26
  onCommandDeleteSelectedPort: (callback: onCommandDeleteSelectedHandler) => IEventListenerReturn;
23
27
  emitCommandDeleteSelectedElement: onCommandDeleteSelectedHandler;
@@ -1,5 +1,5 @@
1
1
  import IText from "../models/IText";
2
2
  import { CustomPortFromShape } from '../models/implementations/CustomPortFromShape';
3
3
  export declare class CustomPort1 extends CustomPortFromShape {
4
- constructor(x: number, y: number, width: number, height: number, label?: IText);
4
+ constructor(x: number, y: number, label?: IText, width?: number, height?: number);
5
5
  }
@@ -1,4 +1,4 @@
1
1
  import { CustomPortFromJSXElement } from "../models/implementations/CustomPortFromJSXElement";
2
2
  export default class PortIn extends CustomPortFromJSXElement {
3
- constructor(x: number, y: number, width: number, height: number);
3
+ constructor(x: number, y: number, width?: number, height?: number);
4
4
  }
@@ -23,6 +23,7 @@ export default interface IElement {
23
23
  portMoveableAreas?: IPosition[][];
24
24
  portSlideRailSVGClassName?: string;
25
25
  portDirection?: SubObjectDirection;
26
+ defaultPortSize?: number;
26
27
  parentElement?: IElement;
27
28
  onParentChanged?: (callback: (oldParent?: IElement, newParent?: IElement) => void) => (() => void);
28
29
  addPort: (newPort: IPort) => void;
@@ -20,6 +20,7 @@ interface IElementProps {
20
20
  portMoveableAreas?: IPosition[][];
21
21
  portSlideRailSVGClassName?: string;
22
22
  portDirection?: SubObjectDirection;
23
+ defaultPortSize?: number;
23
24
  onClick?: (elementId: string, e: React.MouseEvent<SVGElement>, ref: SVGSVGElement | null) => void;
24
25
  container: Element;
25
26
  onResized?: onElementResizedHandler;
@@ -6,7 +6,7 @@ import ISize from "./size";
6
6
  export default interface IPort {
7
7
  readonly id: string;
8
8
  position: IPosition;
9
- size: ISize;
9
+ size?: ISize;
10
10
  label?: IText;
11
11
  renderShape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>;
12
12
  }
@@ -9,6 +9,8 @@ export type onPortMouseDownHandler = (ev: React.MouseEvent<SVGElement>, port: IP
9
9
  export type onPortMouseUpHandler = (ev: React.MouseEvent<SVGElement>, port: IPort, elementId: string) => void;
10
10
  export type onElementMovedHandler = (element: IElement, oldPosition: IPosition, newPosition: IPosition) => void;
11
11
  export type onElementResizedHandler = (element: IElement, oldSize: ISize, newSize: ISize) => void;
12
+ export type OnElementSelected = (element: IElement) => void;
12
13
  export type onCommandDeleteSelectedHandler = () => void;
13
14
  export type OnElementLinkStarted = (elementLink: IElementLink) => void;
14
15
  export type OnElementLinkEnded = (elementLink?: IElementLink) => void;
16
+ export type OnPortSelected = (port: IPort, elementId: string) => void;
@@ -3,5 +3,5 @@ import Port from "./Port";
3
3
  import IText from "../IText";
4
4
  import IPosition from "../position";
5
5
  export declare class CustomPortFromJSXElement extends Port {
6
- constructor(x: number, y: number, width: number, height: number, renderCustomShape: JSX.Element, label?: IText, shapePositioningAnchor?: IPosition);
6
+ constructor(x: number, y: number, renderCustomShape: JSX.Element, label?: IText, shapePositioningAnchor?: IPosition, width?: number, height?: number);
7
7
  }
@@ -3,5 +3,5 @@ import Port from "./Port";
3
3
  import IText from "../IText";
4
4
  import { IPortProps } from "../IPortProps";
5
5
  export declare class CustomPortFromShape extends Port {
6
- constructor(x: number, y: number, width: number, height: number, shape: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>, label?: IText);
6
+ constructor(x: number, y: number, shape: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>, label?: IText, width?: number, height?: number);
7
7
  }
@@ -26,6 +26,7 @@ export default class Element implements IElement {
26
26
  portMoveableAreas?: IPosition[][];
27
27
  portSlideRailSVGClassName?: string;
28
28
  portDirection?: SubObjectDirection;
29
+ defaultPortSize?: number;
29
30
  onResized?: ((width: number, height: number) => void) | undefined;
30
31
  onMoved?: ((x: number, y: number) => void) | undefined;
31
32
  textsPlaceHolderClassName?: string;
@@ -7,9 +7,9 @@ import ISize from "../size";
7
7
  export default class Port implements IPort {
8
8
  private readonly _id;
9
9
  position: IPosition;
10
- size: ISize;
10
+ size?: ISize;
11
11
  label?: IText;
12
12
  renderShape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>;
13
- constructor(x: number, y: number, width: number, height: number, label?: IText, renderShape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>);
13
+ constructor(x: number, y: number, label?: IText, renderShape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>, width?: number, height?: number);
14
14
  get id(): string;
15
15
  }
@@ -6,5 +6,6 @@ import IFlexboxType from '../IFlexboxType';
6
6
  import IPosition from '../position';
7
7
  export default class RectangularFrameElement extends Element {
8
8
  resizability: IResizability;
9
+ defaultPortSize?: number | undefined;
9
10
  constructor(x: number, y: number, width: number, height: number, cssClass?: string, texts?: IText[], ports?: IPort[], textsPlaceHolderClassName?: string, textsPlaceHolderFlexStyle?: IFlexboxType, textsPlaceHolderFlexboxPosition?: IPosition);
10
11
  }
@@ -6,9 +6,11 @@ export declare const EVENT_NAME: {
6
6
  ELEMENT_DRAGGED: string;
7
7
  ELEMENT_RESIZED: string;
8
8
  ELEMENT_DELETED: string;
9
+ ELEMENT_SELECTED: string;
9
10
  PORT_MOUSE_DOWN: string;
10
11
  PORT_MOUSE_UP: string;
11
12
  PORT_MOVED: string;
13
+ PORT_SELECTED: string;
12
14
  COMMAND_DELETE_SELECTED_PORT: string;
13
15
  COMMAND_DELETE_SELECTED_LINK: string;
14
16
  COMMAND_DELETE_SELECTED_ELEMENT: string;
@@ -45,3 +47,4 @@ export declare const PORT_PLACEHOLDER_DEFAULT_SIZE = 8;
45
47
  export declare const PORT_PLACEHOLDER_DEFAULT_STROKE = "green";
46
48
  export declare const PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH = 20;
47
49
  export declare const PORT_MOVING_OFFSET_THRESHOLD = 15;
50
+ export declare const PORT_DEFAULT_SIZE = 20;
package/dist/esm/index.js CHANGED
@@ -557,10 +557,15 @@ var Element$1 = /** @class */ (function () {
557
557
  }());
558
558
 
559
559
  var Port$1 = /** @class */ (function () {
560
- function Port(x, y, width, height, label, renderShape) {
560
+ function Port(x, y, label, renderShape, width, height) {
561
561
  this._id = generateUniqueId();
562
562
  this.position = { x: x, y: y };
563
- this.size = { width: width, height: height };
563
+ if (!height) {
564
+ height = width;
565
+ }
566
+ if (width && height) {
567
+ this.size = { width: width, height: height };
568
+ }
564
569
  this.label = label;
565
570
  this.renderShape = renderShape;
566
571
  }
@@ -799,10 +804,10 @@ var CustomShape = forwardRef(function (props, ref) {
799
804
 
800
805
  var CustomPortFromJSXElement = /** @class */ (function (_super) {
801
806
  __extends(CustomPortFromJSXElement, _super);
802
- function CustomPortFromJSXElement(x, y, width, height, renderCustomShape, label, shapePositioningAnchor) {
803
- var _this = _super.call(this, x, y, width, height, label, forwardRef(function (props, ref) {
807
+ function CustomPortFromJSXElement(x, y, renderCustomShape, label, shapePositioningAnchor, width, height) {
808
+ var _this = _super.call(this, x, y, label, forwardRef(function (props, ref) {
804
809
  return (React$1.createElement(CustomShape, { ref: ref, x: props.x, y: props.y, width: props.width, height: props.height, rotation: props.rotation, positioningAnchor: shapePositioningAnchor, onClick: function (e) { var _a; return (_a = props.onSelected) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseDown: function (e) { var _a; return (_a = props.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseUp: function (e) { var _a; return (_a = props.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); } }, renderCustomShape));
805
- })) || this;
810
+ }), width, height) || this;
806
811
  return _this;
807
812
  }
808
813
  return CustomPortFromJSXElement;
@@ -810,8 +815,8 @@ var CustomPortFromJSXElement = /** @class */ (function (_super) {
810
815
 
811
816
  var CustomPortFromShape = /** @class */ (function (_super) {
812
817
  __extends(CustomPortFromShape, _super);
813
- function CustomPortFromShape(x, y, width, height, shape, label) {
814
- return _super.call(this, x, y, width, height, label, shape) || this;
818
+ function CustomPortFromShape(x, y, shape, label, width, height) {
819
+ return _super.call(this, x, y, label, shape, width, height) || this;
815
820
  }
816
821
  return CustomPortFromShape;
817
822
  }(Port$1));
@@ -931,10 +936,12 @@ var EVENT_NAME = {
931
936
  ELEMENT_DRAGGED: 'element_dragged',
932
937
  ELEMENT_RESIZED: 'element_resized',
933
938
  ELEMENT_DELETED: 'element_deleted',
939
+ ELEMENT_SELECTED: 'element_selected',
934
940
  //PORT
935
941
  PORT_MOUSE_DOWN: 'port_mouse_down',
936
942
  PORT_MOUSE_UP: 'port_mouse_up',
937
943
  PORT_MOVED: 'port_moved',
944
+ PORT_SELECTED: 'port_selected',
938
945
  //COMMAND
939
946
  COMMAND_DELETE_SELECTED_PORT: 'command_delete_selected_port',
940
947
  COMMAND_DELETE_SELECTED_LINK: 'command_delete_selected_link',
@@ -965,7 +972,8 @@ var TEXT_MOVING_OFFSET_THRESHOLD = 10;
965
972
  var PORT_PLACEHOLDER_DEFAULT_SIZE = 8;
966
973
  var PORT_PLACEHOLDER_DEFAULT_STROKE = 'green';
967
974
  var PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH = 20;
968
- var PORT_MOVING_OFFSET_THRESHOLD = 15;
975
+ var PORT_MOVING_OFFSET_THRESHOLD = 15;
976
+ var PORT_DEFAULT_SIZE = 20;
969
977
 
970
978
  var SelectionFrame = function (props) {
971
979
  var _a;
@@ -1268,6 +1276,30 @@ var onElementLinkEnded = function (callback) {
1268
1276
  off: off
1269
1277
  };
1270
1278
  };
1279
+ var emitElementSelected = function (element) {
1280
+ eventEmitter.emit(EVENT_NAME.ELEMENT_SELECTED, element);
1281
+ };
1282
+ var onElementSelected = function (callback) {
1283
+ eventEmitter.on(EVENT_NAME.ELEMENT_SELECTED, callback);
1284
+ var off = function () {
1285
+ eventEmitter.off(EVENT_NAME.ELEMENT_SELECTED, callback);
1286
+ };
1287
+ return {
1288
+ off: off
1289
+ };
1290
+ };
1291
+ var emitPortSelected = function (port, elementId) {
1292
+ eventEmitter.emit(EVENT_NAME.PORT_SELECTED, port, elementId);
1293
+ };
1294
+ var onPortSelected = function (callback) {
1295
+ eventEmitter.on(EVENT_NAME.PORT_SELECTED, callback);
1296
+ var off = function () {
1297
+ eventEmitter.off(EVENT_NAME.PORT_SELECTED, callback);
1298
+ };
1299
+ return {
1300
+ off: off
1301
+ };
1302
+ };
1271
1303
  var paperEventEmitterContext = createContext({
1272
1304
  emitter: eventEmitter,
1273
1305
  emitPaperClicked: emitPaperClicked,
@@ -1278,10 +1310,14 @@ var paperEventEmitterContext = createContext({
1278
1310
  onPortMouseDown: onPortMouseDown,
1279
1311
  emitPortMoved: emitPortMoved,
1280
1312
  onPortMoved: onPortMoved,
1313
+ emitPortSelected: emitPortSelected,
1314
+ onPortSelected: onPortSelected,
1281
1315
  emitElementMoved: emitElementMoved,
1282
1316
  onElementMoved: onElementMoved,
1283
1317
  emitElementResized: emitElementResized,
1284
1318
  onElementResized: onElementResized,
1319
+ emitElementSelected: emitElementSelected,
1320
+ onElementSelected: onElementSelected,
1285
1321
  emitCommandDeleteSelectedPort: emitCommandDeleteSelectedPort,
1286
1322
  onCommandDeleteSelectedPort: onCommandDeleteSelectedPort,
1287
1323
  emitCommandDeleteSelectedElement: emitCommandDeleteSelectedElement,
@@ -8881,7 +8917,7 @@ var Flexbox$1 = /*@__PURE__*/getDefaultExportFromCjs(bundleExports);
8881
8917
 
8882
8918
  var Element = function (props) {
8883
8919
  var _a, _b;
8884
- 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;
8920
+ var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container, textsPlaceHolderFlexStyle = props.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition = props.textsPlaceHolderFlexboxPosition, textsPlaceHolderClassName = props.textsPlaceHolderClassName, texts = props.texts, portSlideRailSVGClassName = props.portSlideRailSVGClassName, portMoveableAreas = props.portMoveableAreas, portDirection = props.portDirection, defaultPortSize = props.defaultPortSize, onClick = props.onClick, 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;
8885
8921
  var _c = useState(), selectedPort = _c[0], setSelectedPort = _c[1];
8886
8922
  var _d = useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
8887
8923
  return __assign(__assign({}, p), { id: p.id, ref: React$1.createRef() });
@@ -8948,9 +8984,30 @@ var Element = function (props) {
8948
8984
  elementEndedListener.off();
8949
8985
  };
8950
8986
  }, []);
8987
+ //Listen another port is selected
8988
+ useEffect(function () {
8989
+ var portSelectedListener = _paperEventEmitterContext.onPortSelected(function (port, elementId) {
8990
+ if (elementId !== id) {
8991
+ setSelectedPort(undefined);
8992
+ }
8993
+ });
8994
+ return function () {
8995
+ portSelectedListener.off();
8996
+ };
8997
+ }, []);
8998
+ //Listen another element is selected
8999
+ useEffect(function () {
9000
+ var portSelectedListener = _paperEventEmitterContext.onElementSelected(function (element) {
9001
+ setSelectedPort(undefined);
9002
+ });
9003
+ return function () {
9004
+ portSelectedListener.off();
9005
+ };
9006
+ }, []);
8951
9007
  var handleSelectedPort = function (port, e) {
8952
9008
  e.stopPropagation();
8953
9009
  setSelectedPort(port);
9010
+ _paperEventEmitterContext.emitPortSelected(port, id);
8954
9011
  };
8955
9012
  //From one point find another point on the line segment so that the distance between the two points is the shortest.
8956
9013
  var findNearestPointOnSegment = function (position, linePoints) {
@@ -9248,7 +9305,8 @@ var Element = function (props) {
9248
9305
  ? React$1.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
9249
9306
  : React$1.createElement("rect", { x: potentialPortPosition.x - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, y: potentialPortPosition.y - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, width: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, height: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, rx: PORT_PLACEHOLDER_DEFAULT_SIZE, ry: PORT_PLACEHOLDER_DEFAULT_SIZE, stroke: PORT_PLACEHOLDER_DEFAULT_STROKE, fill: "none", strokeWidth: 3 })), ports === null || ports === void 0 ? void 0 :
9250
9307
  ports.map(function (p, index) {
9251
- return React$1.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,
9308
+ var _a, _b, _c, _d, _e, _f;
9309
+ return React$1.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: (_c = (_b = (_a = p.size) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : defaultPortSize) !== null && _c !== void 0 ? _c : PORT_DEFAULT_SIZE, height: (_f = (_e = (_d = p.size) === null || _d === void 0 ? void 0 : _d.height) !== null && _e !== void 0 ? _e : defaultPortSize) !== null && _f !== void 0 ? _f : PORT_DEFAULT_SIZE, container: container,
9252
9310
  // rotation={rotatePort(p)}
9253
9311
  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 });
9254
9312
  }),
@@ -9980,7 +10038,8 @@ var Paper = function (props) {
9980
10038
  setSelectedElementSVG(ref);
9981
10039
  setSelectedElement(element);
9982
10040
  setMouseDownedOnPaper(false);
9983
- }, 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,
10041
+ paperEventEmitter.emitElementSelected(element);
10042
+ }, container: paperContainerRef.current, renderShape: element.renderShape, cssClass: element.cssClass, texts: element.texts, ports: element.ports, portMoveableAreas: element.portMoveableAreas, portSlideRailSVGClassName: element.portSlideRailSVGClassName, portDirection: element.portDirection, defaultPortSize: element.defaultPortSize, onPortMoved: handlePortMoved, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp,
9984
10043
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
9985
10044
  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))));
9986
10045
  };