orcasvn-react-diagrams 0.1.10 → 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.
- package/dist/cjs/index.js +77 -9
- package/dist/cjs/types/contexts/paperEventEmitterContext.d.ts +5 -1
- package/dist/cjs/types/mocks/port1.d.ts +1 -1
- package/dist/cjs/types/mocks/portIn.d.ts +1 -1
- package/dist/cjs/types/models/IElement.d.ts +1 -0
- package/dist/cjs/types/models/IElementProps.d.ts +1 -0
- package/dist/cjs/types/models/IPort.d.ts +1 -1
- package/dist/cjs/types/models/callbackTypes.d.ts +2 -0
- package/dist/cjs/types/models/implementations/CustomPortFromJSXElement.d.ts +1 -1
- package/dist/cjs/types/models/implementations/CustomPortFromShape.d.ts +1 -1
- package/dist/cjs/types/models/implementations/Element.d.ts +1 -0
- package/dist/cjs/types/models/implementations/Port.d.ts +2 -2
- package/dist/cjs/types/models/implementations/index.d.ts +1 -0
- package/dist/cjs/types/models/implementations/rectangularFrameElement.d.ts +1 -0
- package/dist/cjs/types/utils/constants.d.ts +3 -0
- package/dist/esm/index.js +77 -10
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/contexts/paperEventEmitterContext.d.ts +5 -1
- package/dist/esm/types/mocks/port1.d.ts +1 -1
- package/dist/esm/types/mocks/portIn.d.ts +1 -1
- package/dist/esm/types/models/IElement.d.ts +1 -0
- package/dist/esm/types/models/IElementProps.d.ts +1 -0
- package/dist/esm/types/models/IPort.d.ts +1 -1
- package/dist/esm/types/models/callbackTypes.d.ts +2 -0
- package/dist/esm/types/models/implementations/CustomPortFromJSXElement.d.ts +1 -1
- package/dist/esm/types/models/implementations/CustomPortFromShape.d.ts +1 -1
- package/dist/esm/types/models/implementations/Element.d.ts +1 -0
- package/dist/esm/types/models/implementations/Port.d.ts +2 -2
- package/dist/esm/types/models/implementations/index.d.ts +1 -0
- package/dist/esm/types/models/implementations/rectangularFrameElement.d.ts +1 -0
- package/dist/esm/types/utils/constants.d.ts +3 -0
- package/dist/index.d.ts +15 -6
- 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,
|
|
564
|
+
function Port(x, y, label, renderShape, width, height) {
|
|
565
565
|
this._id = generateUniqueId();
|
|
566
566
|
this.position = { x: x, y: y };
|
|
567
|
-
|
|
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,15 +808,23 @@ 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,
|
|
807
|
-
var _this = _super.call(this, x, y,
|
|
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;
|
|
813
818
|
}(Port$1));
|
|
814
819
|
|
|
820
|
+
var CustomPortFromShape = /** @class */ (function (_super) {
|
|
821
|
+
__extends(CustomPortFromShape, _super);
|
|
822
|
+
function CustomPortFromShape(x, y, shape, label, width, height) {
|
|
823
|
+
return _super.call(this, x, y, label, shape, width, height) || this;
|
|
824
|
+
}
|
|
825
|
+
return CustomPortFromShape;
|
|
826
|
+
}(Port$1));
|
|
827
|
+
|
|
815
828
|
var Circle = React$1.forwardRef(function (props, ref) {
|
|
816
829
|
var s = { height: 100, width: 100 };
|
|
817
830
|
if (props.r) {
|
|
@@ -927,10 +940,12 @@ var EVENT_NAME = {
|
|
|
927
940
|
ELEMENT_DRAGGED: 'element_dragged',
|
|
928
941
|
ELEMENT_RESIZED: 'element_resized',
|
|
929
942
|
ELEMENT_DELETED: 'element_deleted',
|
|
943
|
+
ELEMENT_SELECTED: 'element_selected',
|
|
930
944
|
//PORT
|
|
931
945
|
PORT_MOUSE_DOWN: 'port_mouse_down',
|
|
932
946
|
PORT_MOUSE_UP: 'port_mouse_up',
|
|
933
947
|
PORT_MOVED: 'port_moved',
|
|
948
|
+
PORT_SELECTED: 'port_selected',
|
|
934
949
|
//COMMAND
|
|
935
950
|
COMMAND_DELETE_SELECTED_PORT: 'command_delete_selected_port',
|
|
936
951
|
COMMAND_DELETE_SELECTED_LINK: 'command_delete_selected_link',
|
|
@@ -961,7 +976,8 @@ var TEXT_MOVING_OFFSET_THRESHOLD = 10;
|
|
|
961
976
|
var PORT_PLACEHOLDER_DEFAULT_SIZE = 8;
|
|
962
977
|
var PORT_PLACEHOLDER_DEFAULT_STROKE = 'green';
|
|
963
978
|
var PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH = 20;
|
|
964
|
-
var PORT_MOVING_OFFSET_THRESHOLD = 15;
|
|
979
|
+
var PORT_MOVING_OFFSET_THRESHOLD = 15;
|
|
980
|
+
var PORT_DEFAULT_SIZE = 20;
|
|
965
981
|
|
|
966
982
|
var SelectionFrame = function (props) {
|
|
967
983
|
var _a;
|
|
@@ -1264,6 +1280,30 @@ var onElementLinkEnded = function (callback) {
|
|
|
1264
1280
|
off: off
|
|
1265
1281
|
};
|
|
1266
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
|
+
};
|
|
1267
1307
|
var paperEventEmitterContext = React$1.createContext({
|
|
1268
1308
|
emitter: eventEmitter,
|
|
1269
1309
|
emitPaperClicked: emitPaperClicked,
|
|
@@ -1274,10 +1314,14 @@ var paperEventEmitterContext = React$1.createContext({
|
|
|
1274
1314
|
onPortMouseDown: onPortMouseDown,
|
|
1275
1315
|
emitPortMoved: emitPortMoved,
|
|
1276
1316
|
onPortMoved: onPortMoved,
|
|
1317
|
+
emitPortSelected: emitPortSelected,
|
|
1318
|
+
onPortSelected: onPortSelected,
|
|
1277
1319
|
emitElementMoved: emitElementMoved,
|
|
1278
1320
|
onElementMoved: onElementMoved,
|
|
1279
1321
|
emitElementResized: emitElementResized,
|
|
1280
1322
|
onElementResized: onElementResized,
|
|
1323
|
+
emitElementSelected: emitElementSelected,
|
|
1324
|
+
onElementSelected: onElementSelected,
|
|
1281
1325
|
emitCommandDeleteSelectedPort: emitCommandDeleteSelectedPort,
|
|
1282
1326
|
onCommandDeleteSelectedPort: onCommandDeleteSelectedPort,
|
|
1283
1327
|
emitCommandDeleteSelectedElement: emitCommandDeleteSelectedElement,
|
|
@@ -8877,7 +8921,7 @@ var Flexbox$1 = /*@__PURE__*/getDefaultExportFromCjs(bundleExports);
|
|
|
8877
8921
|
|
|
8878
8922
|
var Element = function (props) {
|
|
8879
8923
|
var _a, _b;
|
|
8880
|
-
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;
|
|
8881
8925
|
var _c = React$1.useState(), selectedPort = _c[0], setSelectedPort = _c[1];
|
|
8882
8926
|
var _d = React$1.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
|
|
8883
8927
|
return __assign(__assign({}, p), { id: p.id, ref: React$1.createRef() });
|
|
@@ -8944,9 +8988,30 @@ var Element = function (props) {
|
|
|
8944
8988
|
elementEndedListener.off();
|
|
8945
8989
|
};
|
|
8946
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
|
+
}, []);
|
|
8947
9011
|
var handleSelectedPort = function (port, e) {
|
|
8948
9012
|
e.stopPropagation();
|
|
8949
9013
|
setSelectedPort(port);
|
|
9014
|
+
_paperEventEmitterContext.emitPortSelected(port, id);
|
|
8950
9015
|
};
|
|
8951
9016
|
//From one point find another point on the line segment so that the distance between the two points is the shortest.
|
|
8952
9017
|
var findNearestPointOnSegment = function (position, linePoints) {
|
|
@@ -9244,7 +9309,8 @@ var Element = function (props) {
|
|
|
9244
9309
|
? React$1.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
|
|
9245
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 :
|
|
9246
9311
|
ports.map(function (p, index) {
|
|
9247
|
-
|
|
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,
|
|
9248
9314
|
// rotation={rotatePort(p)}
|
|
9249
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 });
|
|
9250
9316
|
}),
|
|
@@ -9976,7 +10042,8 @@ var Paper = function (props) {
|
|
|
9976
10042
|
setSelectedElementSVG(ref);
|
|
9977
10043
|
setSelectedElement(element);
|
|
9978
10044
|
setMouseDownedOnPaper(false);
|
|
9979
|
-
|
|
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,
|
|
9980
10047
|
// portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
|
|
9981
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))));
|
|
9982
10049
|
};
|
|
@@ -10016,6 +10083,7 @@ function Editor(_a) {
|
|
|
10016
10083
|
exports.CircleRC = Circle;
|
|
10017
10084
|
exports.CrescentRC = Crescent;
|
|
10018
10085
|
exports.CustomPortFromJSXElement = CustomPortFromJSXElement;
|
|
10086
|
+
exports.CustomPortFromShape = CustomPortFromShape;
|
|
10019
10087
|
exports.CustomShapeRC = CustomShape;
|
|
10020
10088
|
exports.EditorContext = EditorContext;
|
|
10021
10089
|
exports.Element = Element$1;
|
|
@@ -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,
|
|
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
|
|
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;
|
|
@@ -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,
|
|
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,
|
|
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
|
|
10
|
+
size?: ISize;
|
|
11
11
|
label?: IText;
|
|
12
12
|
renderShape?: React.ForwardRefExoticComponent<IPortProps & React.RefAttributes<SVGSVGElement>>;
|
|
13
|
-
constructor(x: number, y: number,
|
|
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,
|
|
560
|
+
function Port(x, y, label, renderShape, width, height) {
|
|
561
561
|
this._id = generateUniqueId();
|
|
562
562
|
this.position = { x: x, y: y };
|
|
563
|
-
|
|
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,15 +804,23 @@ 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,
|
|
803
|
-
var _this = _super.call(this, x, y,
|
|
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;
|
|
809
814
|
}(Port$1));
|
|
810
815
|
|
|
816
|
+
var CustomPortFromShape = /** @class */ (function (_super) {
|
|
817
|
+
__extends(CustomPortFromShape, _super);
|
|
818
|
+
function CustomPortFromShape(x, y, shape, label, width, height) {
|
|
819
|
+
return _super.call(this, x, y, label, shape, width, height) || this;
|
|
820
|
+
}
|
|
821
|
+
return CustomPortFromShape;
|
|
822
|
+
}(Port$1));
|
|
823
|
+
|
|
811
824
|
var Circle = forwardRef(function (props, ref) {
|
|
812
825
|
var s = { height: 100, width: 100 };
|
|
813
826
|
if (props.r) {
|
|
@@ -923,10 +936,12 @@ var EVENT_NAME = {
|
|
|
923
936
|
ELEMENT_DRAGGED: 'element_dragged',
|
|
924
937
|
ELEMENT_RESIZED: 'element_resized',
|
|
925
938
|
ELEMENT_DELETED: 'element_deleted',
|
|
939
|
+
ELEMENT_SELECTED: 'element_selected',
|
|
926
940
|
//PORT
|
|
927
941
|
PORT_MOUSE_DOWN: 'port_mouse_down',
|
|
928
942
|
PORT_MOUSE_UP: 'port_mouse_up',
|
|
929
943
|
PORT_MOVED: 'port_moved',
|
|
944
|
+
PORT_SELECTED: 'port_selected',
|
|
930
945
|
//COMMAND
|
|
931
946
|
COMMAND_DELETE_SELECTED_PORT: 'command_delete_selected_port',
|
|
932
947
|
COMMAND_DELETE_SELECTED_LINK: 'command_delete_selected_link',
|
|
@@ -957,7 +972,8 @@ var TEXT_MOVING_OFFSET_THRESHOLD = 10;
|
|
|
957
972
|
var PORT_PLACEHOLDER_DEFAULT_SIZE = 8;
|
|
958
973
|
var PORT_PLACEHOLDER_DEFAULT_STROKE = 'green';
|
|
959
974
|
var PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH = 20;
|
|
960
|
-
var PORT_MOVING_OFFSET_THRESHOLD = 15;
|
|
975
|
+
var PORT_MOVING_OFFSET_THRESHOLD = 15;
|
|
976
|
+
var PORT_DEFAULT_SIZE = 20;
|
|
961
977
|
|
|
962
978
|
var SelectionFrame = function (props) {
|
|
963
979
|
var _a;
|
|
@@ -1260,6 +1276,30 @@ var onElementLinkEnded = function (callback) {
|
|
|
1260
1276
|
off: off
|
|
1261
1277
|
};
|
|
1262
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
|
+
};
|
|
1263
1303
|
var paperEventEmitterContext = createContext({
|
|
1264
1304
|
emitter: eventEmitter,
|
|
1265
1305
|
emitPaperClicked: emitPaperClicked,
|
|
@@ -1270,10 +1310,14 @@ var paperEventEmitterContext = createContext({
|
|
|
1270
1310
|
onPortMouseDown: onPortMouseDown,
|
|
1271
1311
|
emitPortMoved: emitPortMoved,
|
|
1272
1312
|
onPortMoved: onPortMoved,
|
|
1313
|
+
emitPortSelected: emitPortSelected,
|
|
1314
|
+
onPortSelected: onPortSelected,
|
|
1273
1315
|
emitElementMoved: emitElementMoved,
|
|
1274
1316
|
onElementMoved: onElementMoved,
|
|
1275
1317
|
emitElementResized: emitElementResized,
|
|
1276
1318
|
onElementResized: onElementResized,
|
|
1319
|
+
emitElementSelected: emitElementSelected,
|
|
1320
|
+
onElementSelected: onElementSelected,
|
|
1277
1321
|
emitCommandDeleteSelectedPort: emitCommandDeleteSelectedPort,
|
|
1278
1322
|
onCommandDeleteSelectedPort: onCommandDeleteSelectedPort,
|
|
1279
1323
|
emitCommandDeleteSelectedElement: emitCommandDeleteSelectedElement,
|
|
@@ -8873,7 +8917,7 @@ var Flexbox$1 = /*@__PURE__*/getDefaultExportFromCjs(bundleExports);
|
|
|
8873
8917
|
|
|
8874
8918
|
var Element = function (props) {
|
|
8875
8919
|
var _a, _b;
|
|
8876
|
-
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;
|
|
8877
8921
|
var _c = useState(), selectedPort = _c[0], setSelectedPort = _c[1];
|
|
8878
8922
|
var _d = useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
|
|
8879
8923
|
return __assign(__assign({}, p), { id: p.id, ref: React$1.createRef() });
|
|
@@ -8940,9 +8984,30 @@ var Element = function (props) {
|
|
|
8940
8984
|
elementEndedListener.off();
|
|
8941
8985
|
};
|
|
8942
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
|
+
}, []);
|
|
8943
9007
|
var handleSelectedPort = function (port, e) {
|
|
8944
9008
|
e.stopPropagation();
|
|
8945
9009
|
setSelectedPort(port);
|
|
9010
|
+
_paperEventEmitterContext.emitPortSelected(port, id);
|
|
8946
9011
|
};
|
|
8947
9012
|
//From one point find another point on the line segment so that the distance between the two points is the shortest.
|
|
8948
9013
|
var findNearestPointOnSegment = function (position, linePoints) {
|
|
@@ -9240,7 +9305,8 @@ var Element = function (props) {
|
|
|
9240
9305
|
? React$1.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
|
|
9241
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 :
|
|
9242
9307
|
ports.map(function (p, index) {
|
|
9243
|
-
|
|
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,
|
|
9244
9310
|
// rotation={rotatePort(p)}
|
|
9245
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 });
|
|
9246
9312
|
}),
|
|
@@ -9972,7 +10038,8 @@ var Paper = function (props) {
|
|
|
9972
10038
|
setSelectedElementSVG(ref);
|
|
9973
10039
|
setSelectedElement(element);
|
|
9974
10040
|
setMouseDownedOnPaper(false);
|
|
9975
|
-
|
|
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,
|
|
9976
10043
|
// portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
|
|
9977
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))));
|
|
9978
10045
|
};
|
|
@@ -10009,5 +10076,5 @@ function Editor(_a) {
|
|
|
10009
10076
|
React$1.createElement(Paper, { size: { width: 3000, height: 3000 }, elements: editorContext.elements, links: editorContext.links, texts: editorContext.texts, onPaperClicked: editorContext.onPaperClicked, onPortMoved: editorContext.onPortMoved, onElementMoved: editorContext.onElementMoved, onElementResized: editorContext.onElementResized, onLinkValidation: editorContext.validateLink, onCreatingLink: editorContext.onCreatingLink, onCreatingPortByLinking: editorContext.onCreatingPortByLinking })));
|
|
10010
10077
|
}
|
|
10011
10078
|
|
|
10012
|
-
export { Circle as CircleRC, Crescent as CrescentRC, CustomPortFromJSXElement, CustomShape as CustomShapeRC, EditorContext, Element$1 as Element, ElementLink$1 as ElementLink, ElementLink as ElementLinkRC, Port$1 as Port, Port as PortRC, PositioningAnchor, Rectangle as RectangleRC, RectangularFrame as RectangularFrameRC, ResizingDirection, ShapeWrapper as ShapeWrapperRC, SubObjectDirection, Text$2 as Text, TextAlign, Text$1 as TextRC, Editor as default };
|
|
10079
|
+
export { Circle as CircleRC, Crescent as CrescentRC, CustomPortFromJSXElement, CustomPortFromShape, CustomShape as CustomShapeRC, EditorContext, Element$1 as Element, ElementLink$1 as ElementLink, ElementLink as ElementLinkRC, Port$1 as Port, Port as PortRC, PositioningAnchor, Rectangle as RectangleRC, RectangularFrame as RectangularFrameRC, ResizingDirection, ShapeWrapper as ShapeWrapperRC, SubObjectDirection, Text$2 as Text, TextAlign, Text$1 as TextRC, Editor as default };
|
|
10013
10080
|
//# sourceMappingURL=index.js.map
|