orcasvn-react-diagrams 0.1.79 → 0.1.81
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 +23 -7
- package/dist/cjs/types/models/implementations/EditorContext.d.ts +1 -1
- package/dist/esm/index.js +23 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/models/implementations/EditorContext.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -943,10 +943,17 @@ var EditorContext = /** @class */ (function () {
|
|
|
943
943
|
this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
|
|
944
944
|
this.onElementAddedHandler(element);
|
|
945
945
|
};
|
|
946
|
-
EditorContext.prototype.removeElement = function (elementId
|
|
946
|
+
EditorContext.prototype.removeElement = function (elementId) {
|
|
947
|
+
//find parent element id
|
|
948
|
+
var element = this.getElement(elementId);
|
|
949
|
+
var parentElement = element === null || element === void 0 ? void 0 : element.parentElement;
|
|
947
950
|
this._elements = this._elements.filter(function (e) { return e.id !== elementId; });
|
|
951
|
+
//remove from parent element if parentElementId is provided
|
|
952
|
+
if (parentElement) {
|
|
953
|
+
parentElement.childrenElements = parentElement.childrenElements.filter(function (e) { return e.id !== elementId; });
|
|
954
|
+
}
|
|
948
955
|
this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
|
|
949
|
-
this.onElementRemovedHandler(elementId,
|
|
956
|
+
this.onElementRemovedHandler(elementId, parentElement === null || parentElement === void 0 ? void 0 : parentElement.id);
|
|
950
957
|
};
|
|
951
958
|
EditorContext.prototype.getLink = function (linkId) {
|
|
952
959
|
return this._links.find(function (l) { return l.id === linkId; });
|
|
@@ -8856,6 +8863,14 @@ var ElementWrapper = React.forwardRef(function (_a, ref) {
|
|
|
8856
8863
|
return (React.createElement("svg", { className: cssClass, x: x, y: y, onClick: handleClick, onContextMenu: handleClick, onMouseDown: onMouseDown, ref: ref, style: { overflow: "visible" }, onMouseMove: onMouseMove, onMouseLeave: onMouseLeave, onMouseUp: onMouseUp }, children));
|
|
8857
8864
|
});
|
|
8858
8865
|
|
|
8866
|
+
var transformPositionToAnchoredPosition = function (position, elementSize, anchor) {
|
|
8867
|
+
var anchoredPosition = { x: position.x, y: position.y };
|
|
8868
|
+
if (anchor === exports.PositioningAnchor.Center) {
|
|
8869
|
+
anchoredPosition.x = position.x - elementSize.width / 2;
|
|
8870
|
+
anchoredPosition.y = position.y - elementSize.height / 2;
|
|
8871
|
+
}
|
|
8872
|
+
return anchoredPosition;
|
|
8873
|
+
};
|
|
8859
8874
|
var Element = React.forwardRef(function (props, forwardedRef) {
|
|
8860
8875
|
var _paperEventEmitterContext = React.useContext(paperEventEmitterContext);
|
|
8861
8876
|
// const elementObj = props.element;
|
|
@@ -8863,7 +8878,7 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
8863
8878
|
var _a = props.element, id = _a.id, cssClass = _a.cssClass; _a.textsPlaceHolderClassName; var portSlideRailSVGClassName = _a.portSlideRailSVGClassName, portMoveableAreas = _a.portMoveableAreas, portDirection = _a.portDirection, defaultPortSize = _a.defaultPortSize; _a.textsPlaceHolderFlexStyle; _a.textsPlaceHolderFlexboxPosition; var resizability = _a.resizability, renderShape = _a.renderShape;
|
|
8864
8879
|
var propPorts = props.element.ports;
|
|
8865
8880
|
//state for position
|
|
8866
|
-
var _b = React.useState(__assign({}, props.element.position)), position = _b[0], setPosition = _b[1];
|
|
8881
|
+
var _b = React.useState(__assign({}, transformPositionToAnchoredPosition(props.element.position, props.element.size, props.element.positionAnchor || exports.PositioningAnchor.TopLeft))), position = _b[0], setPosition = _b[1];
|
|
8867
8882
|
//state for size
|
|
8868
8883
|
var _c = React.useState(__assign({}, props.element.size)), size = _c[0], setSize = _c[1];
|
|
8869
8884
|
var _d = React.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
|
|
@@ -8917,7 +8932,7 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
8917
8932
|
portsRef.current = newState;
|
|
8918
8933
|
return newState;
|
|
8919
8934
|
});
|
|
8920
|
-
}, [normalizePortPosition]);
|
|
8935
|
+
}, [normalizePortPosition, onPortMoved, id, _paperEventEmitterContext]);
|
|
8921
8936
|
// useLayoutEffect(() => {
|
|
8922
8937
|
// if (!hasNormalizedPortPositions.current && elementRef.current) {
|
|
8923
8938
|
// handlePortsState(portsRef.current);
|
|
@@ -8942,9 +8957,10 @@ var Element = React.forwardRef(function (props, forwardedRef) {
|
|
|
8942
8957
|
var elementAbsPosition = React.useMemo(function () { return getElementAbsPosition(); }, [getElementAbsPosition]);
|
|
8943
8958
|
//update element position
|
|
8944
8959
|
var updateElementPosition = React.useCallback(function (newPosition) {
|
|
8945
|
-
|
|
8960
|
+
var newPositionAdjusted = transformPositionToAnchoredPosition(newPosition, { width: size.width, height: size.height }, props.element.positionAnchor || exports.PositioningAnchor.TopLeft);
|
|
8961
|
+
setPosition(newPositionAdjusted);
|
|
8946
8962
|
props.element.position = { x: newPosition.x, y: newPosition.y };
|
|
8947
|
-
}, [props.element]);
|
|
8963
|
+
}, [props.element, size.width, size.height]);
|
|
8948
8964
|
//update element size
|
|
8949
8965
|
var updateElementSize = React.useCallback(function (newSize) {
|
|
8950
8966
|
setSize({ width: newSize.width, height: newSize.height });
|
|
@@ -10511,7 +10527,7 @@ var Paper = function (props) {
|
|
|
10511
10527
|
return (React.createElement("g", { id: "group-of-element-".concat(element.id), key: element.id },
|
|
10512
10528
|
React.createElement(ReactElement, { key: "element-".concat(element.id, "-").concat(element.version), element: element,
|
|
10513
10529
|
//id={element.id}
|
|
10514
|
-
|
|
10530
|
+
ref: function (refDOM) { return element.DOM = refDOM; },
|
|
10515
10531
|
//height={element.size.height}
|
|
10516
10532
|
//width={element.size.width}
|
|
10517
10533
|
//x={element.positionAnchor === PositioningAnchor.Center ? element.position.x - element.size.width / 2 : element.position.x}
|
|
@@ -30,7 +30,7 @@ export declare class EditorContext implements IEditorContext {
|
|
|
30
30
|
get configuration(): IEditorConfiguration;
|
|
31
31
|
getElement(elementId: string): IElement | undefined;
|
|
32
32
|
addElement(element: IElement): void;
|
|
33
|
-
removeElement(elementId: string
|
|
33
|
+
removeElement(elementId: string): void;
|
|
34
34
|
getLink(linkId: string): IElementLink | undefined;
|
|
35
35
|
addLink(link: IElementLink): void;
|
|
36
36
|
removeLink(linkId: string): void;
|
package/dist/esm/index.js
CHANGED
|
@@ -939,10 +939,17 @@ var EditorContext = /** @class */ (function () {
|
|
|
939
939
|
this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
|
|
940
940
|
this.onElementAddedHandler(element);
|
|
941
941
|
};
|
|
942
|
-
EditorContext.prototype.removeElement = function (elementId
|
|
942
|
+
EditorContext.prototype.removeElement = function (elementId) {
|
|
943
|
+
//find parent element id
|
|
944
|
+
var element = this.getElement(elementId);
|
|
945
|
+
var parentElement = element === null || element === void 0 ? void 0 : element.parentElement;
|
|
943
946
|
this._elements = this._elements.filter(function (e) { return e.id !== elementId; });
|
|
947
|
+
//remove from parent element if parentElementId is provided
|
|
948
|
+
if (parentElement) {
|
|
949
|
+
parentElement.childrenElements = parentElement.childrenElements.filter(function (e) { return e.id !== elementId; });
|
|
950
|
+
}
|
|
944
951
|
this._eventEmitter.emit(EVENT_EDITOR_CONTEXT_UPDATED);
|
|
945
|
-
this.onElementRemovedHandler(elementId,
|
|
952
|
+
this.onElementRemovedHandler(elementId, parentElement === null || parentElement === void 0 ? void 0 : parentElement.id);
|
|
946
953
|
};
|
|
947
954
|
EditorContext.prototype.getLink = function (linkId) {
|
|
948
955
|
return this._links.find(function (l) { return l.id === linkId; });
|
|
@@ -8852,6 +8859,14 @@ var ElementWrapper = forwardRef(function (_a, ref) {
|
|
|
8852
8859
|
return (React.createElement("svg", { className: cssClass, x: x, y: y, onClick: handleClick, onContextMenu: handleClick, onMouseDown: onMouseDown, ref: ref, style: { overflow: "visible" }, onMouseMove: onMouseMove, onMouseLeave: onMouseLeave, onMouseUp: onMouseUp }, children));
|
|
8853
8860
|
});
|
|
8854
8861
|
|
|
8862
|
+
var transformPositionToAnchoredPosition = function (position, elementSize, anchor) {
|
|
8863
|
+
var anchoredPosition = { x: position.x, y: position.y };
|
|
8864
|
+
if (anchor === PositioningAnchor.Center) {
|
|
8865
|
+
anchoredPosition.x = position.x - elementSize.width / 2;
|
|
8866
|
+
anchoredPosition.y = position.y - elementSize.height / 2;
|
|
8867
|
+
}
|
|
8868
|
+
return anchoredPosition;
|
|
8869
|
+
};
|
|
8855
8870
|
var Element = forwardRef(function (props, forwardedRef) {
|
|
8856
8871
|
var _paperEventEmitterContext = useContext(paperEventEmitterContext);
|
|
8857
8872
|
// const elementObj = props.element;
|
|
@@ -8859,7 +8874,7 @@ var Element = forwardRef(function (props, forwardedRef) {
|
|
|
8859
8874
|
var _a = props.element, id = _a.id, cssClass = _a.cssClass; _a.textsPlaceHolderClassName; var portSlideRailSVGClassName = _a.portSlideRailSVGClassName, portMoveableAreas = _a.portMoveableAreas, portDirection = _a.portDirection, defaultPortSize = _a.defaultPortSize; _a.textsPlaceHolderFlexStyle; _a.textsPlaceHolderFlexboxPosition; var resizability = _a.resizability, renderShape = _a.renderShape;
|
|
8860
8875
|
var propPorts = props.element.ports;
|
|
8861
8876
|
//state for position
|
|
8862
|
-
var _b = useState(__assign({}, props.element.position)), position = _b[0], setPosition = _b[1];
|
|
8877
|
+
var _b = useState(__assign({}, transformPositionToAnchoredPosition(props.element.position, props.element.size, props.element.positionAnchor || PositioningAnchor.TopLeft))), position = _b[0], setPosition = _b[1];
|
|
8863
8878
|
//state for size
|
|
8864
8879
|
var _c = useState(__assign({}, props.element.size)), size = _c[0], setSize = _c[1];
|
|
8865
8880
|
var _d = useState(), selectedPort = _d[0], setSelectedPort = _d[1];
|
|
@@ -8913,7 +8928,7 @@ var Element = forwardRef(function (props, forwardedRef) {
|
|
|
8913
8928
|
portsRef.current = newState;
|
|
8914
8929
|
return newState;
|
|
8915
8930
|
});
|
|
8916
|
-
}, [normalizePortPosition]);
|
|
8931
|
+
}, [normalizePortPosition, onPortMoved, id, _paperEventEmitterContext]);
|
|
8917
8932
|
// useLayoutEffect(() => {
|
|
8918
8933
|
// if (!hasNormalizedPortPositions.current && elementRef.current) {
|
|
8919
8934
|
// handlePortsState(portsRef.current);
|
|
@@ -8938,9 +8953,10 @@ var Element = forwardRef(function (props, forwardedRef) {
|
|
|
8938
8953
|
var elementAbsPosition = useMemo(function () { return getElementAbsPosition(); }, [getElementAbsPosition]);
|
|
8939
8954
|
//update element position
|
|
8940
8955
|
var updateElementPosition = useCallback(function (newPosition) {
|
|
8941
|
-
|
|
8956
|
+
var newPositionAdjusted = transformPositionToAnchoredPosition(newPosition, { width: size.width, height: size.height }, props.element.positionAnchor || PositioningAnchor.TopLeft);
|
|
8957
|
+
setPosition(newPositionAdjusted);
|
|
8942
8958
|
props.element.position = { x: newPosition.x, y: newPosition.y };
|
|
8943
|
-
}, [props.element]);
|
|
8959
|
+
}, [props.element, size.width, size.height]);
|
|
8944
8960
|
//update element size
|
|
8945
8961
|
var updateElementSize = useCallback(function (newSize) {
|
|
8946
8962
|
setSize({ width: newSize.width, height: newSize.height });
|
|
@@ -10507,7 +10523,7 @@ var Paper = function (props) {
|
|
|
10507
10523
|
return (React.createElement("g", { id: "group-of-element-".concat(element.id), key: element.id },
|
|
10508
10524
|
React.createElement(ReactElement, { key: "element-".concat(element.id, "-").concat(element.version), element: element,
|
|
10509
10525
|
//id={element.id}
|
|
10510
|
-
|
|
10526
|
+
ref: function (refDOM) { return element.DOM = refDOM; },
|
|
10511
10527
|
//height={element.size.height}
|
|
10512
10528
|
//width={element.size.width}
|
|
10513
10529
|
//x={element.positionAnchor === PositioningAnchor.Center ? element.position.x - element.size.width / 2 : element.position.x}
|