orcasvn-react-diagrams 0.1.53 → 0.1.54
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 +81 -21
- package/dist/cjs/types/components/shapes/rectangle.d.ts +1 -0
- package/dist/cjs/types/components/shapes/rectangularFrame.d.ts +1 -0
- package/dist/cjs/types/contexts/editorConfigurationContext.d.ts +4 -0
- package/dist/cjs/types/models/IEditorConfiguration.d.ts +3 -0
- package/dist/cjs/types/models/IEditorContext.d.ts +2 -0
- package/dist/cjs/types/models/implementations/EditorContext.d.ts +4 -1
- package/dist/cjs/types/models/implementations/Element.d.ts +1 -1
- package/dist/esm/index.js +82 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/shapes/rectangle.d.ts +1 -0
- package/dist/esm/types/components/shapes/rectangularFrame.d.ts +1 -0
- package/dist/esm/types/contexts/editorConfigurationContext.d.ts +4 -0
- package/dist/esm/types/models/IEditorConfiguration.d.ts +3 -0
- package/dist/esm/types/models/IEditorContext.d.ts +2 -0
- package/dist/esm/types/models/implementations/EditorContext.d.ts +4 -1
- package/dist/esm/types/models/implementations/Element.d.ts +1 -1
- package/dist/index.d.ts +11 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -819,7 +819,7 @@ var EVENT_ELEMENT_MOUSE_DOWN = 'elementMouseDown';
|
|
|
819
819
|
var EVENT_LINK_SELECTED = 'linkSelected';
|
|
820
820
|
var EVENT_TEXT_SELECTED = 'textSelected';
|
|
821
821
|
var EditorContext = /** @class */ (function () {
|
|
822
|
-
function EditorContext(elements, links, texts) {
|
|
822
|
+
function EditorContext(elements, links, texts, configuration) {
|
|
823
823
|
var _this = this;
|
|
824
824
|
/** @internal */
|
|
825
825
|
this.onEditorContextUpdated = function (callback) {
|
|
@@ -832,6 +832,7 @@ var EditorContext = /** @class */ (function () {
|
|
|
832
832
|
this._elements = elements;
|
|
833
833
|
this._links = links;
|
|
834
834
|
this._texts = texts;
|
|
835
|
+
this._configuration = configuration || {};
|
|
835
836
|
this._eventEmitter = new EventEmitter();
|
|
836
837
|
}
|
|
837
838
|
EditorContext.prototype.addEventListener = function (event, callback) {
|
|
@@ -872,6 +873,13 @@ var EditorContext = /** @class */ (function () {
|
|
|
872
873
|
enumerable: false,
|
|
873
874
|
configurable: true
|
|
874
875
|
});
|
|
876
|
+
Object.defineProperty(EditorContext.prototype, "configuration", {
|
|
877
|
+
get: function () {
|
|
878
|
+
return this._configuration;
|
|
879
|
+
},
|
|
880
|
+
enumerable: false,
|
|
881
|
+
configurable: true
|
|
882
|
+
});
|
|
875
883
|
EditorContext.prototype.getElement = function (elementId) {
|
|
876
884
|
return this._elements.find(function (e) { return e.id === elementId; });
|
|
877
885
|
};
|
|
@@ -1110,8 +1118,20 @@ var Rectangle = React.forwardRef(function (props, ref) {
|
|
|
1110
1118
|
scaledWidth = scaledWidth / heightRatio;
|
|
1111
1119
|
}
|
|
1112
1120
|
var sw = props.stroke ? (props.strokeWidth || 1) : 0;
|
|
1121
|
+
var strokeDasharray;
|
|
1122
|
+
var strokeLinecap = undefined;
|
|
1123
|
+
if (props.strokeStyle === 'dashed') {
|
|
1124
|
+
strokeDasharray = '8, 4';
|
|
1125
|
+
}
|
|
1126
|
+
else if (props.strokeStyle === 'dotted') {
|
|
1127
|
+
strokeDasharray = '0, 4';
|
|
1128
|
+
strokeLinecap = 'round';
|
|
1129
|
+
}
|
|
1130
|
+
else {
|
|
1131
|
+
strokeDasharray = undefined;
|
|
1132
|
+
}
|
|
1113
1133
|
return (React.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
|
|
1114
|
-
React.createElement("rect", { className: "rect-border ".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", width: scaledWidth, height: scaledHeight, fill: props.fill || "transparent", stroke: props.stroke || "none", strokeWidth: sw }),
|
|
1134
|
+
React.createElement("rect", { className: "rect-border ".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", width: scaledWidth, height: scaledHeight, fill: props.fill || "transparent", stroke: props.stroke || "none", strokeWidth: sw, strokeDasharray: strokeDasharray, strokeLinecap: strokeLinecap }),
|
|
1115
1135
|
props.children));
|
|
1116
1136
|
});
|
|
1117
1137
|
|
|
@@ -1133,10 +1153,22 @@ var RectangularFrame = React.forwardRef(function (props, ref) {
|
|
|
1133
1153
|
var fw = props.frameColor ? (props.frameWidth || 1) : 0;
|
|
1134
1154
|
var scaledFw = scaledWidth / props.width * fw;
|
|
1135
1155
|
var sw = props.stroke ? (props.strokeWidth || 1) : 0;
|
|
1156
|
+
var strokeDasharray;
|
|
1157
|
+
var strokeLinecap = undefined;
|
|
1158
|
+
if (props.strokeStyle === 'dashed') {
|
|
1159
|
+
strokeDasharray = '8, 4';
|
|
1160
|
+
}
|
|
1161
|
+
else if (props.strokeStyle === 'dotted') {
|
|
1162
|
+
strokeDasharray = '0, 4';
|
|
1163
|
+
strokeLinecap = 'round';
|
|
1164
|
+
}
|
|
1165
|
+
else {
|
|
1166
|
+
strokeDasharray = undefined;
|
|
1167
|
+
}
|
|
1136
1168
|
return (React.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
|
|
1137
|
-
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: "rectangular-frame-outer-border ".concat(props.portMoveableAreaCssClass), x: vbX, y: vbY, width: scaledWidth, height: scaledHeight, fill: "none", stroke: props.stroke || "none", strokeWidth: sw }),
|
|
1169
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: "rectangular-frame-outer-border ".concat(props.portMoveableAreaCssClass), x: vbX, y: vbY, width: scaledWidth, height: scaledHeight, fill: "none", stroke: props.stroke || "none", strokeWidth: sw, strokeDasharray: strokeDasharray, strokeLinecap: strokeLinecap }),
|
|
1138
1170
|
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-hallway', x: vbX + scaledFw / 2, y: vbY + scaledFw / 2, width: scaledWidth - scaledFw, height: scaledHeight - scaledFw, stroke: props.frameColor || "none", strokeWidth: fw, fill: props.fill || "transparent" }),
|
|
1139
|
-
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-inner-border', x: vbX + scaledFw, y: vbY + scaledFw, width: scaledWidth - scaledFw * 2, height: scaledHeight - scaledFw * 2, stroke: props.stroke || "none", strokeWidth: sw, fill: props.fill || "transparent" }),
|
|
1171
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-inner-border', x: vbX + scaledFw, y: vbY + scaledFw, width: scaledWidth - scaledFw * 2, height: scaledHeight - scaledFw * 2, stroke: props.stroke || "none", strokeWidth: sw, fill: props.fill || "transparent", strokeDasharray: strokeDasharray, strokeLinecap: strokeLinecap }),
|
|
1140
1172
|
props.children));
|
|
1141
1173
|
});
|
|
1142
1174
|
|
|
@@ -1714,10 +1746,21 @@ var paperEventEmitterContext = React.createContext({
|
|
|
1714
1746
|
onCommandRenderPort: onCommandRenderPort,
|
|
1715
1747
|
});
|
|
1716
1748
|
|
|
1749
|
+
var editorConfigurationContext = React.createContext(null);
|
|
1750
|
+
var useEditorConfiguration = function () {
|
|
1751
|
+
var context = React.useContext(editorConfigurationContext);
|
|
1752
|
+
if (!context) {
|
|
1753
|
+
throw new Error("useEditorConfiguration must be used within an EditorConfigurationProvider");
|
|
1754
|
+
}
|
|
1755
|
+
return context;
|
|
1756
|
+
};
|
|
1757
|
+
var EditorConfigurationContextProvider = editorConfigurationContext.Provider;
|
|
1758
|
+
|
|
1717
1759
|
var Text = React.forwardRef(function (_a, ref) {
|
|
1718
1760
|
var id = _a.id, content = _a.content, x = _a.x, y = _a.y, width = _a.width, height = _a.height, editable = _a.editable, _b = _a.selectable, selectable = _b === void 0 ? true : _b, _c = _a.align, align = _c === void 0 ? exports.TextAlign.left : _c, fontSizeProp = _a.fontSize, border = _a.border, container = _a.container, parentAbsolutePosition = _a.parentAbsolutePosition, onSelected = _a.onSelected, onMoved = _a.onMoved, onResized = _a.onResized, onContentChanged = _a.onContentChanged;
|
|
1719
1761
|
var _d = React.useState(false), isSelected = _d[0], setIsSelected = _d[1];
|
|
1720
1762
|
var _e = React.useState(false), isEditing = _e[0], setIsEditing = _e[1];
|
|
1763
|
+
var textFontSize = useEditorConfiguration().textFontSize;
|
|
1721
1764
|
var absolutePosition = React.useMemo(function () {
|
|
1722
1765
|
var _a, _b;
|
|
1723
1766
|
return {
|
|
@@ -1810,9 +1853,12 @@ var Text = React.forwardRef(function (_a, ref) {
|
|
|
1810
1853
|
return 'left';
|
|
1811
1854
|
}
|
|
1812
1855
|
}, [align]);
|
|
1813
|
-
var fontSize = fontSizeProp || TEXT_FONT_SIZE;
|
|
1856
|
+
var fontSize = fontSizeProp || textFontSize || TEXT_FONT_SIZE;
|
|
1814
1857
|
var borderStyle = border || 'none';
|
|
1815
|
-
return (React.createElement("svg", { style: {
|
|
1858
|
+
return (React.createElement("svg", { style: {
|
|
1859
|
+
overflow: "visible",
|
|
1860
|
+
pointerEvents: selectable ? undefined : 'none',
|
|
1861
|
+
}, x: x, y: y, ref: function (node) {
|
|
1816
1862
|
svgRef.current = node;
|
|
1817
1863
|
if (typeof ref === 'function') {
|
|
1818
1864
|
ref(node);
|
|
@@ -9441,13 +9487,13 @@ var Paper = function (props) {
|
|
|
9441
9487
|
}, [selectedText, props.onTextsChanged]);
|
|
9442
9488
|
var handlePaperMouseMove = function (ev) {
|
|
9443
9489
|
var _a;
|
|
9490
|
+
var currentTarget = ev.currentTarget;
|
|
9491
|
+
// Get the mouse position relative to the paper container
|
|
9492
|
+
var paperRect = currentTarget.getBoundingClientRect();
|
|
9493
|
+
var xPosOnPaper = ev.clientX - paperRect.left;
|
|
9494
|
+
var yPosOnPaper = ev.clientY - paperRect.top;
|
|
9444
9495
|
//if there is a temp link, update the temp target point
|
|
9445
9496
|
if (tempLink) {
|
|
9446
|
-
var currentTarget = ev.currentTarget;
|
|
9447
|
-
//get offset x,y of the temp target point relative paper container
|
|
9448
|
-
var rect = currentTarget.getBoundingClientRect();
|
|
9449
|
-
var offsetX = ev.clientX - rect.left;
|
|
9450
|
-
var offsetY = ev.clientY - rect.top;
|
|
9451
9497
|
var sourceElementAbsPosition = getAbsolutePosition(tempLink.sourceElement);
|
|
9452
9498
|
var sourcePosition = {
|
|
9453
9499
|
x: sourceElementAbsPosition.x + tempLink.sourcePort.position.x,
|
|
@@ -9455,19 +9501,24 @@ var Paper = function (props) {
|
|
|
9455
9501
|
};
|
|
9456
9502
|
//reduce the position of offset to the direction of the source point 1 unit to avoid the link to reach the current mouse position
|
|
9457
9503
|
var tempTargetPosition_1 = {
|
|
9458
|
-
x:
|
|
9459
|
-
y:
|
|
9504
|
+
x: xPosOnPaper - (xPosOnPaper > sourcePosition.x ? 1 : -1),
|
|
9505
|
+
y: yPosOnPaper - (yPosOnPaper > sourcePosition.y ? 1 : -1)
|
|
9460
9506
|
};
|
|
9461
9507
|
setTempLink(function (prev) { return (__assign(__assign({}, prev), { tempTargetPosition: tempTargetPosition_1 })); });
|
|
9462
9508
|
}
|
|
9463
9509
|
//broadcast mouse moved position to parent component
|
|
9464
9510
|
(_a = props.onPaperMouseMoved) === null || _a === void 0 ? void 0 : _a.call(props, {
|
|
9465
|
-
x:
|
|
9466
|
-
y:
|
|
9511
|
+
x: xPosOnPaper,
|
|
9512
|
+
y: yPosOnPaper
|
|
9467
9513
|
});
|
|
9468
9514
|
};
|
|
9469
9515
|
var handleMouseDownOnPaper = function (ev) {
|
|
9470
9516
|
var _a, _b;
|
|
9517
|
+
var currentTarget = ev.currentTarget;
|
|
9518
|
+
// Get the mouse position relative to the paper container
|
|
9519
|
+
var paperRect = currentTarget.getBoundingClientRect();
|
|
9520
|
+
var xPosOnPaper = ev.clientX - paperRect.left;
|
|
9521
|
+
var yPosOnPaper = ev.clientY - paperRect.top;
|
|
9471
9522
|
setMouseDownedOnPaper(true);
|
|
9472
9523
|
(_a = props.onPaperClicked) === null || _a === void 0 ? void 0 : _a.call(props, {
|
|
9473
9524
|
x: ev.clientX,
|
|
@@ -9476,12 +9527,17 @@ var Paper = function (props) {
|
|
|
9476
9527
|
paperEventEmitter.emitPaperClicked(ev);
|
|
9477
9528
|
//broadcast mouse moved position to parent component
|
|
9478
9529
|
(_b = props.onPaperMouseDown) === null || _b === void 0 ? void 0 : _b.call(props, {
|
|
9479
|
-
x:
|
|
9480
|
-
y:
|
|
9530
|
+
x: xPosOnPaper,
|
|
9531
|
+
y: yPosOnPaper
|
|
9481
9532
|
});
|
|
9482
9533
|
};
|
|
9483
9534
|
var handleMouseUpOnPaper = function (ev) {
|
|
9484
9535
|
var _a;
|
|
9536
|
+
var currentTarget = ev.currentTarget;
|
|
9537
|
+
// Get the mouse position relative to the paper container
|
|
9538
|
+
var paperRect = currentTarget.getBoundingClientRect();
|
|
9539
|
+
var xPosOnPaper = ev.clientX - paperRect.left;
|
|
9540
|
+
var yPosOnPaper = ev.clientY - paperRect.top;
|
|
9485
9541
|
if (mouseDownedOnPaper) {
|
|
9486
9542
|
setSelectedElement(undefined);
|
|
9487
9543
|
setSelectedElementSVG(null);
|
|
@@ -9498,8 +9554,8 @@ var Paper = function (props) {
|
|
|
9498
9554
|
setMouseDownedOnPaper(false);
|
|
9499
9555
|
//broadcast mouse moved position to parent component
|
|
9500
9556
|
(_a = props.onPaperMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, {
|
|
9501
|
-
x:
|
|
9502
|
-
y:
|
|
9557
|
+
x: xPosOnPaper,
|
|
9558
|
+
y: yPosOnPaper
|
|
9503
9559
|
});
|
|
9504
9560
|
};
|
|
9505
9561
|
var handlePathChange = React.useCallback(function (path, id) {
|
|
@@ -10146,6 +10202,7 @@ var Editor = function (_a) {
|
|
|
10146
10202
|
editorContext.onLinkSelectedHandler(link);
|
|
10147
10203
|
}, [editorContext]);
|
|
10148
10204
|
var handleLinksChanged = React.useCallback(function (links) {
|
|
10205
|
+
console.log(links);
|
|
10149
10206
|
editorContext.links = links;
|
|
10150
10207
|
}, [editorContext]);
|
|
10151
10208
|
var handleTextSelected = React.useCallback(function (text) {
|
|
@@ -10167,16 +10224,19 @@ var Editor = function (_a) {
|
|
|
10167
10224
|
return null;
|
|
10168
10225
|
}, [editorContext]);
|
|
10169
10226
|
var handlePaperMouseMoved = React.useCallback(function (position) {
|
|
10227
|
+
console.log("handlePaperMouseMoved", position);
|
|
10170
10228
|
editorContext.onPaperMouseMovedHandler(position);
|
|
10171
10229
|
}, [editorContext]);
|
|
10172
10230
|
var handlePaperMouseDown = React.useCallback(function (position) {
|
|
10231
|
+
console.log("handlePaperMouseDown", position);
|
|
10173
10232
|
editorContext.onPaperMouseDownHandler(position);
|
|
10174
10233
|
}, [editorContext]);
|
|
10175
10234
|
var handlePaperMouseUp = React.useCallback(function (position) {
|
|
10176
10235
|
editorContext.onPaperMouseUpHandler(position);
|
|
10177
10236
|
}, [editorContext]);
|
|
10178
|
-
return (React.createElement(
|
|
10179
|
-
React.createElement(
|
|
10237
|
+
return (React.createElement(EditorConfigurationContextProvider, { value: editorContext.configuration },
|
|
10238
|
+
React.createElement(ZoomContextProvider, null,
|
|
10239
|
+
React.createElement(Paper$1, { key: "paper", size: { width: width, height: height }, elements: elements, links: links, texts: texts, onPaperClicked: handlePaperClicked, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onPortsChanged: handlePortsChanged, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onElementMouseLeave: handleElementMouseLeave, onElementMouseMove: handleElementMouseMove, onElementMouseDown: handleElementMouseDown, onElementMouseUp: handleElementMouseUp, onElementsChanged: handleElementsChanged, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onLinksChanged: handleLinksChanged, onTextSelected: handleTextSelected, onTextsChanged: handleTextsChanged, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseUp, onPaperMouseDown: handlePaperMouseDown, onManuallyTriggerRenderElement: editorContext.onManuallyTriggerRenderElement.bind(editorContext), onManuallyTriggerRenderPort: editorContext.onManuallyTriggerRenderPort.bind(editorContext) }))));
|
|
10180
10240
|
};
|
|
10181
10241
|
|
|
10182
10242
|
exports.CircleRC = Circle;
|
|
@@ -4,6 +4,7 @@ interface RectangleProps extends IShape {
|
|
|
4
4
|
fill?: string;
|
|
5
5
|
stroke?: string;
|
|
6
6
|
strokeWidth?: number;
|
|
7
|
+
strokeStyle?: string;
|
|
7
8
|
}
|
|
8
9
|
declare const Rectangle: React.ForwardRefExoticComponent<RectangleProps & React.RefAttributes<SVGSVGElement>>;
|
|
9
10
|
export default Rectangle;
|
|
@@ -6,6 +6,7 @@ interface RectangularFrameProps extends IShape {
|
|
|
6
6
|
strokeWidth?: number;
|
|
7
7
|
frameColor?: string;
|
|
8
8
|
frameWidth?: number;
|
|
9
|
+
strokeStyle?: string;
|
|
9
10
|
}
|
|
10
11
|
declare const RectangularFrame: React.ForwardRefExoticComponent<RectangularFrameProps & React.RefAttributes<SVGSVGElement>>;
|
|
11
12
|
export default RectangularFrame;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IEditorConfiguration } from "../models/IEditorConfiguration";
|
|
3
|
+
export declare const useEditorConfiguration: () => IEditorConfiguration;
|
|
4
|
+
export declare const EditorConfigurationContextProvider: import("react").Provider<IEditorConfiguration | null>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { IEditorConfiguration } from "./IEditorConfiguration";
|
|
2
3
|
import IElement from "./IElement";
|
|
3
4
|
import IElementLink from "./IElementLink";
|
|
4
5
|
import IPort from "./IPort";
|
|
@@ -9,6 +10,7 @@ export default interface IEditorContext {
|
|
|
9
10
|
elements: IElement[];
|
|
10
11
|
links: IElementLink[];
|
|
11
12
|
texts: IPaperText[];
|
|
13
|
+
configuration: IEditorConfiguration;
|
|
12
14
|
onCreatingPortByLinkingHandler?: (sourceElement: IElement, sourcePort: IPort, targetElement: IElement, position: IPosition) => IPort | null;
|
|
13
15
|
onCreatingLinkHandler?: (sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => IElementLink | null;
|
|
14
16
|
onPaperClicked: (callback: (position: IPosition) => void) => (() => void);
|
|
@@ -6,14 +6,16 @@ import IPosition from "../position";
|
|
|
6
6
|
import IPort from "../IPort";
|
|
7
7
|
import ISize from "../size";
|
|
8
8
|
import IEditorContext from "../IEditorContext";
|
|
9
|
+
import { IEditorConfiguration } from "../IEditorConfiguration";
|
|
9
10
|
export declare class EditorContext implements IEditorContext {
|
|
10
11
|
private _elements;
|
|
11
12
|
private _links;
|
|
12
13
|
private _texts;
|
|
13
14
|
private _eventEmitter;
|
|
15
|
+
private _configuration;
|
|
14
16
|
onCreatingPortByLinkingHandler?: ((sourceElement: IElement, sourcePort: IPort, targetElement: IElement, position: IPosition) => IPort | null) | undefined;
|
|
15
17
|
onCreatingLinkHandler?: ((sourcePort: IPort, sourceElement: IElement, targetPort: IPort, targetElement: IElement) => IElementLink | null) | undefined;
|
|
16
|
-
constructor(elements: IElement[], links: IElementLink[], texts: IPaperText[]);
|
|
18
|
+
constructor(elements: IElement[], links: IElementLink[], texts: IPaperText[], configuration?: IEditorConfiguration);
|
|
17
19
|
private addEventListener;
|
|
18
20
|
get elements(): IElement[];
|
|
19
21
|
get links(): IElementLink[];
|
|
@@ -21,6 +23,7 @@ export declare class EditorContext implements IEditorContext {
|
|
|
21
23
|
set elements(value: IElement[]);
|
|
22
24
|
set links(value: IElementLink[]);
|
|
23
25
|
set texts(value: IPaperText[]);
|
|
26
|
+
get configuration(): IEditorConfiguration;
|
|
24
27
|
getElement(elementId: string): IElement | undefined;
|
|
25
28
|
addElement(element: IElement): void;
|
|
26
29
|
removeElement(elementId: string): void;
|
|
@@ -37,7 +37,7 @@ export default class Element implements IElement {
|
|
|
37
37
|
textsPlaceHolderFlexStyle?: IFlexboxType;
|
|
38
38
|
textsPlaceHolderFlexboxPosition?: IPosition;
|
|
39
39
|
_eventEmitter: EventEmitter;
|
|
40
|
-
constructor(id: string | null, 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?:
|
|
40
|
+
constructor(id: string | null, 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?: IElement, textsPlaceHolderClassName?: string, textsPlaceHolderFlexStyle?: IFlexboxType, textsPlaceHolderFlexboxPosition?: IPosition);
|
|
41
41
|
get id(): string;
|
|
42
42
|
get size(): ISize;
|
|
43
43
|
set size(value: ISize);
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef, useMemo, useEffect, useState, useCallback, createContext,
|
|
1
|
+
import React, { forwardRef, useMemo, useEffect, useState, useCallback, createContext, useContext, useRef, memo, useLayoutEffect, useImperativeHandle } from 'react';
|
|
2
2
|
import require$$0 from 'react-dom';
|
|
3
3
|
|
|
4
4
|
var PositioningAnchor;
|
|
@@ -815,7 +815,7 @@ var EVENT_ELEMENT_MOUSE_DOWN = 'elementMouseDown';
|
|
|
815
815
|
var EVENT_LINK_SELECTED = 'linkSelected';
|
|
816
816
|
var EVENT_TEXT_SELECTED = 'textSelected';
|
|
817
817
|
var EditorContext = /** @class */ (function () {
|
|
818
|
-
function EditorContext(elements, links, texts) {
|
|
818
|
+
function EditorContext(elements, links, texts, configuration) {
|
|
819
819
|
var _this = this;
|
|
820
820
|
/** @internal */
|
|
821
821
|
this.onEditorContextUpdated = function (callback) {
|
|
@@ -828,6 +828,7 @@ var EditorContext = /** @class */ (function () {
|
|
|
828
828
|
this._elements = elements;
|
|
829
829
|
this._links = links;
|
|
830
830
|
this._texts = texts;
|
|
831
|
+
this._configuration = configuration || {};
|
|
831
832
|
this._eventEmitter = new EventEmitter();
|
|
832
833
|
}
|
|
833
834
|
EditorContext.prototype.addEventListener = function (event, callback) {
|
|
@@ -868,6 +869,13 @@ var EditorContext = /** @class */ (function () {
|
|
|
868
869
|
enumerable: false,
|
|
869
870
|
configurable: true
|
|
870
871
|
});
|
|
872
|
+
Object.defineProperty(EditorContext.prototype, "configuration", {
|
|
873
|
+
get: function () {
|
|
874
|
+
return this._configuration;
|
|
875
|
+
},
|
|
876
|
+
enumerable: false,
|
|
877
|
+
configurable: true
|
|
878
|
+
});
|
|
871
879
|
EditorContext.prototype.getElement = function (elementId) {
|
|
872
880
|
return this._elements.find(function (e) { return e.id === elementId; });
|
|
873
881
|
};
|
|
@@ -1106,8 +1114,20 @@ var Rectangle = forwardRef(function (props, ref) {
|
|
|
1106
1114
|
scaledWidth = scaledWidth / heightRatio;
|
|
1107
1115
|
}
|
|
1108
1116
|
var sw = props.stroke ? (props.strokeWidth || 1) : 0;
|
|
1117
|
+
var strokeDasharray;
|
|
1118
|
+
var strokeLinecap = undefined;
|
|
1119
|
+
if (props.strokeStyle === 'dashed') {
|
|
1120
|
+
strokeDasharray = '8, 4';
|
|
1121
|
+
}
|
|
1122
|
+
else if (props.strokeStyle === 'dotted') {
|
|
1123
|
+
strokeDasharray = '0, 4';
|
|
1124
|
+
strokeLinecap = 'round';
|
|
1125
|
+
}
|
|
1126
|
+
else {
|
|
1127
|
+
strokeDasharray = undefined;
|
|
1128
|
+
}
|
|
1109
1129
|
return (React.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
|
|
1110
|
-
React.createElement("rect", { className: "rect-border ".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", width: scaledWidth, height: scaledHeight, fill: props.fill || "transparent", stroke: props.stroke || "none", strokeWidth: sw }),
|
|
1130
|
+
React.createElement("rect", { className: "rect-border ".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", width: scaledWidth, height: scaledHeight, fill: props.fill || "transparent", stroke: props.stroke || "none", strokeWidth: sw, strokeDasharray: strokeDasharray, strokeLinecap: strokeLinecap }),
|
|
1111
1131
|
props.children));
|
|
1112
1132
|
});
|
|
1113
1133
|
|
|
@@ -1129,10 +1149,22 @@ var RectangularFrame = forwardRef(function (props, ref) {
|
|
|
1129
1149
|
var fw = props.frameColor ? (props.frameWidth || 1) : 0;
|
|
1130
1150
|
var scaledFw = scaledWidth / props.width * fw;
|
|
1131
1151
|
var sw = props.stroke ? (props.strokeWidth || 1) : 0;
|
|
1152
|
+
var strokeDasharray;
|
|
1153
|
+
var strokeLinecap = undefined;
|
|
1154
|
+
if (props.strokeStyle === 'dashed') {
|
|
1155
|
+
strokeDasharray = '8, 4';
|
|
1156
|
+
}
|
|
1157
|
+
else if (props.strokeStyle === 'dotted') {
|
|
1158
|
+
strokeDasharray = '0, 4';
|
|
1159
|
+
strokeLinecap = 'round';
|
|
1160
|
+
}
|
|
1161
|
+
else {
|
|
1162
|
+
strokeDasharray = undefined;
|
|
1163
|
+
}
|
|
1132
1164
|
return (React.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
|
|
1133
|
-
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: "rectangular-frame-outer-border ".concat(props.portMoveableAreaCssClass), x: vbX, y: vbY, width: scaledWidth, height: scaledHeight, fill: "none", stroke: props.stroke || "none", strokeWidth: sw }),
|
|
1165
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: "rectangular-frame-outer-border ".concat(props.portMoveableAreaCssClass), x: vbX, y: vbY, width: scaledWidth, height: scaledHeight, fill: "none", stroke: props.stroke || "none", strokeWidth: sw, strokeDasharray: strokeDasharray, strokeLinecap: strokeLinecap }),
|
|
1134
1166
|
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-hallway', x: vbX + scaledFw / 2, y: vbY + scaledFw / 2, width: scaledWidth - scaledFw, height: scaledHeight - scaledFw, stroke: props.frameColor || "none", strokeWidth: fw, fill: props.fill || "transparent" }),
|
|
1135
|
-
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-inner-border', x: vbX + scaledFw, y: vbY + scaledFw, width: scaledWidth - scaledFw * 2, height: scaledHeight - scaledFw * 2, stroke: props.stroke || "none", strokeWidth: sw, fill: props.fill || "transparent" }),
|
|
1167
|
+
React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-inner-border', x: vbX + scaledFw, y: vbY + scaledFw, width: scaledWidth - scaledFw * 2, height: scaledHeight - scaledFw * 2, stroke: props.stroke || "none", strokeWidth: sw, fill: props.fill || "transparent", strokeDasharray: strokeDasharray, strokeLinecap: strokeLinecap }),
|
|
1136
1168
|
props.children));
|
|
1137
1169
|
});
|
|
1138
1170
|
|
|
@@ -1710,10 +1742,21 @@ var paperEventEmitterContext = createContext({
|
|
|
1710
1742
|
onCommandRenderPort: onCommandRenderPort,
|
|
1711
1743
|
});
|
|
1712
1744
|
|
|
1745
|
+
var editorConfigurationContext = createContext(null);
|
|
1746
|
+
var useEditorConfiguration = function () {
|
|
1747
|
+
var context = useContext(editorConfigurationContext);
|
|
1748
|
+
if (!context) {
|
|
1749
|
+
throw new Error("useEditorConfiguration must be used within an EditorConfigurationProvider");
|
|
1750
|
+
}
|
|
1751
|
+
return context;
|
|
1752
|
+
};
|
|
1753
|
+
var EditorConfigurationContextProvider = editorConfigurationContext.Provider;
|
|
1754
|
+
|
|
1713
1755
|
var Text = forwardRef(function (_a, ref) {
|
|
1714
1756
|
var id = _a.id, content = _a.content, x = _a.x, y = _a.y, width = _a.width, height = _a.height, editable = _a.editable, _b = _a.selectable, selectable = _b === void 0 ? true : _b, _c = _a.align, align = _c === void 0 ? TextAlign.left : _c, fontSizeProp = _a.fontSize, border = _a.border, container = _a.container, parentAbsolutePosition = _a.parentAbsolutePosition, onSelected = _a.onSelected, onMoved = _a.onMoved, onResized = _a.onResized, onContentChanged = _a.onContentChanged;
|
|
1715
1757
|
var _d = useState(false), isSelected = _d[0], setIsSelected = _d[1];
|
|
1716
1758
|
var _e = useState(false), isEditing = _e[0], setIsEditing = _e[1];
|
|
1759
|
+
var textFontSize = useEditorConfiguration().textFontSize;
|
|
1717
1760
|
var absolutePosition = useMemo(function () {
|
|
1718
1761
|
var _a, _b;
|
|
1719
1762
|
return {
|
|
@@ -1806,9 +1849,12 @@ var Text = forwardRef(function (_a, ref) {
|
|
|
1806
1849
|
return 'left';
|
|
1807
1850
|
}
|
|
1808
1851
|
}, [align]);
|
|
1809
|
-
var fontSize = fontSizeProp || TEXT_FONT_SIZE;
|
|
1852
|
+
var fontSize = fontSizeProp || textFontSize || TEXT_FONT_SIZE;
|
|
1810
1853
|
var borderStyle = border || 'none';
|
|
1811
|
-
return (React.createElement("svg", { style: {
|
|
1854
|
+
return (React.createElement("svg", { style: {
|
|
1855
|
+
overflow: "visible",
|
|
1856
|
+
pointerEvents: selectable ? undefined : 'none',
|
|
1857
|
+
}, x: x, y: y, ref: function (node) {
|
|
1812
1858
|
svgRef.current = node;
|
|
1813
1859
|
if (typeof ref === 'function') {
|
|
1814
1860
|
ref(node);
|
|
@@ -9437,13 +9483,13 @@ var Paper = function (props) {
|
|
|
9437
9483
|
}, [selectedText, props.onTextsChanged]);
|
|
9438
9484
|
var handlePaperMouseMove = function (ev) {
|
|
9439
9485
|
var _a;
|
|
9486
|
+
var currentTarget = ev.currentTarget;
|
|
9487
|
+
// Get the mouse position relative to the paper container
|
|
9488
|
+
var paperRect = currentTarget.getBoundingClientRect();
|
|
9489
|
+
var xPosOnPaper = ev.clientX - paperRect.left;
|
|
9490
|
+
var yPosOnPaper = ev.clientY - paperRect.top;
|
|
9440
9491
|
//if there is a temp link, update the temp target point
|
|
9441
9492
|
if (tempLink) {
|
|
9442
|
-
var currentTarget = ev.currentTarget;
|
|
9443
|
-
//get offset x,y of the temp target point relative paper container
|
|
9444
|
-
var rect = currentTarget.getBoundingClientRect();
|
|
9445
|
-
var offsetX = ev.clientX - rect.left;
|
|
9446
|
-
var offsetY = ev.clientY - rect.top;
|
|
9447
9493
|
var sourceElementAbsPosition = getAbsolutePosition(tempLink.sourceElement);
|
|
9448
9494
|
var sourcePosition = {
|
|
9449
9495
|
x: sourceElementAbsPosition.x + tempLink.sourcePort.position.x,
|
|
@@ -9451,19 +9497,24 @@ var Paper = function (props) {
|
|
|
9451
9497
|
};
|
|
9452
9498
|
//reduce the position of offset to the direction of the source point 1 unit to avoid the link to reach the current mouse position
|
|
9453
9499
|
var tempTargetPosition_1 = {
|
|
9454
|
-
x:
|
|
9455
|
-
y:
|
|
9500
|
+
x: xPosOnPaper - (xPosOnPaper > sourcePosition.x ? 1 : -1),
|
|
9501
|
+
y: yPosOnPaper - (yPosOnPaper > sourcePosition.y ? 1 : -1)
|
|
9456
9502
|
};
|
|
9457
9503
|
setTempLink(function (prev) { return (__assign(__assign({}, prev), { tempTargetPosition: tempTargetPosition_1 })); });
|
|
9458
9504
|
}
|
|
9459
9505
|
//broadcast mouse moved position to parent component
|
|
9460
9506
|
(_a = props.onPaperMouseMoved) === null || _a === void 0 ? void 0 : _a.call(props, {
|
|
9461
|
-
x:
|
|
9462
|
-
y:
|
|
9507
|
+
x: xPosOnPaper,
|
|
9508
|
+
y: yPosOnPaper
|
|
9463
9509
|
});
|
|
9464
9510
|
};
|
|
9465
9511
|
var handleMouseDownOnPaper = function (ev) {
|
|
9466
9512
|
var _a, _b;
|
|
9513
|
+
var currentTarget = ev.currentTarget;
|
|
9514
|
+
// Get the mouse position relative to the paper container
|
|
9515
|
+
var paperRect = currentTarget.getBoundingClientRect();
|
|
9516
|
+
var xPosOnPaper = ev.clientX - paperRect.left;
|
|
9517
|
+
var yPosOnPaper = ev.clientY - paperRect.top;
|
|
9467
9518
|
setMouseDownedOnPaper(true);
|
|
9468
9519
|
(_a = props.onPaperClicked) === null || _a === void 0 ? void 0 : _a.call(props, {
|
|
9469
9520
|
x: ev.clientX,
|
|
@@ -9472,12 +9523,17 @@ var Paper = function (props) {
|
|
|
9472
9523
|
paperEventEmitter.emitPaperClicked(ev);
|
|
9473
9524
|
//broadcast mouse moved position to parent component
|
|
9474
9525
|
(_b = props.onPaperMouseDown) === null || _b === void 0 ? void 0 : _b.call(props, {
|
|
9475
|
-
x:
|
|
9476
|
-
y:
|
|
9526
|
+
x: xPosOnPaper,
|
|
9527
|
+
y: yPosOnPaper
|
|
9477
9528
|
});
|
|
9478
9529
|
};
|
|
9479
9530
|
var handleMouseUpOnPaper = function (ev) {
|
|
9480
9531
|
var _a;
|
|
9532
|
+
var currentTarget = ev.currentTarget;
|
|
9533
|
+
// Get the mouse position relative to the paper container
|
|
9534
|
+
var paperRect = currentTarget.getBoundingClientRect();
|
|
9535
|
+
var xPosOnPaper = ev.clientX - paperRect.left;
|
|
9536
|
+
var yPosOnPaper = ev.clientY - paperRect.top;
|
|
9481
9537
|
if (mouseDownedOnPaper) {
|
|
9482
9538
|
setSelectedElement(undefined);
|
|
9483
9539
|
setSelectedElementSVG(null);
|
|
@@ -9494,8 +9550,8 @@ var Paper = function (props) {
|
|
|
9494
9550
|
setMouseDownedOnPaper(false);
|
|
9495
9551
|
//broadcast mouse moved position to parent component
|
|
9496
9552
|
(_a = props.onPaperMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, {
|
|
9497
|
-
x:
|
|
9498
|
-
y:
|
|
9553
|
+
x: xPosOnPaper,
|
|
9554
|
+
y: yPosOnPaper
|
|
9499
9555
|
});
|
|
9500
9556
|
};
|
|
9501
9557
|
var handlePathChange = useCallback(function (path, id) {
|
|
@@ -10142,6 +10198,7 @@ var Editor = function (_a) {
|
|
|
10142
10198
|
editorContext.onLinkSelectedHandler(link);
|
|
10143
10199
|
}, [editorContext]);
|
|
10144
10200
|
var handleLinksChanged = useCallback(function (links) {
|
|
10201
|
+
console.log(links);
|
|
10145
10202
|
editorContext.links = links;
|
|
10146
10203
|
}, [editorContext]);
|
|
10147
10204
|
var handleTextSelected = useCallback(function (text) {
|
|
@@ -10163,16 +10220,19 @@ var Editor = function (_a) {
|
|
|
10163
10220
|
return null;
|
|
10164
10221
|
}, [editorContext]);
|
|
10165
10222
|
var handlePaperMouseMoved = useCallback(function (position) {
|
|
10223
|
+
console.log("handlePaperMouseMoved", position);
|
|
10166
10224
|
editorContext.onPaperMouseMovedHandler(position);
|
|
10167
10225
|
}, [editorContext]);
|
|
10168
10226
|
var handlePaperMouseDown = useCallback(function (position) {
|
|
10227
|
+
console.log("handlePaperMouseDown", position);
|
|
10169
10228
|
editorContext.onPaperMouseDownHandler(position);
|
|
10170
10229
|
}, [editorContext]);
|
|
10171
10230
|
var handlePaperMouseUp = useCallback(function (position) {
|
|
10172
10231
|
editorContext.onPaperMouseUpHandler(position);
|
|
10173
10232
|
}, [editorContext]);
|
|
10174
|
-
return (React.createElement(
|
|
10175
|
-
React.createElement(
|
|
10233
|
+
return (React.createElement(EditorConfigurationContextProvider, { value: editorContext.configuration },
|
|
10234
|
+
React.createElement(ZoomContextProvider, null,
|
|
10235
|
+
React.createElement(Paper$1, { key: "paper", size: { width: width, height: height }, elements: elements, links: links, texts: texts, onPaperClicked: handlePaperClicked, onPortMouseDown: handlePortMouseDown, onPortMouseUp: handlePortMouseUp, onPortMoved: handlePortMoved, onPortSelected: handlePortSelected, onPortsChanged: handlePortsChanged, onElementContextMenu: handleElementContextMenu, onElementMoved: handleElementMoved, onElementResized: handleElementResized, onElementSelected: handleElementSelected, onElementMouseLeave: handleElementMouseLeave, onElementMouseMove: handleElementMouseMove, onElementMouseDown: handleElementMouseDown, onElementMouseUp: handleElementMouseUp, onElementsChanged: handleElementsChanged, onCreatingLink: handleOnCreatingLink, onCreatingPortByLinking: handleOnCreatingPortByLinking, onLinkSelected: handleLinkSelected, onLinksChanged: handleLinksChanged, onTextSelected: handleTextSelected, onTextsChanged: handleTextsChanged, onPaperMouseMoved: handlePaperMouseMoved, onPaperMouseUp: handlePaperMouseUp, onPaperMouseDown: handlePaperMouseDown, onManuallyTriggerRenderElement: editorContext.onManuallyTriggerRenderElement.bind(editorContext), onManuallyTriggerRenderPort: editorContext.onManuallyTriggerRenderPort.bind(editorContext) }))));
|
|
10176
10236
|
};
|
|
10177
10237
|
|
|
10178
10238
|
export { Circle as CircleRC, Crescent as CrescentRC, CustomShape as CustomShapeRC, EditorContext, Element$2 as Element, ElementLink$1 as ElementLink, ElementLink as ElementLinkRC, Port$1 as Port, Port as PortRC, PositioningAnchor, Rectangle as RectangleRC, RectangularFrame as RectangularFrameRC, ResizingDirection, ShapeWrapper as ShapeWrapperRC, SubObjectDirection, Text$2 as Text, TextAlign, Text$1 as TextRC, addPointToList, calculateAngleWithOx, checkPointContainsPolygon, checkPositionOnLine, checkSamePosition, configureLogger, correctPortPositionInElement, createSmoothPathString, Editor as default, degreeToRadian, diamondEdgeInsideSquare, dist, findNearestPointOnSegment, findNearestPosition, findNearestProjectedPoint, generateSubstitutePosition, generateUniqueId, getAbsolutePosition, getCurvePathData, getElementRotationInfo, getFirstIntersection, getFourVertexesOfBBoxFromElement, getIntersectionPositions, getPointsFromPathData, getPointsFromPathElement, getPortAbsolutePosition, getRectangleCorners, getRelativePosition, getRotatedRectangleCoordinates, getRotatedSVGBBox, getSVGBBoxOutsideTransformedParent, makePolygonOfElement, pathDataToD, removeDuplicatePosition, transformAbsPositionToElementRelativePosition, transformAbsPositionToRelativePositionInsideElement };
|